15.133
Bearbeitungen
(str.list) |
(+ stadtteil2PLZ()/Stadtteil2PLZ) |
||
| Zeile 97: | Zeile 97: | ||
function p.getPLZList() | function p.getPLZList() | ||
local plzlist = q.getPages("[[Kategorie:Postleitzahlen]] [[PLZ::+]]", true) | |||
table.sort(plzlist) | |||
-- mw.logObject(plzlist) | |||
return plzlist | |||
end | |||
function p.Stadtteil2PLZ(frame) | |||
mw.logObject(frame) | |||
local plzlist = "" | |||
local stadtteile = frame.args[1] | |||
if not c.isEmpty(stadtteile) then | |||
local stadtteilTable = str.split(stadtteile, ";") | |||
local plztable = p.stadtteil2PLZ(stadtteilTable) | |||
plzlist = str.list(plztable, ";") | |||
end | |||
-- mw.log(plzlist) | |||
return plzlist | |||
end | |||
function p.stadtteil2PLZ(stadtteile) | |||
-- gibt die Postleitzahlen der Stadtteile als table zurück | |||
local plztable = {} | |||
if not c.isEmpty(stadtteile) then | |||
if type(stadtteile) == "table" then | |||
for _, s in pairs(stadtteile) do | |||
for _, p in pairs(q.getValues(s, "PLZ", true)) do -- p ist string | |||
plztable[tonumber(p)] = true -- diese Mechanik verhindert mehrfaches Einfügen der gleichen PLZ | |||
end | |||
end | |||
else | |||
plztable[tonumber(q.getValues(stadtteile, "PLZ", true)[1])] = true | |||
end | |||
end | |||
-- mw.logObject(plztable) | |||
local plzlist = {} -- Tabelle in sortierte Liste überführen | |||
for p, _ in pairs(plztable) do | |||
table.insert(plzlist, p) | |||
end | |||
table.sort(plzlist) | |||
-- mw.logObject(plzlist) | |||
return plzlist | |||
end | end | ||
return p | return p | ||