Module:Attribute

From ema
Jump to navigation Jump to search

Documentation for this module may be created at Module:Attribute/doc

local p = {}

function p.getAttributeHierarchies(frame)
	result = mw.ext.cargo.query(
		'Attributes,Pages',
		'Attributes.Attribute_Category,CONCAT(Pages._pageName),Pages.Name',
		{
			join = 'Attributes._pageName=Pages._pageName',
			orderBy = 'Attributes.Attribute_Category,Pages.Name',
			limit = 500
		}
	)
	s = ''
	last_category = ''
	first = true
	hierarchy = ''
	for k,v in pairs(result) do
		category = v['Attributes.Attribute_Category']
		attribute = v['CONCAT(Pages._pageName)']
		if (last_category ~= category) then
			last_category = category
			if ( not first ) then
				s = s .. frame:extensionTag{ name = 'hierarchy', content = hierarchy, args = { titleiconproperty = "Title Icon" } }
				hierarchy = ''
			else
				first = false
			end
			s = s .. "\n\n<b>" .. category .. '</b>\n'
		end
		hierarchy = hierarchy .. '* [[' .. attribute .. ']]\n'
	end
	if ( not first ) then
		s = s .. frame:extensionTag{ name = 'hierarchy', content = hierarchy, args = { titleiconproperty = "Title Icon" } }
	end
	return s
end

return p