Leaguepedia | League of Legends Esports Wiki
Advertisement

Edit the documentation or categories for this module. This module has an i18n file.


local util_args = require('Module:ArgsUtil')
local util_cargo = require("Module:CargoUtil")
local util_html = require("Module:HtmlUtil")
local util_infobox = require("Module:InfoboxUtil")
local util_news = require("Module:NewsUtil")
local util_sort = require("Module:SortUtil")
local util_source = require("Module:SourceUtil")
local util_table = require("Module:TableUtil")
local util_text = require("Module:TextUtil")
local util_time = require("Module:TimeUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require('Module:i18nUtil')

local m_team = require('Module:Team')

local PRELOADS_TO_IGNORE = {
	'opportunities',
	-- 'expire_notleaves',
}

local h = {}

local NewsQueryAbstract = require('Module:NewsQueryAbstract')
local NewsQuery = NewsQueryAbstract:extends()
local TabsDynamic = require('Module:TabsDynamic').constructor

function NewsQuery:init(args)
	self:super('init', args)
	util_table.mergeArrays(self.PRELOADS_TO_IGNORE, PRELOADS_TO_IGNORE)
end

function NewsQuery:getQuery(args)
	local query = self:super('getQuery', args)
	local new = {
		tables = self.getTables(),
		join = self:getJoin(),
		where = self:getWhere(args, query.where),
		fields = { 'RC.PreloadSortNumber [number]' },
		orderBy = 'News.Date_Sort ASC, N_LineInDate ASC, News.Date_Display, News.IsApproxDate',
		groupBy = 'News.NewsId',
	}
	local ret = util_cargo.concatQueriesAnd(query, new)
	-- util_cargo.logQuery(ret)
	return ret
end

function NewsQuery:getTables()
	return { 'TeamRedirects=TR', 'RosterChanges=RC', 'TeamRegionChanges=TRC' }
end

function NewsQuery:getJoin()
	local ret = {
		'News.Teams HOLDS TR.AllName',
		'News.NewsId=RC.NewsId',
		'News.NewsId=TRC.NewsId',
	}
	return ret
end

function NewsQuery:getWhere(args, where)
	local tbl = {
		where,
		('TR._pageName="%s"'):format(self:getTeam(args.team)),
		util_news.getExcludedPreloadsWhereCondition(self.PRELOADS_TO_IGNORE),
	}
	return util_cargo.concatWhere(tbl)
end

function NewsQuery:getTeam(team)
	if not team then return mw.title.getCurrentTitle().baseText:lower() end
	return m_team.teamlinkname(team):lower()
end

function NewsQuery:groupDataByDate(data)
	local byDate = self:super('groupDataByDate', data)
	local ret = {}
	for _, date in ipairs(byDate) do
		util_sort.tablesByKeys(
			byDate[date],
			{ 'N_LineInDate', 'PreloadSortNumber' },
			{ true, true }
		)
		util_table.initDict(ret, byDate[date].year)
		util_table.pushDict(ret[byDate[date].year], date, byDate[date])
	end
	return ret
end

function h.getYearContent(byDate)
	local ul = mw.html.create('ul')
		:addClass('news-list')
		:addClass('news-team-list')
		:addClass('hoverable-rows')
	for _, date in ipairs(byDate) do
		h.printDateAndContent(ul, byDate[date])
	end
	return tostring(ul)
end

-- print
function NewsQuery:makeOutput(byDate, args)
	local tabs = {}
	for _, year in ipairs(byDate) do
		tabs[#tabs+1] = {
			name = year,
			content = h.getYearContent(byDate[year])
		}
	end
	return TabsDynamic(tabs, #tabs)
end

function h.printDateAndContent(ul, lines)
	local li = ul:tag('li')
	for i, line in ipairs(lines) do
		h.printLine(li, i, line)
		h.printRef(li, line)
		if i < #lines then
			li:wikitext(' ')
		end
	end
	util_news.printEditButton(li, lines.page)
end

function h.printLine(li, i, line)
	if i == 1 then
		li:wikitext(line.SentenceWithDate)
	else
		li:wikitext(line.Sentence)
	end
end

function h.printRef(li, line)
	if DEBUG then
		util_source.printPopupRef(li, line.Source)
		return
	end
	li:wikitext(util_source.makeRef(line.Source))
end

return NewsQuery
Advertisement