Modul:Adresse: Unterschied zwischen den Versionen
Aus FürthWiki
(- Kategorie:Fehlerhafte Adresse) |
(fix formDate2CompareIndex()) |
||
| Zeile 67: | Zeile 67: | ||
-- subobject setzen | -- subobject setzen | ||
mw.smw.subobject(attr, subobject) | mw.smw.subobject(attr, subobject) | ||
-- Plausibilitätsprüfung von/bis | -- Plausibilitätsprüfung von/bis | ||
if attr["AdresseVon"] ~= nil and attr["AdresseBis"] ~= nil and | if attr["AdresseVon"] ~= nil and attr["AdresseBis"] ~= nil and | ||
p. | p.formDate2CompareIndex(attr["AdresseVon"], "von") > p.formDate2CompareIndex(attr["AdresseBis"], "bis") then | ||
fail = true | fail = true | ||
end | end | ||
| Zeile 86: | Zeile 86: | ||
end | end | ||
function p. | function p.formDate2CompareIndex(date, vonbis) | ||
-- mw.log(" | -- mw.log("formDate2CompareIndex(" .. date .. ")") | ||
-- Datum in Index wandeln | -- Datum in Index wandeln | ||
-- Bsp.: 23 April 1989 => 19890423 | -- Bsp.: 23 April 1989 => 19890423 | ||
-- Konsolenzeile zum Debuggen: | -- Konsolenzeile zum Debuggen: | ||
-- =p. | -- =p.formDate2CompareIndex("2000","von") | ||
-- =p. | -- =p.formDate2CompareIndex("2000","bis") | ||
-- =p. | -- =p.formDate2CompareIndex("Februar 2000","von") | ||
-- =p. | -- =p.formDate2CompareIndex("Februar 2000","bis") | ||
-- =p. | -- =p.formDate2CompareIndex("2000/02/03","von") | ||
-- =p. | -- =p.formDate2CompareIndex("2000/02/03","bis") | ||
local index = "" | local index = "" | ||
local date=str.split2(date, " ") | local date = str.split2(date, "/") | ||
if #date == 1 then | if #date == 3 then -- komplettes Datum vorhanden | ||
index = tostring(date[1]) .. tostring(date[2]) .. tostring(date[3]) | |||
else | |||
date = str.split2(date[1], " ") | |||
if #date == 1 then -- nur Jahr vorhanden | |||
index = tostring(date[1]) | |||
if vonbis == "von" then | |||
index = index .. "0101" | |||
else | |||
index = index .. "1231" | |||
end | |||
elseif #date == 2 then -- nur Monat + Jahr vorhanden | |||
index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]]) | |||
if vonbis == "von" then | |||
index = index .. "01" | |||
else | |||
index = index .. "31" | |||
end | |||
end | end | ||
end | end | ||
index = tonumber(index) or 0 | index = tonumber(index) or 0 | ||
Version vom 15. Januar 2026, 14:04 Uhr
Dieses Modul setzt die Subobjekte von Adressen.
Unterseiten
Siehe auch
local p = {}
local dev = require("Modul:Development")
local str = require("Modul:String")
local geo = require("Modul:Geo")
local wik = require("Modul:Wiki")
local kal = require("Modul:Kalender")
function p.Adresse(frame)
-- mw.logObject(frame, "Adresse(frame)")
-- Konsolenzeile zum Debuggen:
-- =p.Adresse{pargs={["Adressart"]="Wohnung", ["Straße"]="Schwabacher Straße", ["Hausnummer"]="12",["AdresseVon"]="2020-03-04", ["AdresseBis"]="2021-05-06", ["Kommentar"]="f"}}
-- =p.Adresse{pargs={["Adressart"]="Wohnung", ["Straße"]="Fichtenstraße", ["Hausnummer"]="44",["AdresseVon"]="2020-03-04", ["AdresseBis"]="2021-05-06", ["Kommentar"]="f"}}
local t = ""
local fail = false
local frame, pargs = dev.GetFrameAndParentArgs(frame)
local attr, attr_empty = wik.getArgs(pargs, {"Adressart", "AdresseVon", "AdresseBis", "Straße", "Hausnummer", "Kommentar"})
if attr_empty then -- Überhaupt Parameter übergeben?
fail = true
else
-- subobject-Name
local subobject = {}
table.insert(subobject, attr["Adressart"])
table.insert(subobject, attr["Straße"])
table.insert(subobject, attr["Hausnummer"])
subobject = table.concat(subobject, " ")
if subobject == "" then -- subobject-Name fehlerhaft?
fail = true
else
-- SubObjektTyp setzen
attr["SubObjektTyp"] = "Adresse"
-- Straße/Hausnummer auswerten
if attr["Straße"] ~= nil then
if attr["Hausnummer"] ~= nil then
attr["StraßeHnr"] = attr["Straße"] .. " " .. attr["Hausnummer"]
else
attr["StraßeHnr"] = attr["Straße"]
end
elseif attr["Hausnummer"] ~= nil then
fail = true -- Fehler Hausnummer ohne Straße
end
-- Postleitzahl ermitteln
if attr["Straße"] ~= nil then
local PLZ = geo.getPLZ(attr["Straße"], attr["Hausnummer"])
if PLZ ~= "" then
attr["PLZ"] = PLZ
end
end
-- VonObjekt erstellen
if attr["StraßeHnr"] ~= nil then
if wik.pageExists(attr["StraßeHnr"]) then
attr["VonObjekt"] = attr["StraßeHnr"]
else
-- Seite mit passender StraßeHnr suchen
local ask_result = mw.smw.ask("[[:+]][[Kategorie:Gebäude]][[StraßeHnr::" .. attr["StraßeHnr"] .. "]]|?#-|limit=1")
if ask_result ~= nil and #ask_result > 0 then
attr["VonObjekt"] = ask_result[1][1]
end
end
end
-- subobject setzen
mw.smw.subobject(attr, subobject)
-- Plausibilitätsprüfung von/bis
if attr["AdresseVon"] ~= nil and attr["AdresseBis"] ~= nil and
p.formDate2CompareIndex(attr["AdresseVon"], "von") > p.formDate2CompareIndex(attr["AdresseBis"], "bis") then
fail = true
end
end -- Ende if subobject-Name fehlerhaft?
end -- Ende if not attr_empty
-- Wartungsmeldung Adresse fehlerhaft
if fail then
mw.smw.set{["Wartungsmeldung"]="Adresse fehlerhaft"}
end
-- mw.logObject(t, "t")
return t
end
function p.formDate2CompareIndex(date, vonbis)
-- mw.log("formDate2CompareIndex(" .. date .. ")")
-- Datum in Index wandeln
-- Bsp.: 23 April 1989 => 19890423
-- Konsolenzeile zum Debuggen:
-- =p.formDate2CompareIndex("2000","von")
-- =p.formDate2CompareIndex("2000","bis")
-- =p.formDate2CompareIndex("Februar 2000","von")
-- =p.formDate2CompareIndex("Februar 2000","bis")
-- =p.formDate2CompareIndex("2000/02/03","von")
-- =p.formDate2CompareIndex("2000/02/03","bis")
local index = ""
local date = str.split2(date, "/")
if #date == 3 then -- komplettes Datum vorhanden
index = tostring(date[1]) .. tostring(date[2]) .. tostring(date[3])
else
date = str.split2(date[1], " ")
if #date == 1 then -- nur Jahr vorhanden
index = tostring(date[1])
if vonbis == "von" then
index = index .. "0101"
else
index = index .. "1231"
end
elseif #date == 2 then -- nur Monat + Jahr vorhanden
index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]])
if vonbis == "von" then
index = index .. "01"
else
index = index .. "31"
end
end
end
index = tonumber(index) or 0
-- mw.log("index = " .. tostring(index))
return index
end
return p