21.056
Bearbeitungen
(Die Seite wurde neu angelegt: „local p = {} local com = require("Modul:Common") local str = require("Modul:String") local wik = require("Modul:Wiki") local que = require("Modul:Queries") local lfd = require("Modul:LinkFormDatum") local fab_tabs = require("Modul:Faktenbox/Tabs") function p.adressenTab_(fbdata) -- mw.log("adressenTab_()") -- mw.logObject(fbdata) -- Konsolenzeile zum Debuggen: -- =p.adressenTab_({fullpagename="Jakob Bock"}) -- =p.adressenTab_({fullpagename="Ludwig E…“) |
(+ Attribut:Gebäude) |
||
| (14 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
local p = {} | local p = {} | ||
local str = require("Modul:String") | local str = require("Modul:String") | ||
local wik = require("Modul:Wiki") | local wik = require("Modul:Wiki") | ||
local | local kal = require("Modul:Kalender") | ||
local lfd = require("Modul:LinkFormDatum") | local lfd = require("Modul:LinkFormDatum") | ||
| Zeile 18: | Zeile 17: | ||
-- =p.adressenTab_({fullpagename="Rathaus"}) | -- =p.adressenTab_({fullpagename="Rathaus"}) | ||
-- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"}) | -- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"}) | ||
-- =p.adressenTab_({fullpagename="Jakob Wassermann"}) | -- =p.adressenTab_({fullpagename="Jakob Wassermann"}) | ||
-- =p.adressenTab_({fullpagename="Hedwig Gellinger"}) | |||
local t = "" | local t = "" | ||
| Zeile 29: | Zeile 28: | ||
["StraßeHnr"] = { querypostfix = "#-", default = ""}, | ["StraßeHnr"] = { querypostfix = "#-", default = ""}, | ||
["VonObjekt"] = { querypostfix = "#-", default = ""}, | ["VonObjekt"] = { querypostfix = "#-", default = ""}, | ||
["Gebäude"] = { querypostfix = "#-", default = ""}, | |||
["AdresseVon"] = { querypostfix = "", default = ""}, | ["AdresseVon"] = { querypostfix = "", default = ""}, | ||
["AdresseBis"] = { querypostfix = "", default = ""}} | ["AdresseBis"] = { querypostfix = "", default = ""}, | ||
["Kommentar"] = { querypostfix = "", default = ""}} | |||
-- DB-Abfrage | -- SMW-DB-Abfrage | ||
local query = "[[-Has subobject::".. fbdata.fullpagename .. "]][[SubObjektTyp::Adresse]]|?#-|limit=100" | local query = "[[-Has subobject::".. fbdata.fullpagename .. "]][[SubObjektTyp::Adresse]]|?#-|limit=100" | ||
for i, a in pairs(attr) do | for i, a in pairs(attr) do | ||
| Zeile 39: | Zeile 40: | ||
local addresses = mw.smw.ask(query) | local addresses = mw.smw.ask(query) | ||
if addresses ~= nil then | if addresses ~= nil then -- Adressen vorhanden? | ||
-- defaults fehlender Attribute | -- defaults setzen fehlender Attribute | ||
for i, _ in pairs(addresses) do | for i, _ in pairs(addresses) do | ||
for j, a in pairs(attr) do | for j, a in pairs(attr) do | ||
addresses[i][j] = addresses[i][j] or a.default | addresses[i][j] = addresses[i][j] or a.default | ||
end | end | ||
end | end | ||
-- | -- Chronologische Sortierung | ||
if #addresses > 1 then | |||
-- Sortier-Indizes setzen | |||
for | for i, _ in pairs(addresses) do | ||
addresses[i].von_sort_index, addresses[i].bis_sort_index = p.sortIndex(addresses[i]) | |||
end | end | ||
-- Tabelle sortieren | |||
table.sort(addresses, function(a1, a2) return a1.bis_sort_index < a2.von_sort_index end) | |||
end | end | ||
-- Liste erstellen | -- Liste erstellen | ||
t = t .. "<nowiki></nowiki>\n" | t = t .. "<nowiki></nowiki>\n" -- nötig, warum auch immer, damit erster Listeeintrag richtig gerendert wird | ||
for _, e in ipairs(addresses) do | for _, e in ipairs(addresses) do | ||
t = t .. "* '''" | t = t .. "* '''" -- Zeilenanfang Liste | ||
-- Straße/Hausnummer ausgeben | -- Straße/Hausnummer ausgeben | ||
if wik.pageExists(e["StraßeHnr"]) then | if wik.pageExists(e["StraßeHnr"]) then -- Link zu Einzel-Gebäude-Seite | ||
t = t .. "[[" .. e["StraßeHnr"] .. "]]" | t = t .. "[[" .. e["StraßeHnr"] .. "]]" | ||
elseif wik.pageExists(e["VonObjekt"]) then | elseif wik.pageExists(e["VonObjekt"]) then -- alternativ Link zu Gebäude-Komplex-Seite | ||
t = t .. "[[" .. e["VonObjekt"] .. "|" .. e["StraßeHnr"] .. "]]" | t = t .. "[[" .. e["VonObjekt"] .. "|" .. e["StraßeHnr"] .. "]]" | ||
elseif wik.pageExists(e["Straße"]) then | elseif wik.pageExists(e["Gebäude"]) then -- alternativ Link zu Gebäude-Komplex-Seite | ||
t = t .. "[[" .. e["Gebäude"] .. "|" .. e["StraßeHnr"] .. "]]" | |||
elseif wik.pageExists(e["Straße"]) then -- alternativ Link zu Straße-Seite | |||
t = t .. "[[" .. e["Straße"] .. "]] " .. tostring(e["Hausnummer"]) | t = t .. "[[" .. e["Straße"] .. "]] " .. tostring(e["Hausnummer"]) | ||
elseif e["StraßeHnr"] ~= "" then | |||
t = t .. "" | t = t .. e["StraßeHnr"] -- alternativ nur fetter Text | ||
elseif e["Kommentar"] ~= "" then | |||
t = t .. e["Kommentar"] -- alternativ nur fetter Text | |||
else | |||
t = t .. " " -- damit es keine Probleme gibt mit ''' | |||
end | end | ||
t = t .. "'''" | t = t .. "'''" | ||
| Zeile 86: | Zeile 86: | ||
end | end | ||
if e["AdresseVon"] ~= "" then | if e["AdresseVon"] ~= "" then | ||
if e["AdresseBis"] | if e["AdresseBis"] == "" then | ||
table.insert(bracket, " | table.insert(bracket, "seit") | ||
end | |||
table.insert(bracket, lfd.formatDate(e["AdresseVon"])) | |||
end | |||
if e["AdresseBis"] ~= "" and e["AdresseBis"] ~= e["AdresseVon"] then | |||
if e["AdresseVon"] ~= "" then | |||
table.insert(bracket, "-") | |||
else | else | ||
table.insert(bracket, " | table.insert(bracket, "bis") | ||
end | end | ||
table.insert(bracket, lfd.formatDate(e["AdresseBis"])) | |||
table.insert(bracket, | |||
end | end | ||
if #bracket > 0 then | if #bracket > 0 then | ||
| Zeile 100: | Zeile 104: | ||
t = t .. "\n" | t = t .. "\n" | ||
end | end | ||
end | |||
end -- Ende if Adressen vorhanden | |||
-- Tab draus machen | -- Tab draus machen | ||
| Zeile 108: | Zeile 113: | ||
end | end | ||
function smwDate2SortIndex(date) | function p.sortIndex(address) | ||
-- mw.log("sortIndex(address)") | |||
-- mw.logObject(address) | |||
-- Datums-Index holen | |||
local von_sort_index = p.smwDate2SortIndex(address["AdresseVon"], "von") | |||
local bis_sort_index = p.smwDate2SortIndex(address["AdresseBis"], "bis") | |||
-- Ggf. Index von Geburtshaus/-ort setzen | |||
-- ganz nach vorne => höchste Prio = -99999999 | |||
if string.find(address["Adressart"], "Geburt") == 1 then -- beginnt mit "Geburt" | |||
von_sort_index = -99999999 | |||
end | |||
-- Ggf. Index von "Letzter Wohnort" (nicht unbedingt Fürth!) setzen | |||
-- ganz nach hinten => niedrigste Prio = 99999999 | |||
if address["Adressart"] == "Letzter Wohnort" then -- exakte Übereinstimmung | |||
von_sort_index = 99999999 | |||
bis_sort_index = 99999999 | |||
-- Ggf. Index von fehlenden von/bis setzen | |||
-- wenn fehlt, ganz nach hinten (aber vor "Letzter Wohnort") => drittniedrigste Prio = 77777777 | |||
-- "Letzter Wohnort" => zweitniedrigste Prio = 88888888 | |||
elseif von_sort_index == 0 and bis_sort_index == 0 then | |||
if string.find(address["Adressart"], "Letzter Wohnort") == 1 then -- beginnt mit "Letzter Wohnort" | |||
von_sort_index = 88888888 | |||
bis_sort_index = 88888888 | |||
else | |||
von_sort_index = 77777777 | |||
bis_sort_index = 77777777 | |||
end | |||
-- Übernahme fehlender Index von | |||
elseif von_sort_index == 0 and bis_sort_index ~= 0 then | |||
von_sort_index = bis_sort_index | |||
-- Übernahme fehlender Index bis | |||
elseif bis_sort_index == 0 and von_sort_index ~= 0 then | |||
bis_sort_index = von_sort_index | |||
-- Korrektur von > bis | |||
elseif von_sort_index > bis_sort_index then | |||
von_sort_index = bis_sort_index -- den kleineren übernehmen | |||
end | |||
-- mw.log(von_sort_index .. " - " .. bis_sort_index) | |||
return von_sort_index, bis_sort_index | |||
end | |||
function p.smwDate2SortIndex(date, vonbis) | |||
-- mw.log("smwDate2SortIndex(" .. date .. ")") | -- mw.log("smwDate2SortIndex(" .. date .. ")") | ||
-- Datum in Index wandeln | |||
-- Bsp.: 23 April 1989 => 19890423 | |||
-- Konsolenzeile zum Debuggen: | -- Konsolenzeile zum Debuggen: | ||
-- =p.smwDate2SortIndex("2000") | -- =p.smwDate2SortIndex("2000") | ||
| Zeile 116: | Zeile 164: | ||
local sort_index = "" | local sort_index = "" | ||
local date=str.split2(date, " ") | local date=str.split2(date, " ") | ||
if #date == 1 then -- nur Jahr vorhanden | |||
if #date == 1 then -- nur Jahr | sort_index = tostring(date[1]) | ||
sort_index = tostring(date[1]) .. | if vonbis == "von" then | ||
" | sort_index = sort_index .. "9999" | ||
elseif #date == 2 then -- nur Monat + Jahr | else | ||
sort_index = tostring(date[2]) .. | sort_index = sort_index .. "0000" | ||
end | |||
" | elseif #date == 2 then -- nur Monat + Jahr vorhanden | ||
elseif #date == 3 then -- komplettes Datum | sort_index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]]) | ||
if vonbis == "von" then | |||
sort_index = sort_index .. "99" | |||
else | |||
sort_index = sort_index .. "00" | |||
end | |||
elseif #date == 3 then -- komplettes Datum vorhanden | |||
sort_index = tostring(date[3]) .. | sort_index = tostring(date[3]) .. | ||
string.format("%02d", kal.month_numbers[date[2]]) .. | |||
string.format("%02d", tonumber(string.match(date[1], "%d*"))) | |||
end | end | ||
sort_index = tonumber(sort_index) or 0 | sort_index = tonumber(sort_index) or 0 | ||
-- mw.log("sort_index = " .. tostring(sort_index)) | -- mw.log("sort_index = " .. tostring(sort_index)) | ||
return sort_index | return sort_index | ||
end | end | ||
return p | return p | ||