Module:Transfer List

local p = {} -- p stands for package

local getArgs = require('Module:Arguments').getArgs local Flag = require('Module:Flags')._Flag local args

function formatDate(date) return os.date("!%Y-%m-%d", date) end

function argExists(s) return s and s ~= '' end

function formatTeam(frame, team, role) teamText = '' if argExists(team) then if team:match('\'+.*\'+') then teamText = team else teamText = frame:expandTemplate({title = 'TeamIcon', args = {string.lower(team)}}) end else teamText = '\'\'None\'\'' end if argExists(role) then return teamText .. ' \'\'(' .. role .. ')\'\' ' else return teamText end end

function p.getSMWTransfers(frame, data, team) SMWConditions = 'has date::>' .. frame.args.sdate .. ' has date::<' .. frame.args.edate .. '' SMWConditions = SMWConditions .. ' has old team::' .. team .. ' OR ' .. SMWConditions .. ' has new team::' .. team .. '' SMWConditions = SMWConditions .. '|?has date=date |?has old role=oldRole |?has new role=newRole |?has old team=oldTeam |?has new team=newTeam |?has ref=ref |?has status=status' for i=1,10 do SMWConditions = SMWConditions .. '|?has player ' .. tostring(i) .. ' name=p' .. tostring(i) .. 'name |?has player ' .. tostring(i) .. ' flag=p' .. tostring(i) .. 'flag |?has player ' .. tostring(i) .. ' page=p' .. tostring(i) .. 'page |?has player ' .. tostring(i) .. ' position=p' .. tostring(i) .. 'position' end SMWConditions = SMWConditions .. '|mainlabel=page |limit=1000' --mw.log(SMWConditions) local queryResult = mw.smw.getQueryResult( SMWConditions ) local output = {} if type( queryResult ) == "table" then for key, item in pairs( queryResult.results ) do	 		local tempTransfers = {} for i=1,10 do if argExists(item.printouts['p' .. tostring(i) .. 'name'][1]) then if argExists(item.printouts['p' .. tostring(i) .. 'page'][1]) then playerPage = item.printouts['p' .. tostring(i) .. 'page'][1].fulltext else playerPage = nil end table.insert(tempTransfers, {			 			name = item.printouts['p' .. tostring(i) .. 'name'][1],			  			flag = item.printouts['p' .. tostring(i) .. 'flag'][1],			  			page = playerPage,			  			position = item.printouts['p' .. tostring(i) .. 'position'][1]			  		}) end end if not data[item.fullurl] then table.insert(data, {					page = item.fullurl,					date = item.printouts.date[1].timestamp,					oldRole = item.printouts.oldRole[1],					newRole = item.printouts.newRole[1],					oldTeam = item.printouts.oldTeam[1],					newTeam = item.printouts.newTeam[1],					ref = item.printouts.ref[1],					status = item.printouts.status[1],					transfers = tempTransfers				}) end data[item.fullurl] = 1 end end return data end

function p.getTransfers(frame) local tableWrapper = '' local teamList = {} local data = {} for key, item in pairs(frame.args) do		if item == '' or item == '\n' then frame.args[key] = nil end if type(key) == 'string' and item ~= '' then if key:match('^[^%d]*(%d*)$') then local param = key:match('^([^%d]*)%d*$')

-- teamX if param == 'team' then local teamName = frame:expandTemplate{ title = 'TeamName', args = {item} } table.insert(teamList, {name = teamName, teamArg = item}) teamList[teamName] = #teamList end end end end for key, team in ipairs(teamList) do		data = p.getSMWTransfers(frame, data, team.name) end table.sort(data, function(item1, item2) return item1.date > item2.date end) if type(data) == 'table' then if frame.args.shown ~= 'true' then tableWrapper = mw.html.create('table') :addClass('wikitable collapsible collapsed OffSeasonOverview') :css('margin','0px') else tableWrapper = mw.html.create('table') :addClass('wikitable OffSeasonOverview') :css('margin','0px') end tableWrapper:tag('tr') :tag('th') :attr('colspan','7') :wikitext(frame.args.title or 'Roster moves during the season') local transferTable = mw.html.create('div') :addClass('divTable mainpage-transfer Ref') :css('text-align','center') :css('width','100%') transferTable:tag('div'):addClass('divHeaderRow') :tag('div'):addClass('divCell Date'):wikitext('Date'):done :tag('div'):addClass('divCell Name'):wikitext('Player'):done :tag('div'):addClass('divCell Team OldTeam'):wikitext('Old'):done :tag('div'):addClass('divCell Icon'):done :tag('div'):addClass('divCell Team NewTeam'):wikitext('New'):done :tag('div'):addClass('divCell Empty'):done for key, item in ipairs(data) do	 		local playerText = '' local output = (output or '') .. (item.oldTeam or '') for key2, player in pairs(item.transfers) do				if key2>1 then playerText = playerText .. ' '		 		end playerText = playerText .. frame:expandTemplate({title = 'Flag/' .. string.lower(player.flag or 'filler flag')}) .. ' ' .. 						frame:expandTemplate({title = 'PositionIcon/' .. string.lower(player.position or '')}) .. ' ' .. player.name .. '' end transferTable:tag('div'):addClass('divRow mainpage-transfer-' .. item.status) :tag('div'):addClass('divCell Date'):wikitext(formatDate(item.date)):done :tag('div'):addClass('divCell Name'):wikitext(playerText):done :tag('div'):addClass('divCell Team OldTeam'):wikitext(formatTeam(frame, item.oldTeam, item.oldRole)):done :tag('div'):addClass('divCell Icon'):wikitext(frame:expandTemplate({title='rarr'})):done :tag('div'):addClass('divCell Team NewTeam'):wikitext(formatTeam(frame, item.newTeam, item.newRole)):done :tag('div'):addClass('divCell Empty'):wikitext(item.ref):done end tableWrapper:tag('tr') :tag('td') :wikitext(tostring(transferTable)):done else error(data) end return tableWrapper end

-- Get a list of recent transfers up to the specified limit -- This ONLY works for general transfers right now since there is no field for icons function p.getLpdbTransfers(frame) args = getArgs(frame) local tableWrapper = '' local wrapper = '' args.limit = args.limit or '20' local sort = args.sort or 'date' local order = args.order or 'desc' local sort_order = sort .. ' ' .. order local iconModule = args.iconModule and mw.loadData(args.iconModule) -- Set date conditions local conditions if args.sdate then conditions = '(date::>' .. args.sdate .. ' 00:00:00 OR date::' .. args.sdate .. ' 00:00:00)' else conditions = 'date::>1971-01-01' end if args.edate then conditions = conditions .. ' AND (date::<' .. args.edate .. ' 23:59:59 OR date::' .. args.edate .. ' 23:59:59)' end -- Set player conditions if args.players then local playerArray = mw.text.split(args.players, ',', true) local player = mw.ext.TeamLiquidIntegration.resolve_redirect(playerArray[1]) conditions = conditions .. ' AND (player::' .. player .. 		for i=2, #playerArray do			player = mw.ext.TeamLiquidIntegration.resolve_redirect(playerArray[i]) 			conditions = conditions .. ' OR player::' .. player ..   		end		conditions = conditions .. ')' elseif args.player then conditions = conditions .. ' AND player::' .. args.player .. '' end -- Set team conditions if args.teams then local teamArray = mw.text.split(args.teams, ',', true) local team = mw.ext.TeamLiquidIntegration.resolve_redirect( mw.ext.TeamTemplate.teampage( teamArray[1] ) ) team = team ~= '' and team or mw.ext.TeamLiquidIntegration.resolve_redirect( teamArray[1] ) conditions = conditions .. ' AND ((fromteam::' .. team .. ' OR toteam::' .. team .. ')'		for i=2,#teamArray do	 		team = mw.ext.TeamLiquidIntegration.resolve_redirect( mw.ext.TeamTemplate.teampage( teamArray[i] ) )			team = team ~= '' and team or mw.ext.TeamLiquidIntegration.resolve_redirect( teamArray[i] )	  		conditions = conditions .. ' OR (fromteam::' .. team .. ' OR toteam::' .. team .. ')'		end		conditions = conditions .. ')' elseif args.team then local teamList = {} for key, item in pairs(frame.args) do			if item == '' or item == '\n' then frame.args[key] = nil end if type(key) == 'string' and item ~= '' then if key:match('^[^%d]*(%d*)$') then local param = key:match('^([^%d]*)%d*$') -- teamX if param == 'team' then local teamName = mw.ext.TeamLiquidIntegration.resolve_redirect( mw.ext.TeamTemplate.teampage( item ) ) if teamName == '' then mw.log(item) return 'Invalid team name specified.' end table.insert(teamList, teamName) end end end end conditions = conditions .. ' AND ((fromteam::' .. teamList[1] .. ' OR toteam::' .. teamList[1] .. ')'		for i=2, #teamList do	  		conditions = conditions .. ' OR (fromteam::' .. teamList[i] .. ' OR toteam::'  .. teamList[i] .. ')'	  	end		conditions = conditions .. ')' elseif args.page then local teamListPage = {} local tournament = string.gsub(args.page, ' ', '_') local data = mw.ext.LiquipediaDB.lpdb('placement', {			conditions = 'pagename::' .. tournament .. ' AND participant::!Tbd',			query = 'participant'		}) if type(data[1]) == 'table' then for _, item in ipairs(data) do				table.insert(teamListPage, item.participant) end conditions = conditions .. ' AND ((fromteam::' .. teamListPage[1] .. ' OR toteam::' .. teamListPage[1] .. ')'			for i=2, #teamListPage do				conditions = conditions .. ' OR (fromteam::' .. teamListPage[i] .. ' OR toteam::'  .. teamListPage[i] .. ')'			end			conditions = conditions .. ')' end end -- Set nationality conditions if args.nationality then --temp fix for duplicate entry Form bug countryArray = mw.text.split(args.nationality, ',', true) conditions = conditions .. ' AND nationality::' .. countryArray[1] .. '' end -- Set role conditions if args.role then conditions = conditions .. ' AND (role1::' .. args.role .. ' OR role2::'  .. args.role .. ' )' end -- Set reference conditions (needs reference/source) if args.reference then conditions = conditions .. ' AND reference::>' end -- Retrieve LPDB data. These results are grouped by date, toteam, fromteam, role1 and role2. Getting all players for each transfer happens later local data = mw.ext.LiquipediaDB.lpdb('transfer', {	 		conditions = conditions,			limit = args.limit,			order = sort_order,			query = 'fromteam, toteam, date, role1, role2, objectname',	  		groupby = 'date desc, toteam desc, fromteam desc, role1 desc, role2 desc'	}) -- Wrapper if (frame.args.title or ) ~=  then tableWrapper = mw.html.create('table') :css('margin-top','0px') if frame.args.shown ~= 'true' then tableWrapper:addClass('wikitable collapsible collapsed OffSeasonOverview') else tableWrapper:addClass('wikitable OffSeasonOverview') end tableWrapper:tag('tr') :tag('th') :attr('colspan','7') :wikitext(frame.args.title) wrapper = tableWrapper:tag('tr'):tag('td'):tag('div') :addClass('divTable mainpage-transfer Ref') :css('text-align', 'center') :css('width', '100%') if args.class then wrapper:addClass(args.class) end else tableWrapper = mw.html.create('div') wrapper = tableWrapper :addClass('divTable mainpage-transfer Ref') :css('text-align', 'center') :css('width', '100%') if args.class then wrapper:addClass(args.class) end end --Headings local header = wrapper:tag('div') :addClass('divHeaderRow') header:tag('div') :addClass('divCell Date') :wikitext('Date') header:tag('div') :addClass('divCell Name') :wikitext('Player') header:tag('div') :addClass('divCell Team OldTeam') :wikitext('Old') header:tag('div') :addClass('divCell Icon') header:tag('div') :addClass('divCell Team NewTeam') :wikitext('New') header:tag('div') :addClass('divCell Empty') :tag('span') :addClass('mobile-hide') :wikitext(frame:callParserFunction{ name = '#tag:abbr', args = {'Ref', title = 'Reference'} }) -- Loop through each transfer to retrieve all players associated with it 	for i=1, #data do local loopconditions = 'date::' .. data[i].date .. ' AND fromteam::' .. data[i].fromteam .. ' AND toteam::' .. data[i].toteam .. ' AND role1::' .. data[i].role1 .. ' AND role2::' .. data[i].role2 .. '' if args.nationality then loopconditions = loopconditions .. 'AND nationality::' .. countryArray[1] .. '' end if args.player then loopconditions = loopconditions .. 'AND player::' .. args.player .. '' end local rowOfTransfers = mw.ext.LiquipediaDB.lpdb('transfer', {			limit = args.limit,			order = 'player asc',			conditions = loopconditions,			query = 'player, nationality, fromteam, toteam, role1, role2, reference, date, extradata, objectname',		}) -- Create a new row local row = wrapper:tag('div') p.transferRow(row, rowOfTransfers, args.refTable, iconModule) end return tableWrapper end

function p.transferRow(row, transferInfo, refTable, iconModule) -- Determine the class of transfer based on what toteam/fromteam info is filled out if transferInfo[1].fromteam and transferInfo[1].fromteam ~=  and transferInfo[1].toteam and transferInfo[1].toteam ~=  then row:addClass('divRow mainpage-transfer-neutral') elseif transferInfo[1].fromteam and transferInfo[1].fromteam ~= '' then row:addClass('divRow mainpage-transfer-from-team') elseif transferInfo[1].toteam and transferInfo[1].toteam ~= '' then row:addClass('divRow mainpage-transfer-to-team') else row:addClass('divRow mainpage-transfer-neutral') end -- Date row:tag('div') :addClass('divCell Date') :wikitext(mw.getContentLanguage:formatDate('Y-m-d', transferInfo[1].date)) -- Name local name = row:tag('div') :addClass('divCell Name') -- Write out the flag, icon, and name for each player in the transaction for i=1, #transferInfo do		if i > 1 then name:wikitext(' ') end	-- Insert new line for each successive player -- Flag if transferInfo[i].nationality ~= '' then name:wikitext(Flag(transferInfo[i].nationality) .. ' ') else name:wikitext(' ') end -- Insert an icon if one exists if iconModule then local iconText = iconModule[ string.lower(transferInfo[i].extradata.icon) ] if iconText then name:wikitext(iconText .. ' ') else name:wikitext(' ') end end -- Write out the player's link and name name:wikitext( .. transferInfo[i].extradata.displayname .. ) end -- Old team local team1 = row:tag('div') :addClass('divCell Team OldTeam') if transferInfo[1].fromteam and transferInfo[1].fromteam ~= '' then team1:wikitext(mw.ext.TeamTemplate.teamicon( transferInfo[1].fromteam, transferInfo[1].date )) if transferInfo[1].extradata.fromteamsec and transferInfo[1].extradata.fromteamsec ~= '' then team1:wikitext('/' .. mw.ext.TeamTemplate.teamicon( transferInfo[1].extradata.fromteamsec, transferInfo[1].date )) end if transferInfo[1].role1 and transferInfo[1].role1 ~= '' then team1:wikitext(' (' .. (transferInfo[1].role1:gsub("^%l", string.upper)) .. ') ')		end elseif transferInfo[1].role1 ~= '' then team1:css('font-style', 'italic'):wikitext((transferInfo[1].role1:gsub("^%l", string.upper))) else team1:css('font-style', 'italic'):wikitext('None') end -- Arrow local arrowDiv = row:tag('div') :addClass('divCell Icon') :tag('span') :css('font-size','larger') :css('text-align','center') :wikitext('&#x21d2;') -- New team local team2 = row:tag('div') :addClass('divCell Team OldTeam') if transferInfo[1].toteam and transferInfo[1].toteam ~= '' then team2:wikitext(mw.ext.TeamTemplate.teamicon( transferInfo[1].toteam, transferInfo[1].date )) if transferInfo[1].extradata.toteamsec and transferInfo[1].extradata.toteamsec ~= '' then team2:wikitext('/' .. mw.ext.TeamTemplate.teamicon( transferInfo[1].extradata.toteamsec, transferInfo[1].date )) end if transferInfo[1].role2 and transferInfo[1].role2 ~= '' then team2:wikitext(' (' .. (transferInfo[1].role2:gsub("^%l", string.upper)) .. ') ')		end elseif transferInfo[1].role2 ~= '' then team2:css('font-style', 'italic'):wikitext((transferInfo[1].role2:gsub("^%l", string.upper))) else team2:css('font-style', 'italic'):wikitext('None') end -- Reference local ref = row:tag('div') :addClass('divCell Ref') local refTemp = '' for i=1, #transferInfo do		if transferInfo[i].reference and transferInfo[i].reference.reference1 ~= refTemp then if refTable then local refTable = {} local references = mw.text.split(transferInfo[i].extradata.reference1 or '', ';;;', true) for _, item in pairs(references) do					local refTemp = mw.text.split(item, ',,,', true) if (refTemp[1] or ) ~=  then table.insert(refTable, {							type = refTemp[1],							text = refTemp[2],							url = refTemp[3],							title = refTemp[4],							trans_title = refTemp[5],							language = refTemp[6],							author = refTemp[7],							publisher = refTemp[8],							archiveurl = refTemp[9],							archivedate = refTemp[10]						}) end end for key, item in pairs(refTable) do					if (item.type or '') == 'web source' then if (item.url or ) ~=  then ref:wikitext('[' .. item.url .. ']') end elseif (item.type or '') == 'tournament source' then ref:wikitext('') elseif (item.type or '') == 'inside source' then ref:wikitext(frame:callParserFunction{ name = '#tag:abbr', args = {'', title = 'Liquipedia has gained this information from a trusted inside source'} }) end end else ref:wikitext(transferInfo[i].reference and transferInfo[i].reference.reference1 or '') end end refTemp = transferInfo[i].reference and transferInfo[i].reference.reference1 or '' end end

return p