Module:BroadcasterCard

local p = {} local getArgs = require('Module:Arguments').getArgs local Flags = require('Module:Flags')._Flag

function p.var(name, default) return (mw.ext.VariablesLua.var(name) ~= ) and mw.ext.VariablesLua.var(name) or default or  end

function p.create(frame) local args = getArgs(frame) return p._create(args) end

function tableSortCat( a, b ) return (a.sort < b.sort) or (a.sort == b.sort and a.id < b.id) end

function p._get_caster_data(caster) local data = mw.ext.LiquipediaDB.lpdb('player', {		conditions = 'pagename::' .. string.gsub(caster, ' ', '_') .. '',		query = 'name, nationality',	})

if type(data[1]) == 'table' then return data[1]['name'], data[1]['nationality'] end end

function p._create(args) local CasterList = {} local sort_mode = args.sort or '' local list_index = 0 local disable_storage = p.var('disable_SMW_storage', 'false') if mw.title.getCurrentTitle.nsText ~= '' then disable_storage = 'true' end -- parse parameters for key, item in pairs(args) do		if item == '' or item == '\n' then args[key] = nil end if type(key) == 'string' and item ~= '' then if key:match('^%d-([^%d]*%d*)$') then local param, caster_index = key:match('^([^%d]*)(%d*)$') caster_index = tonumber(caster_index) if param == 'b' then local caster_page = args[param .. caster_index .. 'link'] or item list_index = list_index + 1 local caster_pageRR = mw.ext.TeamLiquidIntegration.resolve_redirect(caster_page) local caster_lpdbname, caster_lpdbflag = p._get_caster_data(caster_pageRR) local caster_flag = args[param .. caster_index .. 'flag'] or caster_lpdbflag or 'unknown' local caster_name = args[param .. caster_index .. 'name'] or caster_lpdbname or '' local caster_dq = args[param .. caster_index .. 'dq'] or 'false' local caster_note = args[param .. caster_index .. 'note'] or '' local caster_sort = item if sort_mode == 'flag' then caster_sort = caster_flag elseif sort_mode == 'number' or sort_mode == 'false' then caster_sort = caster_index elseif sort_mode == 'manual' then caster_sort = 99 - (tonumber(args[param .. caster_index .. 'sort']) or 0) end CasterList[list_index] = {id = item, page = caster_pageRR, flag = caster_flag, name = caster_name, dq = caster_dq, note = caster_note, sort = caster_sort, number = caster_index} end end end end table.sort(CasterList, tableSortCat) local lang = args.lang or '' mw.ext.VariablesLua.vardefine('bt_lang', lang) local frame = mw.getCurrentFrame local position = args.position or frame:expandTemplate{ title = 'abbr/TBD' } local ref = args.ref or '' local title = args.title or '' -- get date and set broadcaster_date local date = args.date or p.var('broadcaster_date', p.var('tournament_date', '1970-01-01')) mw.ext.VariablesLua.vardefine('broadcaster_date', date) --get tournament data local t_page = mw.title.getCurrentTitle.text local t_name = p.var('tournament_name', t_page) local tier = p.var('tournament_tier') local series = p.var('tournament_series') local weight = p.BroadcastWeight(tier, p.var('tournament_prizepool', 1), p.var('tournament_tiertype')) local icon = p.var('tournament_icon') local output = '' if title ~= '' then output = '*  .. title .. '	elseif lang ~= '' then output = '*  .. lang .. ' ' .. position .. '	else output = '*  .. position .. '	end if ref ~= '' then local ref_display = frame:callParserFunction{ name = '#tag', args = { 'ref', ref } } --tostring(mw.html.create('ref'):wikitext(ref)) output = output .. ' ' .. ref_display end if list_index == 0 then output = output .. '\n** TBD' elseif list_index > 1 then output = output .. 's' end for i=1,list_index do		if CasterList[i].dq ~= 'false' then output = output .. '\n** ' .. Flags(CasterList[i].flag) .. ' ' .. CasterList[i].id .. ' (' .. CasterList[i].name .. ') ' .. CasterList[i].note .. ''	 	else if disable_storage ~= 'true' then local storeinformation = p._store_information(CasterList[i], date, weight, lang, position) end if (CasterList[i].name or ) ~=  then CasterList[i].name = ' (' .. CasterList[i].name .. ')' end local temp = Flags(CasterList[i].flag) if temp == nil then return ' '''Bad flag entry for ' .. CasterList[i].page ..  '			end output = output .. '\n** ' .. temp .. ' ' .. CasterList[i].id .. '' .. CasterList[i].name .. '' .. CasterList[i].note .. ''	 	end end return output end

function p._store_information(Caster, date, weight, lang, position) local id = Caster.page if (lang or ) ~=  then id = id .. '_' .. lang end mw.ext.LiquipediaDB.lpdb_broadcasters( 'broadcaster_' .. Caster.id .. '_' .. position:gsub( '%s+','_' ), {	 	id = Caster.id,		name = Caster.name,	  	page = Caster.page,	  	language = lang,	  	flag = Caster.flag,		  	position = position,	  	weight = weight,	  	date = date	}) mw.ext.VariablesLua.vardefine('b' .. Caster.number .. 'flag', Caster.flag) return true end

function p.BroadcastWeight(tier, prizepool, tiertype) local weight tier = string.lower(tier or '') if tier == '3' then weight = 2 elseif tier == '2' then weight = 4 elseif tier == '1' then local prize = string.gsub(prizepool, ',', '') prize = tonumber(prize) or 1 weight = 8 * prize else weight = 1 end if tiertype == 'Qualifier' then weight = weight * 0.001 end return weight end

return p