Modul:Faktenbox/Tabs/Adressen: Unterschied zwischen den Versionen

Aus FürthWiki

Kommentar
(Überarbeitung, + Sortierung Geburtshaus/ort und Letzter Wohnort)
(Kommentar)
 
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 32: Zeile 32:
["AdresseBis"] = { querypostfix = "", default = ""}}
["AdresseBis"] = { 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 39:
local addresses = mw.smw.ask(query)
local addresses = mw.smw.ask(query)


if addresses ~= nil then
if addresses ~= nil then -- Adressen vorhanden?


-- defaults setzen fehlender Attribute
-- defaults setzen fehlender Attribute
Zeile 79: Zeile 79:
end
end
if e["AdresseVon"] ~= "" then
if e["AdresseVon"] ~= "" then
if e["AdresseBis"] ~= "" then
if e["AdresseBis"] == "" then
table.insert(bracket, " " .. lfd.formatDate(e["AdresseVon"]))
table.insert(bracket, "seit")
else
table.insert(bracket, "seit " .. lfd.formatDate(e["AdresseVon"]))
end
end
table.insert(bracket, lfd.formatDate(e["AdresseVon"]))
end
end
if e["AdresseBis"] ~= "" then
if e["AdresseBis"] ~= "" and e["AdresseBis"] ~= e["AdresseVon"] then
if e["AdresseVon"] ~= "" then
if e["AdresseVon"] ~= "" then
table.insert(bracket, "- " .. lfd.formatDate(e["AdresseBis"]))
table.insert(bracket, "-")
else
else
table.insert(bracket, "bis " .. lfd.formatDate(e["AdresseBis"]))
table.insert(bracket, "bis")
end
end
table.insert(bracket, lfd.formatDate(e["AdresseBis"]))
end
end
if #bracket > 0 then
if #bracket > 0 then
Zeile 97: Zeile 97:
t = t .. "\n"
t = t .. "\n"
end
end
end
 
end -- Ende if Adressen vorhanden


-- Tab draus machen
-- Tab draus machen
Zeile 106: Zeile 107:


function p.sortIndex(address)
function p.sortIndex(address)
local von_sort_index = p.smwDate2SortIndex(address["AdresseVon"])
-- mw.log("sortIndex(address)")
local bis_sort_index = p.smwDate2SortIndex(address["AdresseBis"])
-- 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
-- Ggf. Index von Geburtshaus/-ort setzen
-- ganz nach vorne => höchste Prio = -99999999
-- ganz nach vorne => höchste Prio = -99999999
Zeile 129: Zeile 133:
bis_sort_index = 77777777
bis_sort_index = 77777777
end
end
end
-- Übernahme fehlender Index von
-- Übernahme fehlender Index von => bis oder umgekehrt
elseif von_sort_index == 0 and bis_sort_index ~= 0 then
if von_sort_index == 0 and bis_sort_index ~= 0 then
von_sort_index = bis_sort_index
von_sort_index = bis_sort_index
end
-- Übernahme fehlender Index bis
if bis_sort_index == 0 and von_sort_index ~= 0 then
elseif bis_sort_index == 0 and von_sort_index ~= 0 then
bis_sort_index = von_sort_index
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
end
-- mw.log(von_sort_index .. " - " .. bis_sort_index)
return von_sort_index, bis_sort_index
return von_sort_index, bis_sort_index
end
end


function p.smwDate2SortIndex(date)
function p.smwDate2SortIndex(date, vonbis)
-- mw.log("smwDate2SortIndex(" .. date .. ")")
-- mw.log("smwDate2SortIndex(" .. date .. ")")
-- Datum in Index wandeln
-- Datum in Index wandeln
Zeile 150: Zeile 157:
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 vorhanden
sort_index = tostring(date[1]) .. "0101" -- mit 1. Januar ergänzen
sort_index = tostring(date[1])
elseif #date == 2 then -- nur Monat + Jahr vorhanden
if vonbis == "von" then
sort_index = tostring(date[2]) .. string.format("%02d", com.getMonthnr(date[1])) .. "01" -- mit 1. Tag im Monat ergänzen
sort_index = sort_index .. "9999"
elseif #date == 3 then -- komplettes Datum vorhanden
else
sort_index = sort_index .. "0000"
end
elseif #date == 2 then -- nur Monat + Jahr vorhanden
sort_index = tostring(date[2]) .. string.format("%02d", com.getMonthnr(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]) .. string.format("%02d",com.getMonthnr(date[2])) .. string.format("%02d", tonumber(string.match(date[1], "%d*")))
sort_index = tostring(date[3]) .. string.format("%02d",com.getMonthnr(date[2])) .. string.format("%02d", tonumber(string.match(date[1], "%d*")))
end
end