15.075
Bearbeitungen
(besserer von/bis-Text) |
(Kommentar) |
||
| (7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 18: | Zeile 18: | ||
-- =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 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 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 | ||
| Zeile 86: | Zeile 79: | ||
end | end | ||
if e["AdresseVon"] ~= "" then | if e["AdresseVon"] ~= "" then | ||
if e["AdresseBis"] | if e["AdresseBis"] == "" then | ||
table.insert(bracket, "seit") | |||
table.insert(bracket, "seit " | |||
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, "- " | table.insert(bracket, "-") | ||
else | else | ||
table.insert(bracket, "bis " | table.insert(bracket, "bis") | ||
end | end | ||
table.insert(bracket, lfd.formatDate(e["AdresseBis"])) | |||
end | end | ||
if #bracket > 0 then | if #bracket > 0 then | ||
| Zeile 104: | Zeile 97: | ||
t = t .. "\n" | t = t .. "\n" | ||
end | end | ||
end | |||
end -- Ende if Adressen vorhanden | |||
-- Tab draus machen | -- Tab draus machen | ||
| Zeile 112: | Zeile 106: | ||
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 Apr. 1989 => 19890423 | |||
-- Konsolenzeile zum Debuggen: | -- Konsolenzeile zum Debuggen: | ||
-- =p.smwDate2SortIndex("2000") | -- =p.smwDate2SortIndex("2000") | ||
| Zeile 120: | 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 | 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", com.getMonthnr(date[1])) | ||
sort_index = tostring(date[3]) .. | 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*"))) | |||
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 | ||