Module:CFCR

De ESCR
Aller à la navigation Aller à la recherche

La documentation pour ce module peut être créée à Module:CFCR/doc

local p = {}

--[[ For test
frame = mw.getCurrentFrame() -- Get a frame object
newFrame = frame:newChild{ -- Get one with args
	title = 'Dupond Bertrand' ,
	 args = {
		iri = 'https://data.escr.fr/wiki/Utilisateur:Dupond_Bertrand' ,
		["année"] = '2021' ,
		["niveau"] = 'école supérieure' ,
		["établissement"] = 'Mon école',
		["classe"] = 'A1',
		["méthode pour le contacter"] = ' à contacter par email',
		["demo"] = '1'
	    }
}
mw.log(p.referent( newFrame ) )
--]]

function p.referent(f)
    local capiunto = require 'capiunto'
    local linkedwiki = require 'linkedwiki'
    
	linkedwiki.setCurrentFrame(mw.getCurrentFrame())
	
    -- init the prefix
    local escr = 'https://data.escr.fr/wiki/Data:'
    
    local rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
    -- local xsd = 'http://www.w3.org/2001/XMLSchema#'

    local dateFormat = "d M Y"

    local subject = f.args.iri or linkedwiki.getCurrentIRI();  --find the iri of the current page

    local object = linkedwiki.new(subject,"https://data.escr.fr/data")
    --object:setDebug(true)

	-- for key,value in pairs(f.args) do
	--     mw.log("found member " .. key);
	-- end
    
    if linkedwiki.isEmpty(f.args['demo']) then
	    -- Save the data in the infobox in a knowledge base
	    mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'CFCR#Référent'))
	    mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'CFCR#Référent'..f.args['année']))
	    
	    mw.log(object:addProperty(escr .. 'CFCR#niveau', f.args['niveau'] ))
	    mw.log(object:addPropertyWithIri(escr .. 'CFCR#établissement', mw.uri.decode(mw.title.new(f.args['établissement']):fullUrl()) ))
	    -- mw.log(object:getLastQuery())
	    mw.log(object:addProperty(escr .. 'CFCR#classe', f.args['classe'] ))
	    mw.log(object:addProperty(escr .. 'CFCR#methodePourLeContacter', f.args['méthode pour le contacter'] ))
    end

    --Make infobox with capiunto
    local infobox = capiunto.create({
        title = 'Référent CFCR '..f.args['année'],
        top = '[['..f.args['établissement']..']]',
        topStyle = 'background: #dfedff;  font-size: 1.4em;padding: 15px;'
    })
    
     if not linkedwiki.isEmpty(f.args['classe']) then
		infobox:addRow('Classe', f.args['classe'])
     end

    infobox:addWikitext(f.args['méthode pour le contacter'] )

    return infobox
    --return 	mw.logObject( f.args )
end

return p