Module:Locations/Full list: Difference between revisions

From TwogPedia
mNo edit summary
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 47: Line 47:
join = 'Locations._pageName = _pageData._pageName',
join = 'Locations._pageName = _pageData._pageName',
where = whereStr,
where = whereStr,
limit = 20,
orderBy = "_pageData._modificationDate DESC",
orderBy = "_pageData._modificationDate DESC",
        limit = limit
}
}



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