Anonimo

Modulo:DTFunzioniComuni: differenze tra le versioni

Da Wikitrek.
nessun oggetto della modifica
(Error in case of no linked entity)
Nessun oggetto della modifica
Riga 72: Riga 72:
return table.concat(results, ', ')
return table.concat(results, ', ')
end
end
--- Three dashes indicate the beginning of a function or field documented
 
-- using the LDoc format
--------------------------------------------------------------------------------
-- Return a specific Property from Item and/or Instance and/or
-- Instance of Instance.
-- Return the single or multiple values of the Property
--
-- @param Property The property whose values are returned
-- @param Property The property whose values are returned
-- @param Depth How far to go on the tree: 1 - item only, 2 - item and Instance, 3 - item, Instance and Instance of Instance
-- @param Depth How far to go on the tree: 1 - item only,
-- @param Aggregate Wether to aggregate results or return the first found
--                                        2 - item and Instance,
-- @param SkipItem Don't return value for current item, Instance and Instance of Instance only
--                                        3 - item, Instance and
-- @return Table withs strings or wikilinks
--                                            Instance of Instance
-- @param Aggregate Wether to aggregate results or return upon first match
-- @param SkipItem Don't return value for current item,
--                return Instance and Instance of Instance only
-- @return Table with strings or wikilinks
--------------------------------------------------------------------------------
function p.PropertiesOnTree(Property, Depth, Aggregate, SkipItem)
function p.PropertiesOnTree(Property, Depth, Aggregate, SkipItem)
local CurrentItem = mw.wikibase.getEntity()
local CurrentItem = mw.wikibase.getEntity()
Riga 84: Riga 93:
local InstanceInstanceItem = nil
local InstanceInstanceItem = nil
local ResultsArray = {}
local ResultsArray = {}
--local ItemQ = mw.wikibase.getEntityIdForCurrentPage()
if not CurrentItem then
if not CurrentItem then
CurrentItem = mw.wikibase.getEntity('Q1')
CurrentItem = mw.wikibase.getEntity('Q1')
Riga 101: Riga 109:
if Depth > 1 and CurrentItem['claims']['P14'] then
if Depth > 1 and CurrentItem['claims']['P14'] then
--Set instance of
--Set instance of
--ResultsArray[#ResultsArray + 1] = ">1"
InstanceItem = mw.wikibase.getEntity(CurrentItem['claims']['P14'][1].mainsnak.datavalue.value['id'])
InstanceItem = mw.wikibase.getEntity(CurrentItem['claims']['P14'][1].mainsnak.datavalue.value['id'])
if Depth > 2 and InstanceItem['claims']['P14'] then
if Depth > 2 and InstanceItem['claims']['P14'] then
--Set instance of instance
--Set instance of instance
--ResultsArray[#ResultsArray + 1] = ">2"
InstanceInstanceItem = mw.wikibase.getEntity(InstanceItem['claims']['P14'][1].mainsnak.datavalue.value['id'])
InstanceInstanceItem = mw.wikibase.getEntity(InstanceItem['claims']['P14'][1].mainsnak.datavalue.value['id'])
end
end
Riga 128: Riga 134:
end
end
--for _, Item in pairs({CurrentItem, InstanceItem, InstanceInstanceItem}) do
for _, Item in pairs(QList) do
for _, Item in pairs(QList) do
--ResultsArray[#ResultsArray + 1] = "For - " .. Item.id  
--ResultsArray[#ResultsArray + 1] = "For - " .. Item.id  
if Item ~= nil and Item.claims[Property] then
if Item ~= nil and Item.claims[Property] then
--ResultsArray[#ResultsArray + 1] = Item.id .. " - " .. Property
--ResultsArray[#ResultsArray + 1] = LabelOrLink(Item.claims[Property][1].mainsnak.datavalue.value.id)
local Values = Item.claims[Property]
local Values = Item.claims[Property]
for _, SnakValue in pairs(Values) do
for _, SnakValue in pairs(Values) do
if SnakValue.mainsnak.datavalue.value.amount ~= nil then
if SnakValue.mainsnak.datavalue.value.amount ~= nil then
ResultsArray[#ResultsArray + 1] = string.format('%u', SnakValue.mainsnak.datavalue.value.amount)
--ResultsArray[#ResultsArray + 1] = string.format('%u', SnakValue.mainsnak.datavalue.value.amount)
table.insert(ResultsArray, string.format('%u', SnakValue.mainsnak.datavalue.value.amount))
elseif SnakValue.mainsnak.datavalue.value.id ~= nil then
elseif SnakValue.mainsnak.datavalue.value.id ~= nil then
ResultsArray[#ResultsArray + 1] = LabelOrLink(SnakValue.mainsnak.datavalue.value.id)
--ResultsArray[#ResultsArray + 1] = LabelOrLink(SnakValue.mainsnak.datavalue.value.id)
table.insert(ResultsArray, LabelOrLink(SnakValue.mainsnak.datavalue.value.id))
else
else
ResultsArray[#ResultsArray + 1] = SnakValue.mainsnak.datavalue.value
--ResultsArray[#ResultsArray + 1] = SnakValue.mainsnak.datavalue.value
table.insert(ResultsArray, SnakValue.mainsnak.datavalue.value)
end
end
end
end
if not Aggregate then
if not Aggregate then
return ResultsArray
return ResultsArray[1]
end
end
end
end