Modul:Spiel-Info: Unterschied zwischen den Versionen

Aus LASK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 22: Zeile 22:




-- Erstellt eine Zeile mit mehreren Werten
local function addMatchRow(box, label, date, stadium, result)
local function addMatchRow(box, label, date, stadium, result)


     if date ~= "" or stadium ~= "" or result ~= "" then
     if date ~= "" or stadium ~= "" or result ~= "" then


         local row = box:tag("tr")
         -- Überschrift des Spiels
        box
            :tag("tr")
                :tag("th")
                    :attr("colspan", "4")
                    :wikitext(label)
                    :done()
            :done()


         row
 
             :tag("th")
         -- Datum
                :wikitext(label)
        if date ~= "" then
             box
                :tag("tr")
                    :tag("th")
                        :wikitext("Datum")
                        :done()
                    :tag("td")
                        :wikitext(date)
                        :done()
                 :done()
                 :done()
        end


         row
 
             :tag("td")
         -- Stadion
                :wikitext(date)
        if stadium ~= "" then
             box
                :tag("tr")
                    :tag("th")
                        :wikitext("Stadion")
                        :done()
                    :tag("td")
                        :wikitext(stadium)
                        :done()
                 :done()
                 :done()
        end


        row
            :tag("td")
                :wikitext(stadium)
                :done()


         row
         -- Ergebnis
             :tag("td")
        if result ~= "" then
                :wikitext(result)
             box
                :tag("tr")
                    :tag("th")
                        :wikitext("Ergebnis")
                        :done()
                    :tag("td")
                        :wikitext(result)
                        :done()
                 :done()
                 :done()
 
         end
         row:done()


     end
     end


end
end





Version vom 3. September 2026, 12:38 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Spiel-Info/Doku erstellt werden

local p = {}


-- Erstellt eine normale Zeile der Infobox
local function addRow(box, label, value)

    if value and value ~= "" then

        box
            :tag("tr")
                :tag("th")
                    :wikitext(label)
                    :done()
                :tag("td")
                    :wikitext(value)
                    :done()
            :done()

    end

end


local function addMatchRow(box, label, date, stadium, result)

    if date ~= "" or stadium ~= "" or result ~= "" then

        -- Überschrift des Spiels
        box
            :tag("tr")
                :tag("th")
                    :attr("colspan", "4")
                    :wikitext(label)
                    :done()
            :done()


        -- Datum
        if date ~= "" then
            box
                :tag("tr")
                    :tag("th")
                        :wikitext("Datum")
                        :done()
                    :tag("td")
                        :wikitext(date)
                        :done()
                :done()
        end


        -- Stadion
        if stadium ~= "" then
            box
                :tag("tr")
                    :tag("th")
                        :wikitext("Stadion")
                        :done()
                    :tag("td")
                        :wikitext(stadium)
                        :done()
                :done()
        end


        -- Ergebnis
        if result ~= "" then
            box
                :tag("tr")
                    :tag("th")
                        :wikitext("Ergebnis")
                        :done()
                    :tag("td")
                        :wikitext(result)
                        :done()
                :done()
        end

    end

end



-- Liste der normalen Felder
local fields = {
    {"result", "Endergebnis"},
    {"coach", "Trainer"},
}


-- Hauptfunktion
function p.main(frame)

    -- Parameter der Vorlage holen
    local args = frame:getParent().args


    -- Grundparameter
    local titel = args.titel or ""


    -- Werte für Hin- und Rückspiel
    local date_first_leg = args.date_first_leg or ""
    local stadium_first_leg = args.stadium_first_leg or ""
    local result_first_leg = args.result_first_leg or ""

    local date_second_leg = args.date_second_leg or ""
    local stadium_second_leg = args.stadium_second_leg or ""
    local result_second_leg = args.result_second_leg or ""


    -- Prüfen, ob ein Rückspiel vorhanden ist
    local has_second_leg =
        date_second_leg ~= "" or
        stadium_second_leg ~= "" or
        result_second_leg ~= ""


    -- Tabelle erstellen
    local box = mw.html.create("table")
        :addClass("infobox")


    -- Titel
    if titel ~= "" then

        box
            :tag("caption")
                :wikitext(titel)
                :done()

    end


    -- Spiele
    if has_second_leg then

        addMatchRow(
            box,
            "Hinspiel",
            date_first_leg,
            stadium_first_leg,
            result_first_leg
        )

        addMatchRow(
            box,
            "Rückspiel",
            date_second_leg,
            stadium_second_leg,
            result_second_leg
        )

    else

        addMatchRow(
            box,
            "Spiel",
            date_first_leg,
            stadium_first_leg,
            result_first_leg
        )

    end


    -- Normale Felder
    for _, field in ipairs(fields) do

        local parameter = field[1]
        local label = field[2]

        local value = args[parameter]

        addRow(box, label, value)

    end


    -- HTML zurückgeben
    return tostring(box)

end

return p