Модуль:GetField: различия между версиями

Нет описания правки
Нет описания правки
 
(не показаны 2 промежуточные версии этого же участника)
Строка 252: Строка 252:
                         if type(first) == "table" then
                         if type(first) == "table" then
                             walk(first, key)
                             walk(first, key)
                        elseif first ~= nil then
                            parts[#parts + 1] = key .. "=" .. tostring(first)
                         end
                         end
                     else
                     else
Строка 355: Строка 353:
     local pagePath = args[2] or ""
     local pagePath = args[2] or ""
     local keyPath = args[3] or ""
     local keyPath = args[3] or ""
    local searchType = (args.searchType or ""):lower()


     if searchValue == "" or pagePath == "" or keyPath == "" then
     if searchValue == "" or pagePath == "" or keyPath == "" then
         return ""
         return ""
    end
    if searchType == "" then
        searchType = "value"
     end
     end


Строка 369: Строка 371:
     end
     end


     local matches = find_matching_ids(idsTable, keyPath, searchValue)
     local matches
    if searchType == "key" then
        local target = tostring(searchValue)
        matches = {}
        for idKey, entry in pairs(idsTable) do
            if type(entry) == "table" then
                local v = get_by_path(entry, keyPath)
                if type(v) == "table" and v[target] ~= nil then
                    matches[#matches + 1] = idKey
                end
            end
        end
    else
        matches = find_matching_ids(idsTable, keyPath, searchValue)
    end


     if #matches == 0 then
     if #matches == 0 then
Строка 389: Строка 405:
     local keyPath = args[3] or ""
     local keyPath = args[3] or ""
     local tplPath = mw.text.unstripNoWiki(args[4] or "")
     local tplPath = mw.text.unstripNoWiki(args[4] or "")
    local searchType = (args.searchType or ""):lower()


     if searchValue == "" or pagePath == "" or keyPath == "" or tplPath == "" then
     if searchValue == "" or pagePath == "" or keyPath == "" or tplPath == "" then
         return ""
         return ""
    end
    if searchType == "" then
        searchType = "value"
     end
     end


Строка 403: Строка 423:
     end
     end


     local matches = find_matching_ids(idsTable, keyPath, searchValue)
     local matches
    if searchType == "key" then
        local target = tostring(searchValue)
        matches = {}
        for idKey, entry in pairs(idsTable) do
            if type(entry) == "table" then
                local v = get_by_path(entry, keyPath)
                if type(v) == "table" and v[target] ~= nil then
                    matches[#matches + 1] = idKey
                end
            end
        end
    else
        matches = find_matching_ids(idsTable, keyPath, searchValue)
    end


     if #matches == 0 then
     if #matches == 0 then