21.068
Bearbeitungen
(smwDate2SortIndex() verbessert) |
(+ Attribut:Gebäude) |
||
| (11 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 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 setzen fehlender Attribute | -- defaults setzen fehlender Attribute | ||
| Zeile 59: | Zeile 60: | ||
-- 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 79: | Zeile 86: | ||
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 97: | Zeile 104: | ||
t = t .. "\n" | t = t .. "\n" | ||
end | end | ||
end | |||
end -- Ende if Adressen vorhanden | |||
-- Tab draus machen | -- Tab draus machen | ||
| Zeile 106: | Zeile 114: | ||
function p.sortIndex(address) | function p.sortIndex(address) | ||
-- mw.log("sortIndex(address)") | |||
-- mw.logObject(address) | |||
-- Datums-Index holen | |||
local von_sort_index = p.smwDate2SortIndex(address["AdresseVon"], "von") | local von_sort_index = p.smwDate2SortIndex(address["AdresseVon"], "von") | ||
local bis_sort_index = p.smwDate2SortIndex(address["AdresseBis"], "bis") | local bis_sort_index = p.smwDate2SortIndex(address["AdresseBis"], "bis") | ||
| Zeile 129: | Zeile 140: | ||
bis_sort_index = 77777777 | bis_sort_index = 77777777 | ||
end | end | ||
-- Übernahme fehlender Index von | |||
-- Übernahme fehlender Index von | elseif von_sort_index == 0 and bis_sort_index ~= 0 then | ||
von_sort_index = bis_sort_index | 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 | 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 | ||
| Zeile 143: | Zeile 157: | ||
-- mw.log("smwDate2SortIndex(" .. date .. ")") | -- mw.log("smwDate2SortIndex(" .. date .. ")") | ||
-- Datum in Index wandeln | -- Datum in Index wandeln | ||
-- Bsp.: 23 | -- Bsp.: 23 April 1989 => 19890423 | ||
-- Konsolenzeile zum Debuggen: | -- Konsolenzeile zum Debuggen: | ||
-- =p.smwDate2SortIndex("2000") | -- =p.smwDate2SortIndex("2000") | ||
| Zeile 150: | Zeile 164: | ||
local sort_index = "" | local sort_index = "" | ||
local date=str.split2(date, " ") | local date=str.split2(date, " ") | ||
if #date == 1 then | if #date == 1 then -- nur Jahr vorhanden | ||
sort_index = tostring(date[1]) | sort_index = tostring(date[1]) | ||
if vonbis == "von" then | if vonbis == "von" then | ||
| Zeile 157: | Zeile 171: | ||
sort_index = sort_index .. "0000" | sort_index = sort_index .. "0000" | ||
end | end | ||
elseif #date == 2 then | elseif #date == 2 then -- nur Monat + Jahr vorhanden | ||
sort_index = tostring(date[2]) .. string.format("%02d", | sort_index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]]) | ||
if vonbis == "von" then | if vonbis == "von" then | ||
sort_index = sort_index .. "99" | sort_index = sort_index .. "99" | ||
| Zeile 164: | Zeile 178: | ||
sort_index = sort_index .. "00" | sort_index = sort_index .. "00" | ||
end | end | ||
elseif #date == 3 then | elseif #date == 3 then -- komplettes Datum vorhanden | ||
sort_index = tostring(date[3]) .. string.format("%02d", | 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 | ||