Mô đun:Television critical response

-- Mô đun này thực hiện .
require('strict')
local yesno = require('Mô đun:Yesno')
--------------------------------------------------------------------------------
-- CriticalResponse class
-- The main class.
--------------------------------------------------------------------------------
local CriticalResponse = {}
function CriticalResponse.cellspan(SeasonEntries, SeasonEntries_ordered, key, cell, multipart)
	local spanlength = 1
	
	for i = cell+1, #SeasonEntries_ordered do
		local entry = SeasonEntriesSeasonEntries_orderedi
		-- Split season, then regular season
		if entry.startA then
			if not entrykey..'A' then spanlength = spanlength + 1
			else break end
			if not entrykey..'B' then spanlength = spanlength + 1
			else break end
		else
			if not entrykey and (not entry.special and multipart) then
				spanlength = spanlength + 1
			else break end
		end
	end
	return spanlength
end
-- Sorting function
function CriticalResponse.series_sort(op1, op2)
	local n1,s1 = string.match(op1,"(%d+)(%a*)")
	local n2,s2 = string.match(op2,"(%d+)(%a*)")
	local n1N,n2N = tonumber(n1),tonumber(n2)
	if n1N == n2N then
		return s1 ' .. args.title .. }})
		else
			root:tag('caption'):wikitext(frame:expandTemplate{title='Screen reader-only',args={'Critical response of ' .. series_name .. }})
		end
	end
	-- Extract seasons info and place into a 3D array
	local SeasonEntries = {}
	for k,v in pairs(args) do
		local str, num, str2 = string.match(k, '(^%d*)(%d*)(%a*)')
		if num ~=  then
			-- Special
			local special = false
			if string.sub(str2,1,1) == 'S' then
				special = true
				num = num .. str2
				str2 = 
			end
			-- Add to entries, create if necessary
			if not SeasonEntriesnum then
				SeasonEntriesnum = {}
			end
			SeasonEntriesnumstr .. str2 = v
			if special then
				SeasonEntriesnum'special' = 'y'
			end
		end
	end
	-- Order table by season number
	local SeasonEntries_ordered = {}
	for k in pairs(SeasonEntries) do
		table.insert(SeasonEntries_ordered, k)
	end
	table.sort(SeasonEntries_ordered,CriticalResponse.series_sort)
	
	local firstRow = args.multiseries and {} or SeasonEntriesSeasonEntries_ordered1
	-- Headers
	do
		if args.multiseries or not args.series then
			local headerRow = root:tag('tr')
			headerRow
				:css('text-align', 'center')
			
			-- Multiple series header
			if args.multiseries then
				headerRow:tag('th')
					:attr('scope', 'col')
					:css('padding', cellPadding)
					:wikitext('Tựa đề')
			end
			
			-- Season header
			if not hide_season then
				headerRow:tag('th')
					:attr('scope', 'col')
					:css('min-width', '50px')
					:css('padding', cellPadding)
					:addClass('unsortable')
					:wikitext(args.seriesT or args.seasonT or 'Mùa')
			end
			-- Rotten Tomatoes header
			if not hide_rotten_tomatoes then
				headerRow:tag('th')
					:attr('scope', 'col')
					:wikitext('Rotten Tomatoes')
			end
			-- Metacritic header
			if not hide_metacritic then
				headerRow:tag('th')
					:attr('scope', 'col')
					:wikitext('Metacritic')
			end
			
			-- CinemaScore header
			if show_cinemascore then
				headerRow:tag('th')
					:attr('scope', 'col')
					:wikitext('CinemaScore')
			end
		end
	end
	-- Season rows
	do
		if args.multiseries then
			-- Multi series individual entries
			if args.multiseries ~= "y" then
				root:node(args.multiseries)
			end
		else
			-- One row entries, only categorized in the mainspace
			if #SeasonEntries == 1 then
				categories = categories .. 'Thể loại:Bài viết sử dụng Bản mẫu:Phản ứng phê bình trên truyền hình chỉ có một hàng'
			end
		
			-- Determine number of rows in the whole table
			local SeasonEntriesRows = 0
			for X = 1, #SeasonEntries_ordered do
				local season, entry = SeasonEntries_orderedX, SeasonEntriesSeasonEntries_orderedX
				SeasonEntriesRows = SeasonEntriesRows + 1
			end
			
			for X = 1, #SeasonEntries_ordered do
				local season, entry = SeasonEntries_orderedX, SeasonEntriesSeasonEntries_orderedX
				
				-- Season rows for each season
				for k0 = string.byte('A')-1, string.byte('Z') do
					local k = string.char(k0)
					if k0 == string.byte('A')-1 then k =  end
					
					-- New season row
					local seasonRow = (entry'rotten_tomatoes' .. k or entry'metacritic' .. k or entry'cinemascore' .. k) and root:tag('tr') or mw.html.create('tr')
					
					-- Series name for group overviews
					if X == 1 and (k ==  or k == 'A') and args.series then
						seasonRow:tag('th')
							:attr('scope', 'row')
							:attr('rowspan', SeasonEntriesRows)
							:wikitext(args.series)
					end
					
					-- Season number link, included only in the first row
					if not hide_season then
						if k ==  or k == 'A' then
							seasonRow:tag(args.series and 'td' or 'th')
								:attr('scope', 'row')
								:attr('colspan', entry.special or 1)
								:css('text-align', 'center')
								:wikitext((entry.link and  .. (entry.linkT or season) ..  or (entry.linkT or season)) .. (entry.linkR or ))
						end
					end
				
					-- Rotten Tomatoes
					if not hide_rotten_tomatoes and entry'rotten_tomatoes' .. k ~= 'metacritic' then
						if entry'rotten_tomatoes' .. k then
							local thisCell = CriticalResponse.season_cell(entry'rotten_tomatoes' .. k, frame)
								:css('padding',basePadding)
							seasonRow:node(thisCell)
						else
							local infoCell = CriticalResponse.series_attributes( frame:expandTemplate{title='N/A'} )
							infoCell:css('padding',basePadding)
							seasonRow:node(infoCell)
						end
					end
					
					-- Metacritic
					if not hide_metacritic and entry'metacritic' .. k ~= 'rotten_tomatoes' then
						if entry'metacritic' .. k then
							local thisCell = CriticalResponse.season_cell(entry'metacritic' .. k, frame)
								:css('padding',cellPadding)
							seasonRow:node(thisCell)
						else
							local infoCell = CriticalResponse.series_attributes( frame:expandTemplate{title='N/A'} )
							infoCell:css('padding',cellPadding)
							seasonRow:node(infoCell)
						end
					end
					
					-- CinemaScore
					if show_cinemascore and entry'cinemascore' .. k ~= 'rotten_tomatoes' then
						if entry'cinemascore' .. k then
							local thisCell = CriticalResponse.season_cell(entry'cinemascore' .. k, frame)
								:css('padding',cellPadding)
							seasonRow:node(thisCell)
						else
							local infoCell = CriticalResponse.series_attributes( frame:expandTemplate{title='N/A'} )
							infoCell:css('padding',cellPadding)
							seasonRow:node(infoCell)
						end
					end
				
				end -- End k0 string.byte
			end -- End 'for' SeasonEntries_ordered
		end -- End 'if' multiseries
	end -- End 'do' season rows
	return (args.dontclose and mw.ustring.gsub(tostring(root), "", "") or tostring(root)) .. categories
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p = {}
function p.main(frame)
	local args = require('Mô đun:Arguments').getArgs(frame, {
		wrappers = 'Bản mẫu:Phản ứng phê bình trên truyền hình'
	})
	return CriticalResponse.new(frame, args)
end
return p