Module:Capability

From ema
Jump to navigation Jump to search

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

local p = {}

function p.getCapabilityHierarchy(frame)
	include_behaviors = false
	for _,v in pairs(frame.args) do
		if ( v == 'include behaviors' ) then
			include_behaviors = true
		end
	end
	result1 = mw.ext.cargo.query(
		'Capabilities,Pages',
		'CONCAT(Pages._pageName),Pages.Name',
		{
			join = 'Capabilities._pageName=Pages._pageName',
			orderBy = 'Pages.Name',
			limit = 500
		}
	)
	s = ''
	for k1,v1 in pairs(result1) do
		capability = v1['CONCAT(Pages._pageName)']
		s = s .. '* [[' .. capability  .. ']]\n'
		result2 = mw.ext.cargo.query(
			'Associations,Pages',
			'CONCAT(Pages._pageName),Pages.Name',
			{
				where = 'Associations.Association_Type="Capability" AND Associations.Associated_Page="' .. capability .. '"',
				join = 'Associations._pageName=Pages._pageName',
				orderBy = 'Pages.Name',
				limit = 500
			}
		)
		for k2,v2 in pairs(result2) do
			subcapability = v2['CONCAT(Pages._pageName)']
			s = s .. '** [[' .. subcapability  .. ']]\n'
			if ( include_behaviors ) then
				result3 = mw.ext.cargo.query(
					'Associations,Pages',
					'CONCAT(Pages._pageName),Pages.Name',
					{
						where = 'Associations.Association_Type="Capability" AND Associations.Associated_Page="' .. subcapability .. '"',
						join = 'Associations._pageName=Pages._pageName',
						orderBy = 'Pages.Name',
						limit = 500
					}
				)
				for k3,v3 in pairs(result3) do
					behavior = v3['CONCAT(Pages._pageName)']
					s = s .. '*** [[' .. behavior  .. ']]\n'
				end
			end
		end
	end
	return s
end

return p