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

local p = {}
local cargo = mw.ext.cargo

local x = 
{
    { "", "", "Hero of the Federation", "", "" },
    { "M.I. Bronze Star", "M.I. Cross", "Medal of Valour", "Legion of Merit", "M.I. Silver Star" },
    { "Superior Command Commendation", "Distinguished Service Commendation", "Veterans Commendation", "Prisoner of War Commendation", "Emergency First Aid Commendation" },
    { "Professional Development Commendation", "Meritorious Service Commendation", "Good Conduct Commendation", "Humitarian Aid Commendation", "M.I. Reconnaissance Commendation" },
    { "Combat Commendation", "PsyOps Accomplishment Commendation", "Medical Accomplishment Commendation", "Engineering Accomplishment Commendation", "Purple Heart" },
    { "", "", "Veteran's Ribbon", "", "" }
}

function p.Main( frame )
    local t = {}
    local tables = 'Commendations'
    local fields = 'Commendation, COUNT(*)'

    local args = {
        groupBy = 'Commendation',
    }

    local results = cargo.query( tables, fields, args )
    local groups = {}
    
    for r = 1, #results do
        local r = results[r]
        groups[r.Commendation] = r["COUNT(*)"]
    end
    
    table.insert(t, "<table>")
    for k, r in pairs(x) do
        table.insert(t, "<tr>")
        for k2, v in pairs(r) do
            local g = groups[v]
            table.insert(t, "<td>")
            if v ~= "" then
                table.insert(t, frame:expandTemplate("Commendation", { v, (g or 0) }))
            end
            table.insert(t, "</td>")
        end
        table.insert(t, "</tr>")
    end
    table.insert(t, "</table>")
    return table.concat(t, '')
end

return p


Categories: