Module:Locations/Full list: Difference between revisions

From TwogPedia
(Created page with "local getArgs = require('Module:Arguments').getArgs local News = require('Module:NewsItem') local cargo = mw.ext.cargo local limit = 100000 local LocationsList = {} function LocationsList.main(frame) local args = getArgs(frame) local results = query( args) if #results > 0 then local container = mw.html.create('div'):attr('id', 'locations-search-container') local ul = mw.html.create('ul') for r = 1, #results do ul:node(mw.html.create('li'):node('[['...")
 
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local News = require('Module:NewsItem')
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


Line 29: Line 28:
local whereStr = ''
local whereStr = ''
local tables = 'Locations'
if args.type then whereStr = whereStr .. 'Locations.type HOLDS "' .. args.type .. '"' end
local fields = '_pageName'
if args.country then
local countries = mw.text.split(args.country, ',')
if whereStr ~= '' then whereStr = whereStr .. ' AND ' end
whereStr = whereStr .. '('
for i = 1, #countries do
if i > 1 then whereStr = whereStr .. ' OR ' end
whereStr = whereStr .. 'Locations.country="' .. countries[i] .. '"'
end
whereStr = whereStr .. ')'
end
if args.name then whereStr = whereStr .. (whereStr ~= '' and ' AND ' or '') .. 'Locations._pageName LIKE "%' .. args.name .. '%"'  end
local tables = 'Locations, _pageData'
local fields = 'Locations._pageName=_pageName, Locations.franchise=franchise, Locations.country=country, Locations.city=city, Locations.type=type'
local cargoArgs = {
local cargoArgs = {
join = 'Locations._pageName = _pageData._pageName',
where = whereStr,
where = whereStr,
orderBy = '_pageName DESC',
orderBy = "_pageData._modificationDate DESC",
limit = limit
        limit = limit
}
}
local results = cargo.query(tables, fields, cargoArgs)
local results = cargo.query(tables, fields, cargoArgs)

Latest revision as of 12:32, 9 April 2024

Documentation for this module may be created at Module:Locations/Full list/doc

local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo

local limit = 100000

local LocationsList = {}

function LocationsList.main(frame)
	local args = getArgs(frame)
	local results = query( args)
	
	if #results > 0 then
		local container = mw.html.create('div'):attr('id', 'locations-search-container')
		
		local ul = mw.html.create('ul')
		
		for r = 1, #results do
			ul:node(mw.html.create('li'):node('[[' .. results[r]._pageName .. ']]'))
		end

		container:node(ul)
		
		return container
	end
end

function query(args)
	local whereStr = ''
	
	if args.type then whereStr = whereStr .. 'Locations.type HOLDS "' .. args.type .. '"' end
	if args.country then 
		local countries = mw.text.split(args.country, ',')
		if whereStr ~= '' then whereStr = whereStr .. ' AND ' end
		whereStr = whereStr .. '('
		for i = 1, #countries do
			if i > 1 then whereStr = whereStr .. ' OR ' end
			whereStr = whereStr .. 'Locations.country="' .. countries[i] .. '"'
		end
		whereStr = whereStr .. ')'
	end
	
	if args.name then whereStr = whereStr .. (whereStr ~= '' and ' AND ' or '') .. 'Locations._pageName LIKE "%' .. args.name .. '%"'  end
	
	local tables = 'Locations, _pageData'
	local fields = 'Locations._pageName=_pageName, Locations.franchise=franchise, Locations.country=country, Locations.city=city, Locations.type=type'
	local cargoArgs = {
		join = 'Locations._pageName = _pageData._pageName',
		where = whereStr,
		orderBy = "_pageData._modificationDate DESC",
        limit = limit
	}

	local results = cargo.query(tables, fields, cargoArgs)
	
    return results
end

return LocationsList