Modul:Klasse: Unterschied zwischen den Versionen

Aus FürthWiki

(+ attributListeParser(), Attribut-Tabelle)
(+ Attribute-Liste in Attribut:Attribut ablegen)
Zeile 49: Zeile 49:
t=t..'</tr><tr>'..
t=t..'</tr><tr>'..
    '<td>[[Attribut:Attribut|Attribut]]</td>'
    '<td>Attribut</td>'
t=t..'<td colspan="3">[[Attribut::Attribut:'..title..']]</td>'
t=t..'<td colspan="3">[[Attribut:'..title..']]</td>'
t=t..'</tr><tr>'..
t=t..'</tr><tr>'..
Zeile 105: Zeile 105:
t = t .. htm.tableFooter()
t = t .. htm.tableFooter()
end
end
-- Attribute-Liste in Attribut:Attribut ablegen
for i = 1, #attr_list do
attr_list[i] = "Attribut:" .. attr_list[i]
end
mw.smw.set{["Attribut"] = attr_list}
return t
return t

Version vom 19. Februar 2026, 09:48 Uhr

Seiten-Übersicht

Zur Klasse Klasse gehörende Seiten:
Hauptseite Unterseiten
Allgemein
Faktenbox Vorlagen
Formulare
Module
Abfrage Vorlagen


Formulare


Sonstige


Faktenbox()

Die Faktenbox der Klassen.

Formular()

Baut das Formular einer Artikelseite (Lemma) einer Klasse zusammen. Als Basis wird dafür die in der jeweiligen Klasse eingetragene Attribut:AttributListe genommen, daraus die Attribut-Datentabelle attr_data generiert und diese weiter an attrForm() im Modul:Formular übergeben.

faktenboxDatenTab()

Baut den Daten-Tab der Faktenbox einer Artikelseite (Lemma) einer Klasse zusammen. Als Basis wird dafür die in der jeweiligen Klasse eingetragene Attribut:AttributListe genommen, daraus die Attribut-Datentabelle attr_data generiert und dann zeilenweise in Reihenfolge der AttributListe abgearbeitet.

Dabei werden die verschiedenen Sonderfälle der Faktenbox-Zeilen beachtet (z. B. Denkmalschutz-Aktennummer, Datum, Ehemals, ...). Siehe Modul:Faktenbox/Zeilen.

getAttrData()

Gibt Attribut-Datentabelle attr_data zurück.

attrListParser()

Analysiert übergebene Attribut:AttributListe und gibt von Attribut-Datentabelle attr_data die Werte attr_data.form_layout, attr_data.width und attr_data.list zurück.

Attribut-Datentabelle attr_data


local p = {}

local com = require("Module:Common")
local str = require("Module:String")
local atr = require("Module:Attribut")
local frm = require("Modul:Formular")
local fab = require("Modul:Faktenbox")
local htm = require("Modul:HTML")

function p.Faktenbox( frame )
	local args = frame:getParent().args
	local t = p.daten( frame, args )
	
	-- Use preprocess to render the factbox and all contens at once
	return frame:preprocess(t)
end

function p.daten(frame, args)
	local title = mw.title.getCurrentTitle().text
	local t = '<table class="wikitable">'..
	    '<th>[[FürthWiki:Semantik]]</th>'..
		'<th colspan="3">'..'[[KlassenName::'..title..']]</th>'

	t=t..'<tr>'..
	    '<td>[[Attribut:Bild|Bild dieser Klasse]]</td>'
	if not com.isEmpty(args.Bild) then
	    t=t..'<td colspan="3"><div class="ImageLink">[[Datei:'..
	    	args.Bild..'|48px]]</div></td>'
	    mw.smw.set{["Bild"] = "Datei:" .. args.Bild}
	end

	t=t..'</tr><tr>'..
	    '<td>[[Attribut:KlassenVorlage|Vorlage]]</td>'
	t=t..'<td colspan="3">[[KlassenVorlage::Vorlage:'..title..']]</td>'
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:KlassenModul|Modul]]</td>'
	t=t..'<td colspan="3">[[KlassenModul::Modul:'..title..']]</td>'
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:KlassenKategorie|Kategorie]]</td>'
	if not com.isEmpty(args.KlassenKategorie) then
	    t=t..'<td colspan="3">[[KlassenKategorie::Kategorie:'..args.KlassenKategorie..']]</td>'
	end
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:KlassenFormular|Formular]]</td>'
	t=t..'<td colspan="3">[[KlassenFormular::Formular:'..title..']]</td>'
	
	t=t..'</tr><tr>'..
	    '<td>Attribut</td>'
	t=t..'<td colspan="3">[[Attribut:'..title..']]</td>'
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:Suchformular|Suchformular]]</td>'
	if not com.isEmpty(args.KlassenKategorie) then
	    t=t..'<td colspan="2">[[Suchformular::Abfrage_'..args.KlassenKategorie..']]</td>'..
	    	'<td>[[Formular:Abfrage_'..args.KlassenKategorie..']]</td>'
	end
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:Suchvorlage|Suchvorlage]]</td>'
	if not com.isEmpty(args.KlassenKategorie) then
	    t=t..'<td colspan="2">[[Suchvorlage::Abfrage_'..args.KlassenKategorie..']]</td>'..
	    	'<td>[[Spezial:Abfrage_ausführen/Abfrage_'..args.KlassenKategorie..']]</td>'
	end
	
	t=t..'</tr><tr>'..
	    '<td>[[Attribut:AttributListe|AttributListe]]</td>'
	if not com.isEmpty(args.AttributListe) then
	    t=t..'<td colspan="3">[[AttributListe::'..args.AttributListe..']]</td>'
	end
	
	t=t..'<tr>'..
		'<td>[[Bild:IconSearch.svg|16px|semantisches Browsen|link=Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}]]</td>'..
		'<td colspan="3">[[Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}|semantisches Browsen]]</td>'..
	'</tr>'
	t=t..'</table>'
	
	-- Attribut-Tabelle
	attr_list = p.attributListeParser(args.AttributListe)
	if #attr_list > 0 then
		attr = {"Attribut", "Datentyp", "EhemalsAttribut",
			"Anzeigegenauigkeit", "Einzahl", "Mehrzahl", "Delimiter",
			"FieldArgs", "Infotext", "Anzeigeformat"}
		-- Tabellen-Kopf
		t = t .. htm.tableHeader(attr)
		-- Tabellen-Zeilen
		for i, a in ipairs(attr_list) do
			local line = {}
			-- Attribut-Attribute
			local attr_val = atr.getAttrAttributes(a, title)
			attr_val = attr_val or {}
			-- Zeile befüllen
			for i, l in ipairs(attr) do
				if l == "Attribut" then
					line[i] = "[[Attribut:" .. a .. "|" .. a .. "]]"
				else
					line[i] = attr_val[l] or ""
				end
			end
			t = t .. htm.tableLine(line)
		end
		-- Tabellen-Fuß
		t = t .. htm.tableFooter()
	end

	-- Attribute-Liste in Attribut:Attribut ablegen
	for i = 1, #attr_list do
		attr_list[i] = "Attribut:" .. attr_list[i]
	end
	mw.smw.set{["Attribut"] = attr_list}
	
	return t
end

function p.getAttrData(klasse)
	local attr_data = {}
	local query = {"[[Klasse:" .. klasse .. "]]",
		"?AttributListe"}
	query = mw.smw.ask(query)
	if query ~= nil then
		local attributliste = query[1]["AttributListe"]
		attributliste = str.splitAndStrip(attributliste, ";")
		if #attributliste > 0 then
			attr_data = {}
			for i, a in ipairs(attributliste) do
				attr_data[i] = atr.getAttrAttributes(a, klasse)
				attr_data[i]["Attribut"] = a
			end
		end
	end
	return attr_data
end

function p.Formular(frame, klasse)
	-- Kommandozeile zum Debuggen:
	-- frame=mw.getCurrentFrame(); print(p.Formular(frame, "Bauwerk"))
	local t = ""
	local attr_data = p.getAttrData(klasse)
	t = frm.attrForm(frame, attr_data)
	return t
end

function p.faktenboxDatenTab(fbdata, kindex)
--	mw.log("datenTab(fbdata)")
--	mw.logObject(frame, "frame")
	--[[ Konsolenzeile zum Debuggen:
	fab=require("Modul:Faktenbox"); fbdata=fab.getFbdata{pargs={Baujahr="1987",AktenNr="D-5-63-000-1464"}};
	fbdata.klasse={"Bauwerk"}; fbdata.kategorie={"Bauwerke"}; fbdata.fullpagename="Pegnitz"; fbdata.subpagename="Pegnitz";
	print(p.faktenboxDatenTab(fbdata)); mw.logObject(fbdata)
	]]
	local t = ""
	local klasse = fbdata.klasse[kindex or 1]
	local attr_data = p.getAttrData(klasse)
	-- Vorbereitung Nicht-unterstützte Argumente testen
	local pargs_test = {}
	for a, _ in pairs(fbdata.pargs) do
		pargs_test[a] = true
	end
	-- Zusammenbau
	t = t .. fab.zeileKategorieSeite(fbdata)
	-- EhemalsAttribut ermitteln (gibt es nur 1x)
	local ehemals_attribut
	for _, a in ipairs(attr_data) do
		if a["EhemalsAttribut"] ~= nil then
			ehemals_attribut = a["EhemalsAttribut"]
			break
		end
	end
	-- Attribut-Zeilen
	for _, a in ipairs(attr_data) do
		local attr = a["Attribut"]
		local delimiter = a["Delimiter"]
		if a["Attribut"] == "AktenNr" then										-- Denkmalschutz Akten-Nummer
			t = t .. fab.zeileAktenNr(fbdata)
		elseif a["EhemalsAttribut"] ~= nil then									-- Kombi von Ehemals-Attribut und Ende-Datum/Jahr
			t = t .. fab.zeileEndeJahr{fbdata = fbdata,							-- Z. B. Ehemals bei Abrissjahr, Verstorben bei Todesdatum
				attr_year = attr, attr_ended = a["EhemalsAttribut"],
				delimiter = delimiter}
		elseif attr ~= ehemals_attribut and attr ~= "Bild" then
			t = t .. fab.zeile{fbdata = fbdata, attr_name = attr,
				delimiter = delimiter}
		end
		pargs_test[a["Attribut"]] = nil											-- Argumente ausklammern
	end
	-- Rest der Tabelle
	t = fab.table_header_footer(t)
	t = t .. fab.zeileSemantikBrowsenAbfrage(fbdata)
	-- Tab draus machen
	t = fab.tab(t, "Daten")
	-- Nicht-unterstützte Argumente testen
	for _, a in ipairs(fab.karten_args ) do										-- Karten-Argumente ausklammern
		pargs_test[a] = nil
	end
	local pargs_test_fail = false
	for _, _ in pairs(pargs_test) do											-- Argumente übrig?
		pargs_test_fail = true
		break
	end
	if pargs_test_fail then
		fab.addWartungsmeldung(fbdata, "Faktenbox-Daten nicht unterstützt (Einzelwerte)")
	end
--	mw.logObject(t, "t")
    return t
end

function p.attributListeParser(attribut_liste)
	-- Kommandozeile zum Debuggen:
	-- mw.logObject(p.attributListeParser("Test1;Test2; Test3 ;; ; "))
	local attr_list = {}
	if not com.isEmpty(attribut_liste) then
		local loop_count = 0
		repeat
			loop_count = loop_count + 1
--			mw.logObject(loop_count, "loop_count")
			-- Komma finden
			local semicolon = string.find(attribut_liste, ";")
			if semicolon == nil	then											-- letzter Eintrag
				semicolon = #attribut_liste + 1
			end
--			mw.logObject(semicolon, "semicolon")
			-- aufteilen und zur attr_list hinzufügen
			local attr = str.strip(string.sub(attribut_liste, 1, semicolon - 1))
--			mw.logObject(attr, "attr")
			if attr ~= "" then
				table.insert(attr_list, attr)
			end
			attribut_liste = string.sub(attribut_liste, semicolon + 1)
		until attribut_liste == "" or loop_count >= 100							-- max. Durchläufe
	end
	return attr_list
end

return p