15.133
Bearbeitungen
(GetPLZ/getPLZ optimiert) |
(Variablen Schreibweise) |
||
| Zeile 75: | Zeile 75: | ||
elseif hausnummer < 9 then plz = 90762 elseif hausnummer < 401 then plz = 90766 else plz = 90768 end -- ungerade H.nr. | elseif hausnummer < 9 then plz = 90762 elseif hausnummer < 401 then plz = 90766 else plz = 90768 end -- ungerade H.nr. | ||
else | else | ||
local | local plz_ask = que.getValues(strasse, "PLZ", true) -- alle anderen Straßen haben nur eine PLZ, die auf deren Seite vemerkt ist | ||
if # | if #plz_ask == 1 then -- mehr als eine oder keine PLZ? | ||
plz = | plz = plz_ask[1] | ||
end | end | ||
end | end | ||
| Zeile 86: | Zeile 86: | ||
function p.GetPLZList(frame) | function p.GetPLZList(frame) | ||
local sep = frame.args.sep or ";" | local sep = frame.args.sep or ";" | ||
local | local plz_table = p.getPLZList() | ||
local | local plz_list = str.list(plz_table, sep) | ||
return | return plz_list | ||
end | end | ||
| Zeile 97: | Zeile 97: | ||
function p.Stadtteil2PLZ(frame) | function p.Stadtteil2PLZ(frame) | ||
-- mw.logObject(frame) | -- mw.logObject(frame) | ||
local | local plz_list = "" | ||
local stadtteile = frame.args[1] | local stadtteile = frame.args[1] | ||
if not com.isEmpty(stadtteile) then | if not com.isEmpty(stadtteile) then | ||
local stadtteilTable = str.split(stadtteile, ";") | local stadtteilTable = str.split(stadtteile, ";") | ||
local | local plz_table = p.stadtteil2PLZ(stadtteilTable) | ||
plz_list = str.list(plz_table, ";") | |||
end | end | ||
-- mw.log( | -- mw.log(plz_list) | ||
return | return plz_list | ||
end | end | ||
function p.stadtteil2PLZ(stadtteile) | function p.stadtteil2PLZ(stadtteile) | ||
-- gibt die Postleitzahlen der Stadtteile als table zurück | -- gibt die Postleitzahlen der Stadtteile als table zurück | ||
local | local plz_table = {} | ||
if not com.isEmpty(stadtteile) then | if not com.isEmpty(stadtteile) then | ||
if type(stadtteile) == "table" then | if type(stadtteile) == "table" then | ||
for _, s in pairs(stadtteile) do | for _, s in pairs(stadtteile) do | ||
for _, p in pairs(que.getValues(s, "PLZ", true)) do -- p ist string | for _, p in pairs(que.getValues(s, "PLZ", true)) do -- p ist string | ||
plz_table[tonumber(p)] = true -- diese Mechanik verhindert mehrfaches Einfügen der gleichen PLZ | |||
end | end | ||
end | end | ||
else | else | ||
plz_table[tonumber(que.getValues(stadtteile, "PLZ", true)[1])] = true | |||
end | end | ||
end | end | ||
-- mw.logObject( | -- mw.logObject(plz_table) | ||
local | local plz_list = {} -- Tabelle in sortierte Liste überführen | ||
for p, _ in pairs( | for p, _ in pairs(plz_table) do | ||
table.insert( | table.insert(plz_list, p) | ||
end | end | ||
table.sort( | table.sort(plz_list) | ||
-- mw.logObject( | -- mw.logObject(plz_list) | ||
return | return plz_list | ||
end | end | ||
return p | return p | ||