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" },
    { "Corporal", "Sergeant", "Commanding Officer", "Marauder", "Pathfinder" },
    { "MIPOD", "Medic", "Trooper", "Engineer", "Aviator" },
    { "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", "Humanitarian Aid Commendation", "M.I. Reconnaissance Commendation" },
    { "Combat Commendation", "PsyOps Accomplishment Commendation", "Medical Accomplishment Commendation", "Engineering Accomplishment Commendation", "Purple Heart" },
    { "", "", "Veteran's Ribbon", "", "" },
    { "Operation Big K Pin", "", "", "", "" }
}

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

    local args = {
        groupBy = 'Commendation',
        where = 'Recipient = "' .. frame.args[1] .. '" AND Approved = true'
    }

    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 class='citations-table'>")
    for k, r in pairs(x) do

        if k == 1 then
            table.insert(t, "<tr class='first'>")
        else
            table.insert(t, "<tr>")
        end

        for k2, v in pairs(r) do
            local g = groups[v]
            table.insert(t, "<td>")
            if v ~= "" then
                table.insert(t, 
                                frame:expandTemplate({title = "Commendation", args = { v, v .. ".png", (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: