mNo edit summary
mNo edit summary
 
(31 intermediate revisions by the same user not shown)
Line 6: Line 6:
     { "", "", "Hero of the Federation", "", "" },
     { "", "", "Hero of the Federation", "", "" },
     { "M.I. Bronze Star", "M.I. Cross", "Medal of Valour", "Legion of Merit", "M.I. Silver Star" },
     { "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" },
     { "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" },
     { "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" },
     { "Combat Commendation", "PsyOps Accomplishment Commendation", "Medical Accomplishment Commendation", "Engineering Accomplishment Commendation", "Purple Heart" },
     { "", "", "Veteran's Ribbon", "", "" }
     { "", "", "Veteran's Ribbon", "", "" },
    { "Operation Big K Pin", "", "", "", "" }
}
}


Line 16: Line 19:
     local tables = 'Commendations'
     local tables = 'Commendations'
     local fields = 'Commendation, COUNT(*)'
     local fields = 'Commendation, COUNT(*)'
    -- optional parameters are grouped in one table
 
    -- you can omit any or all of them, except join if you use more than one table
     local args = {
     local args = {
        --where = '',
        --join = 'table1.fieldA = table2.fieldB,table2.fieldC=table3.fieldD, etc.',
         groupBy = 'Commendation',
         groupBy = 'Commendation',
         --having = 'table1.fieldG="some value", etc.',
         where = 'Recipient = "' .. frame.args[1] .. '" AND Approved = true'
        --orderBy = 'table2.fieldF, etc.',
        --limit = some number,
        --offset = some number,
     }
     }
     local results = cargo.query( tables, fields, args )
     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
     for k, r in pairs(x) do
         table.insert(t, "<tr>")
 
         for k2, r2 in pairs(r) 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>")
             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>")
             table.insert(t, "</td>")
         end
         end
         table.insert(t, "</tr>")
         table.insert(t, "</tr>")
     end
     end
     for r = 1, #results do
     table.insert(t, "</table>")
        local result = results[r]
        table.insert(t, result.Commendation .. " = " .. result["COUNT(*)"])
    end
     return table.concat(t, '')
     return table.concat(t, '')
end
end


return p
return p

Latest revision as of 23:24, 17 November 2022

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: