وحدة:Wikidata2/P3828
اذهب إلى التنقل
اذهب إلى البحث
local p = {} local Frame = mw.getCurrentFrame() function get_qualifiers_id( snak ) if snak and snak[1] and snak[1].snaktype and snak[1].snaktype == "value" and snak[1].datavalue and snak[1].datavalue.type and snak[1].datavalue.type == "wikibase-entityid" and snak[1].datavalue.value and snak[1].datavalue.value.id then ID = snak[1].datavalue.value.id return ID end end function find_Kit_type( claims , id) local kit_id = "" mw.log( "Module:Wikidata2/P3828: id : ".. id) for i, statement in pairs( claims ) do statement_id = get_snak_id( statement ) if statement.qualifiers and statement.qualifiers["P1013"] then local id2 = get_qualifiers_id( statement.qualifiers["P1013"]) if id2 == id then kit_id = statement_id end end end return kit_id end function Get_image_color( statement ) local tab = {image = "" , color = ""} if statement.qualifiers then qua = statement.qualifiers if qua["P18"] and qua["P18"][1] and qua["P18"][1].datavalue and qua["P18"][1].snaktype and qua["P18"][1].snaktype == "value" and qua["P18"][1].datavalue.value then tab.image = qua["P18"][1].datavalue.value end if qua["P465"] and qua["P465"][1] and qua["P465"][1].datavalue and qua["P465"][1].snaktype and qua["P465"][1].snaktype == "value" and qua["P465"][1].datavalue.value then tab.color = qua["P465"][1].datavalue.value end end return tab end type_of_kit = {} type_of_kit["Q170494"] = "body" type_of_kit["Q223269"] = "shorts" type_of_kit["Q24206679"] = "right_arm" type_of_kit["Q3643394"] = "left_arm" type_of_kit["Q43663"] = "socks" function find_team_Kit( claims , id , title, options) local kit_claims = {} kit_claims["body"] = {image = "" , color = ""} kit_claims["shorts"] = {image = "" , color = ""} kit_claims["right_arm"] = {image = "" , color = ""} kit_claims["left_arm"] = {image = "" , color = ""} kit_claims["socks"] = {image = "" , color = ""} local kit_id = find_Kit_type( claims , id) mw.log( "Module:Wikidata2/P3828: kit_id : ".. kit_id) local entity = getEntityFromId( kit_id ) if not entity then return '' end --TODO error? if not entity.claims or not entity.claims["P527"] then return '' --TODO error? end for i, statement in pairs( entity.claims["P527"] ) do ss_id = get_snak_id( statement ) --table.insert( kit_claims, statement ) if type_of_kit[ss_id] then ss_id = type_of_kit[ss_id] end kit_claims[ss_id] = Get_image_color( statement ) end --local tt = formatStatements( {property ="P527", entityId = kit_id }) local main_args = { qid = kit_id , leftarm_color = kit_claims.left_arm.color or "", Kit_left_arm = kit_claims.left_arm.image or "", body_color = kit_claims.body.color or "", Kit_body = kit_claims.body.image or "", rightarm_color = kit_claims.right_arm.color or "", Kit_right_arm = kit_claims.right_arm.image or "", shorts_color = kit_claims.shorts.color or "", Kit_shorts = kit_claims.shorts.image or "", socks_color = kit_claims.socks.color or "", Kit_socks = kit_claims.socks.image or "", title = title, } ---------- s = mw.getCurrentFrame():expandTemplate{ title = "طقم_كرة_قدم/ويكي بيانات/نواة" , args = main_args} s = addTrackingCategory(s , options) --return Frame:extensionTag("source", mw.dumpObject( main_args ),{ lang= 'lua'}) return s end function p.P3828( claims , options) --local value = statement.mainsnak.datavalue.value options.noicon = "t" --local entit = getEntityIdFromValue( value ) local home_kit = find_team_Kit( claims , "Q45321977" , "الطقم الأساسي", options) local away_kit = find_team_Kit( claims , "Q45321990" , "الطقم الاحتياطي", options) local third_kit = find_team_Kit( claims , "Q45322173" , "الطقم الثالث", options) local Main_Table = {} table.insert(Main_Table , home_kit) table.insert(Main_Table , away_kit) table.insert(Main_Table , third_kit) --[[ leftarm_color = leftarm.color, Kit_left_arm = leftarm.image, body_color = body.color, Kit_body = body.image, rightarm_color = right_arm.color, Kit_right_arm = right_arm.image, shorts_color = shorts.color, Kit_shorts = shorts.image, socks_color = socks.color, Kit_socks = socks.image, title = title, } --]] ---------- s = mw.text.listToText( Main_Table, "", "" ) return s end return p