Difference between revisions of "Module:IndianPremierLeague/GroupStageTable"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jfd34
blackwiki>Jfd34
Line 4: Line 4:
 
     local args = frame.args
 
     local args = frame.args
 
     local year = tonumber(args.year) or error("Parameter: 'year' is missing or invalid")
 
     local year = tonumber(args.year) or error("Parameter: 'year' is missing or invalid")
    local teams = {}
 
 
      
 
      
     do
+
     local j = 1
        -- Get the team objects for the given teams
+
    local teams = mw.loadData("Module:IndianPremierLeague/Teams")
        local i = 1
+
    local filteredTeams = {}
        local teamTable = mw.loadData("Module:IndianPremierLeague/Teams")
+
    for i, v in ipairs(teams) do
        for t in mw.text.gsplit(args.teams or error("Missing parameter: 'teams'"), '%s*,%s*') do
+
        -- Filter the teams based on the year
            local teamObj = teamTable[t]
+
        if year >= v.startYear and (not v.endYear or v.endYear >= year) then
            if not teamObj or year < teamObj.startYear or (teamObj.endYear and teamObj.endYear < year) then
+
             filteredTeams[j] = v
                error("Team '" .. t .. "' does not exist or is not valid for the given year.")
+
             j = j + 1
            end
 
             teams[i] = teamObj
 
             i = i + 1
 
 
         end
 
         end
 
     end
 
     end
     return require("Module:CricketLeagueGroupStageSummary").create(frame, year .. " IPL Group Stage Table", teams, args.useParentData, true, nil, args.useWebSlice)
+
 
 +
     return require("Module:CricketLeagueGroupStageSummary").create(args.useParentData and frame:getParent() or frame, year .. " IPL Group Stage Match Summary", filteredTeams, true, nil, args.useWebSlice)
 
end
 
end
 
   
 
   
 
return _module
 
return _module

Revision as of 09:07, 7 April 2014

local _module = {}
 
_module.create = function(frame)
    local args = frame.args
    local year = tonumber(args.year) or error("Parameter: 'year' is missing or invalid")
    
    local j = 1
    local teams = mw.loadData("Module:IndianPremierLeague/Teams")
    local filteredTeams = {}
    for i, v in ipairs(teams) do
        -- Filter the teams based on the year
        if year >= v.startYear and (not v.endYear or v.endYear >= year) then
            filteredTeams[j] = v
            j = j + 1
        end
    end

    return require("Module:CricketLeagueGroupStageSummary").create(args.useParentData and frame:getParent() or frame, year .. " IPL Group Stage Match Summary", filteredTeams, true, nil, args.useWebSlice)
end
 
return _module