Modulis:Varsezkom

(Europos futbolo duomenų bazė)
{{fg1}}
{{#invoke:Varsezkom | kom |1|Crumlin United|26|16|7|3|43|25|55}}
{{#invoke:Varsezkom | kom |2|Crumlin United|26|16|7|3|43|25|55||2-3}}
{{#invoke:Varsezkom | kom |20|Witney Town|10=pasitraukė|red=t}}
|}
Vieta Komanda R + = Įvarčiai Tšk. Pastabos V
1. Crumlin United 26 16 7 3 43 — 25 55
2-3. Crumlin United 26 16 7 3 43 — 25 55
20. Witney Town pasitraukė
{{fg1}}
{{#invoke:Varsezkom | komAll |fed=eng|tip=9|met=2012–2013|uef=2013|zona=Combined Counties Football League Division 1}}
|}
Vieta Komanda R + = Įvarčiai Tšk. Pastabos V

local HtmlBuilder = require('Modulis:HtmlBuilder')
local Parm = require('Modulis:Parm')

varsez = {}

varsez.kom = function( frame )
    local args, pargs = frame.args or {}, (frame:getParent() or {}).args or {}
    
    local pg = mw.title.getCurrentTitle()
    local ns = pg.namespace
    local pgname = pg.text
    local fed = Parm._get{ page = pgname, parm = 'fed', namespace = '0' } or ''
    local tip = Parm._get{ page = pgname, parm = 'tip', namespace = '0' } or ''
    local met = Parm._get{ page = pgname, parm = 'met', namespace = '0' } or ''
    local uef = Parm._get{ page = pgname, parm = 'uef', namespace = '0' } or ''

    local vieta = args.vieta or pargs.vieta or mw.text.trim(args[1] or pargs[1] or '')
    local kom = args.kom or pargs.kom or mw.text.trim(args[2] or pargs[2] or '')
    local rung = args.rung or pargs.rung or mw.text.trim(args[3] or pargs[3] or '')
    local laim = args.laim or pargs.laim or mw.text.trim(args[4] or pargs[4] or '')
    local lygu = args.lygu or pargs.lygu or mw.text.trim(args[5] or pargs[5] or '')
    local pralaim = args.pralaim or pargs.pralaim or mw.text.trim(args[6] or pargs[6] or '')
    local imuse = args.imuse or pargs.imuse or mw.text.trim(args[7] or pargs[7] or '')
    local praleid = args.praleid or pargs.praleid or mw.text.trim(args[8] or pargs[8] or '')
    local task = args.task or pargs.task or mw.text.trim(args[9] or pargs[9] or '')
    local past = args.past or pargs.past or mw.text.trim(args[10] or pargs[10] or '')
    local vietarod = args.vietarod or pargs.vietarod or mw.text.trim(args[11] or pargs[11] or '')
    local up = args.up or pargs.up or ''
    local down = args.down or pargs.down or ''
    local red = args.red or pargs.red or ''
    local redlin = "||"
    local runglin = rung
    local rezlin = imuse .. " — " .. praleid
    local tasklin = "'''" .. task .. "'''"
    local uplin = ' ↑'
    local downlin = ' ↓'
    local komlink = kom
    local komshow = kom
    
    local kom2 = mw.ustring.gsub(kom, "'", "''")
    local rtxt = frame:preprocess("{{#get_db_data:|db=foot-db|from=varsez_kom=p "..
                    " |where=p.fed='"..fed.."' and p.tip='"..tip.."' and p.met='"..met.."' and p.uef='"..uef.."' and p.kom='"..kom2.."'|limit=1|data=str=p.kom_str,ist=p.kom_ist}}"..
                    "{{#for_external_table:{{{str}}};{{{ist}}}}}{{#clear_external_data:}}") or ''
    if rtxt ~= '' then
    	local sart = mw.text.split(rtxt, ';')
    	if sart[1] ~= '' then
    		komlink = sart[1]
	    	if sart[2] ~= '' then
	    		komshow = sart[2]
	    	end
    	end
	end

	if vietarod ~= '' then
		vieta = vietarod
	end
    
    if red ~= '' then
    	redlin = "|| colspan=7 bgcolor=#FF0000 |"
    	runglin = ''
    	rezlin = ''
    	tasklin = ''
    	laim = ''
    end
    
    if up == '' then
    	uplin = ''
    end
    
    if down == '' then
    	downlin = ''
    end
    
    local eilute = HtmlBuilder.create()
    
    eilute
    	.newline()
    	.wikitext('|-')
    	.newline()
    	.wikitext('|')
    	--.newline()
    	.wikitext(vieta, '.')
    	--.newline()
    	.wikitext('|| style="text-align: left;" | ')
    	--.newline()
		.wikitext('[[', komlink, '|', komshow, ']]', uplin, downlin)
    	--.newline()
    	.wikitext("||")
    	--.newline()
    	.wikitext(runglin)
    	--.newline()
    	.wikitext("||")
    	--.newline()
		.wikitext(laim)
    	--.newline()
    	.wikitext("||")
    	--.newline()
		.wikitext(lygu)
    	--.newline()
    	.wikitext("||")
    	--.newline()
		.wikitext(pralaim)
    	--.newline()
    	.wikitext("||")
    	--.newline()
		.wikitext(rezlin)
    	--.newline()
    	.wikitext("||")
    	--.newline()
		.wikitext(tasklin)
    	--.newline()
    	.wikitext(redlin)
    	--.newline()
		.wikitext(past)
		.newline()
    	.wikitext('|-')
    	.newline()
		.done()
    
    return tostring(eilute)
end

varsez.komAll = function( frame )
    local args, pargs = frame.args or {}, (frame:getParent() or {}).args or {}
    
    local pg = mw.title.getCurrentTitle()
    local ns = pg.namespace
    local pgname = pg.text
    local fed = Parm._get{ page = pgname, parm = 'fed', namespace = '0' } or args.fed or pargs.fed or ''
    local tip = Parm._get{ page = pgname, parm = 'tip', namespace = '0' } or args.tip or pargs.tip or ''
    local met = Parm._get{ page = pgname, parm = 'met', namespace = '0' } or args.met or pargs.met or ''
    local uef = Parm._get{ page = pgname, parm = 'uef', namespace = '0' } or args.uef or pargs.uef or ''
    local zona = args.zona or pargs.zona or ''

    local zona2 = mw.ustring.gsub(zona, "'", "''")
    local rtxt2 = frame:preprocess("{{#get_db_data:|db=foot-db|from=varsez_kom=p "..
                    " |where=p.fed='"..fed.."' and p.tip='"..tip.."' and p.met='"..met.."' and p.uef='"..uef.."' and p.zona='"..zona2..
                    "'|limit=100|order by=p.vieta+0 ASC|data=vieta=p.vieta,kom=p.kom,rung=p.rung,laim=p.laim,lygu=p.lygu,pralaim=p.pralaim,imuse=p.imuse,praleid=p.praleid,task=p.task,past=p.past,vietarod=p.vietarod,sab=p.sab}}"..
                    "{{#for_external_table:{{{vieta}}};{{{kom}}};{{{rung}}};{{{laim}}};{{{lygu}}};{{{pralaim}}};{{{imuse}}};{{{praleid}}};{{{task}}};{{{past}}};{{{vietarod}}};{{{sab}}}~}}{{#clear_external_data:}}") or ''

    local rtxt2tbl = mw.text.split(rtxt2, '~')
    local rez = HtmlBuilder.create()
    
    for i, lstel in ipairs(rtxt2tbl) do
    	if lstel~='' then
        	local colidm = mw.text.split(lstel,';') or {}

    		local vieta = mw.text.trim(colidm[1]) or ''
    		local kom = mw.text.trim(colidm[2]) or ''
    		local rung = mw.text.trim(colidm[3]) or ''
    		local laim = mw.text.trim(colidm[4]) or ''
    		local lygu = mw.text.trim(colidm[5]) or ''
    		local pralaim = mw.text.trim(colidm[6]) or ''
    		local imuse = mw.text.trim(colidm[7]) or ''
    		local praleid = mw.text.trim(colidm[8]) or ''
    		local task = mw.text.trim(colidm[9]) or ''
    		local past = mw.text.trim(colidm[10]) or ''
    		local vietarod = mw.text.trim(colidm[11]) or ''
    		local sab = mw.text.trim(colidm[12]) or ''
    		
    		local up = args.up or pargs.up or ''
    		local down = args.down or pargs.down or ''
    		local red = args.red or pargs.red or ''
    		if sab == 'fg2' or sab == 'fg4' or sab == 'fg5' then
    			red = ''
    		else
    			red = 'T'
    		end
    		
    		local redlin = "||"
    		local runglin = rung
    		local rezlin = imuse .. " — " .. praleid
    		if sab == 'fg5' then
    			rung = "''" .. rung .. "''"
    			laim = "''" .. laim .. "''"
    			lygu = "''" .. lygu .. "''"
    			pralaim = "''" .. pralaim .. "''"
    			rezlin = "''" .. rezlin .. "''"
    		end
    		local tasklin = "'''" .. task .. "'''"
    		local uplin = ' ↑'
    		local downlin = ' ↓'
    		local komlink = kom
    		local komshow = kom
    		
    		local kom2 = mw.ustring.gsub(kom, "'", "''")
    		local rtxt = frame:preprocess("{{#get_db_data:|db=foot-db|from=varsez_kom=p "..
    		                " |where=p.fed='"..fed.."' and p.tip='"..tip.."' and p.met='"..met.."' and p.uef='"..uef.."' and p.kom='"..kom2.."'|limit=1|data=str=p.kom_str,ist=p.kom_ist}}"..
    		                "{{#for_external_table:{{{str}}};{{{ist}}}}}{{#clear_external_data:}}") or ''
    		if rtxt ~= '' then
    			local sart = mw.text.split(rtxt, ';')
    			if sart[1] ~= '' then
    				komlink = sart[1]
			    	if sart[2] ~= '' then
			    		komshow = sart[2]
			    	end
    			end
			end

			if vietarod ~= '' then
				vieta = vietarod
			end
    		
    		if red ~= '' then
    			redlin = "|| colspan=7 bgcolor=#FF0000 |"
    			runglin = ''
    			rezlin = ''
    			tasklin = ''
    			laim = ''
    		end
    		
    		if up == '' then
    			uplin = ''
    		end
    
    		if down == '' then
    			downlin = ''
    		end
    
    		rez
    			.newline()
    			.wikitext('|-')
    			.newline()
    			.wikitext('|')
    			--.newline()
    			.wikitext(vieta, '.')
    			--.newline()
    			.wikitext('|| style="text-align: left;" | ')
    			--.newline()
				.wikitext('[[', komlink, '|', komshow, ']]', uplin, downlin)
    			--.newline()
    			.wikitext("||")
    			--.newline()
    			.wikitext(runglin)
    			--.newline()
    			.wikitext("||")
    			--.newline()
				.wikitext(laim)
    			--.newline()
    			.wikitext("||")
    			--.newline()
				.wikitext(lygu)
    			--.newline()
    			.wikitext("||")
    			--.newline()
				.wikitext(pralaim)
    			--.newline()
    			.wikitext("||")
    			--.newline()
				.wikitext(rezlin)
    			--.newline()
    			.wikitext("||")
    			--.newline()
				.wikitext(tasklin)
    			--.newline()
    			.wikitext(redlin)
    			--.newline()
				.wikitext(past)
				.newline()
    			.wikitext('|-')
    			.newline()
				.done()
				
		end
	end
    
    return tostring(rez)
end

return varsez