|
|
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) |
| Zeile 5: |
Zeile 5: |
| local wik = require("Modul:Wiki") | | local wik = require("Modul:Wiki") |
| local que = require("Modul:Queries") | | local que = require("Modul:Queries") |
| local lfd = require("Modul:LinkFormDatum")
| |
|
| |
|
| local fab_zeilen = require("Modul:Faktenbox/Zeilen") | | local fab_zeilen = require("Modul:Faktenbox/Zeilen") |
| Zeile 169: |
Zeile 168: |
| -- Tab draus machen | | -- Tab draus machen |
| t = p.tab_(t, "Benennungen") | | t = p.tab_(t, "Benennungen") |
| -- mw.log("t = " .. t)
| |
| return t
| |
| end
| |
|
| |
| function p.adressenTab_(fbdata)
| |
| -- mw.log("adressenTab_()")
| |
| -- mw.logObject(fbdata)
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- =p.adressenTab_({fullpagename="Jakob Bock"})
| |
| -- =p.adressenTab_({fullpagename="Ludwig Erhard"})
| |
| -- =p.adressenTab_({fullpagename="Druck & Kopie Hartmann KG"})
| |
| -- =p.adressenTab_({fullpagename="Rathaus"})
| |
| -- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"})
| |
| -- =p.adressenTab_({fullpagename="TestPerson2"})
| |
| -- =p.adressenTab_({fullpagename="Jakob Wassermann"})
| |
| local t = ""
| |
|
| |
| -- Attribute-Liste
| |
| local attr = {
| |
| ["Adressart"] = { querypostfix = "", default = ""},
| |
| ["Straße"] = { querypostfix = "#-", default = ""},
| |
| ["Hausnummer"] = { querypostfix = "", default = 0},
| |
| ["StraßeHnr"] = { querypostfix = "#-", default = ""},
| |
| ["VonObjekt"] = { querypostfix = "#-", default = ""},
| |
| ["AdresseVon"] = { querypostfix = "", default = ""},
| |
| ["AdresseBis"] = { querypostfix = "", default = ""}}
| |
|
| |
| -- DB-Abfrage
| |
| local query = "[[-Has subobject::".. fbdata.fullpagename .. "]][[SubObjektTyp::Adresse]]|?#-|limit=100"
| |
| for i, a in pairs(attr) do
| |
| query = query .. "|?" .. i .. a.querypostfix
| |
| end
| |
| local addresses = mw.smw.ask(query)
| |
|
| |
| if addresses ~= nil then
| |
|
| |
| -- defaults fehlender Attribute und Sortier-Index setzen
| |
| for i, _ in pairs(addresses) do
| |
| for j, a in pairs(attr) do
| |
| addresses[i][j] = addresses[i][j] or a.default
| |
| end
| |
| addresses[i].von_sort_index = smwDate2SortIndex(addresses[i]["AdresseVon"])
| |
| addresses[i].bis_sort_index = smwDate2SortIndex(addresses[i]["AdresseBis"])
| |
| end
| |
|
| |
| -- Tabelle sortieren
| |
| for i = 1, #addresses - 1 do -- max. #addresses - 1 Durchgänge nötig
| |
| local swap_this_interation = false
| |
| for j = 1, #addresses - 1 do
| |
| local swap = vonBisSortCompare(addresses[j], addresses[j+1])
| |
| if swap then
| |
| addresses[j], addresses[j+1] = addresses[j+1], addresses[j]
| |
| end
| |
| swap_this_interation = swap_this_interation or swap
| |
| end
| |
| if not swap_this_interation then
| |
| break
| |
| end
| |
| end
| |
|
| |
| -- Liste erstellen
| |
| t = t .. "<nowiki></nowiki>\n" -- nötig, warum auch immer, damit erster Listeeintrag richtig gerendert wird
| |
| for _, e in ipairs(addresses) do
| |
| t = t .. "* '''" -- Zeilenanfang Liste
| |
| -- Straße/Hausnummer ausgeben
| |
| if wik.pageExists(e["StraßeHnr"]) then -- Link zu Einzel-Gebäude-Seite
| |
| t = t .. "[[" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["VonObjekt"]) then -- alternativ Link zu Gebäude-Komplex-Seite
| |
| t = t .. "[[" .. e["VonObjekt"] .. "|" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["Straße"]) then -- alternativ Link zu Straße-Seite
| |
| t = t .. "[[" .. e["Straße"] .. "]] " .. tostring(e["Hausnummer"])
| |
| else
| |
| t = t .. "" .. e["StraßeHnr"] .. "" -- alternativ nur fetter Text
| |
| end
| |
| t = t .. "'''"
| |
| -- Zusatzinfos in Klammern anfügen
| |
| local bracket = {}
| |
| if e["Adressart"] ~= "" then
| |
| table.insert(bracket, e["Adressart"])
| |
| end
| |
| if e["AdresseVon"] ~= "" then
| |
| table.insert(bracket, "von " .. lfd.formatDate(e["AdresseVon"]))
| |
| end
| |
| if e["AdresseBis"] ~= "" then
| |
| table.insert(bracket, "bis " .. lfd.formatDate(e["AdresseBis"]))
| |
| end
| |
| if #bracket > 0 then
| |
| t = t .. " (" .. table.concat(bracket, " ") ..")"
| |
| end
| |
| t = t .. "\n"
| |
| end
| |
| end
| |
|
| |
| -- Tab draus machen
| |
| t = p.tab_(t, "Adressen")
| |
| -- mw.log("t = " .. t) | | -- mw.log("t = " .. t) |
| return t | | return t |
| Zeile 277: |
Zeile 181: |
| -- mw.log("t = " .. t) | | -- mw.log("t = " .. t) |
| return t | | return t |
| end
| |
|
| |
| function smwDate2SortIndex(date)
| |
| -- mw.log("smwDate2SortIndex(" .. date .. ")")
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- =p.smwDate2SortIndex("2000")
| |
| -- =p.smwDate2SortIndex("Februar 2000")
| |
| -- =p.smwDate2SortIndex("3. Februar 2000")
| |
| local sort_index = ""
| |
| local date=str.split2(date, " ")
| |
|
| |
| if #date == 1 then -- nur Jahr
| |
| sort_index = tostring(date[1]) ..
| |
| "0101" -- 1. Januar
| |
| elseif #date == 2 then -- nur Monat + Jahr
| |
| sort_index = tostring(date[2]) ..
| |
| string.format("%02d", com.getMonthnr(date[1])) ..
| |
| "01" -- 1. Tag
| |
| elseif #date == 3 then -- komplettes Datum
| |
| sort_index = tostring(date[3]) ..
| |
| string.format("%02d",com.getMonthnr(date[2])) ..
| |
| string.format("%02d", tonumber(string.match(date[1], "%d*")))
| |
| end
| |
| sort_index = tonumber(sort_index) or 0
| |
| -- mw.log("sort_index = " .. tostring(sort_index))
| |
| return sort_index
| |
| end
| |
|
| |
| function vonBisSortCompare(k1, k2)
| |
| -- mw.log("vonBisSortCompare(k1, k2)")
| |
| -- mw.logObject(k1)
| |
| -- mw.logObject(k2)
| |
| local swap = false
| |
| if k1.bis_sort_index ~= 0 then
| |
| if k2.von_sort_index ~= 0 then
| |
| swap = ( k1.bis_sort_index > k2.von_sort_index )
| |
| elseif k2.bis_sort_index ~= 0 then
| |
| swap = ( k1.bis_sort_index > k2.bis_sort_index )
| |
| end
| |
| elseif k1.von_sort_index ~= 0 then
| |
| if k2.von_sort_index ~= 0 then
| |
| swap = ( k1.von_sort_index > k2.von_sort_index )
| |
| elseif k2.bis_sort_index ~= 0 then
| |
| swap = ( k1.von_sort_index > k2.bis_sort_index )
| |
| end
| |
| else
| |
| if k2.von_sort_index ~= 0 or k2.bis_sort_index ~= 0 then
| |
| swap = true
| |
| end
| |
| end
| |
| -- mw.log("swap = " .. tostring(swap))
| |
| return swap
| |
| end | | end |
|
| |
|
| return p | | return p |