FANDOM


--<nowiki> 
--|Creates a "class" containing each course data
local courseClass = {}
local libraryUtil = require( 'libraryUtil' )
local libUtility = require("Module:Utility")
local libLang  = require('Module:Lang')
 
--Helper functions--
--%Sets current phase
--@oCourse (table) A table containing course content
function setPhase(oCourse)
    local iPhase = 1
    local L1 = oCourse:getL1()
    local L2 = oCourse:getL2()
    local startDate = oCourse:getStartDate()
    local betaDate = oCourse:getBetaDate()
    local releaseDate = oCourse:getReleaseDate()
 
    if L1 and L2 and oCourse:isStaffCourse() then 
        iPhase = 3  
    elseif libUtility.checkDate(startDate) then
            iPhase = 1
        if libUtility.checkDate(betaDate) then
            iPhase = 2
            if libUtility.checkDate(releaseDate) then
                iPhase = 3
            end
        end
    end
 
    oCourse.phase = iPhase
end
--%Creates new course -- e.g. p.new("en", "fr")
--@L1code (string) language code for user's mother tongue
--@L2code(string) language code for learning language
--@startDate (string) phase 1 date
--@betaDate (string) phase 2 date
--@releaseDate (string) phase 3 date
--@p1Ref (string) reference for phase 1 
--@p2Ref (string) reference for phase 2
--@p3Ref (string) reference for phase 3
--@oCourse (table) A table containing course content
--:(table) A table containing data about the course
function courseClass.new(L1code, L2code, startDate, betaDate, releaseDate, p1Ref, p2Ref, p3Ref)
    libraryUtil.checkType( "L1code", 1, L1code, "string")
    libraryUtil.checkType( "L2code", 2, L2code, "string")
    libraryUtil.checkType( "startDate", 1, startDate, "string", true)
    libraryUtil.checkType( "betaDate", 2, betaDate, "string", true)
    libraryUtil.checkType( "releaseDate", 1, releaseDate, "string", true)
    libraryUtil.checkType( "p1Ref", 2, p1Ref, "string", true)
    libraryUtil.checkType( "p2Ref", 1, p2Ref, "string", true)
    libraryUtil.checkType( "p3Ref", 2, p3Ref, "string", true)
 
    local course = {}
    local checkSelf = libraryUtil.makeCheckSelfFunction( 'courseClass', 'course', course, 'courseClass object' )
    -- Staff courses
    local tStaffCourse = {fr = { en = 1 }, 
        en = { fr = 1 , it = 1, de = 1, pt = 1, es = 1},
        it = { en = 1 }, pt = { en = 1 }, es = { en = 1 }, de = { en = 1}
    }
 
    --% Creates a copy (reference) of this "class" and objects to be reused efficiently
    --@obj (table) Object that will be copied
    --@seen (table) A "cached" object I think ...
    function copy(obj, seen)
        if type(obj) ~= 'table' then 
            return obj 
        end
        if seen and seen[obj] then 
            return seen[obj] 
        end
        local s = seen or {}
        local res = setmetatable({}, getmetatable(obj))
        s[obj] = res
        for k, v in pairs(obj) do 
            res[copy(k, s)] = copy(v, s) 
        end
        return res
    end 
    --%Gets language code (i.e users' language)
    --:(string) Returns a user's first language ISO code
    function course:getL1()
        checkSelf(self,"getL1")
        return self.L1
    end
    --% Gets full name of language
    --:(string) Returns a course first language name
    function course:getL1Name()
        checkSelf(self,"getL1Name")
        return libLang.getLang(self.L1) 
    end
    --%Gets language name for language being taught
    --:(string) A course's 2nd language code
    function course:getL2Name()
        checkSelf(self,"getL2Name")
        return libLang.getLang(self.L1) 
    end
    --%Gets language code (i.e learning language)
    --: (string) Language code 
    function course:getL2()
        checkSelf(self,"getL2")
        return self.L2
    end
    --%Sets language code (i.e users' language)
    --@lang (string) language code 
    function course:setL1(lang)
        checkSelf(self,"setL1")
        libraryUtil.checkType( "lang", 1, lang, "string")
        self.L1 = lang
    end
    --%Sets language code (i.e learning language)
    --@lang (string) language code
    function course:setL2(lang)
        checkSelf(self,"setL2")
        libraryUtil.checkType( "lang", 1, lang, "string")
        self.L2 = lang
    end
    --%Gets start date for course construction
    --:(string) Start date for course construction
    function course:getStartDate()
        checkSelf(self,"getStartDate")
        return self.startDate
    end
    --%Gets start date for course construction
    --:(string) Start date for course construction
    function course:setStartDate(pDate)
        checkSelf(self,"setStartDate")
        self.startDate = pDate
        setPhase(self)
    end
    --%Gets date (Beta) when course is available for learning
    --:(string) Beta date for course construction
    function course:getBetaDate()
        checkSelf(self,"getBetaDate")
        return self.betaDate 
    end
    --%Sets date (beta) when course is available for learning
    function course:setBetadate(pDate)
        checkSelf(self,"setBetadate")
        self.betaDate = pDate
        setPhase(self)
    end
    --%Gets release date (phase 3)
    --:(string) Release date  for course
    function course:getReleaseDate()
        checkSelf(self,"getReleaseDate")
        return self.releaseDate 
    end
    --%Sets release date (phase 3)
    function course:setReleaseDate(pDate)
        checkSelf(self,"setReleaseDate")
        self.releaseDate = pDate
        setPhase(self)
    end
    -- Returns date for each phase
    --%Gets date for each phase
    --@phase (number) A number indicating a phase (1,2, or 3)
    --:(string) Release date  for course
    function course:getPhaseDate(phase)
        checkSelf(self,"getPhaseDate")
        local tPhases = {
            [1] = self.startDate,
            [2] = self.betaDate,
            [3] = self.releaseDate
        }
        return tPhases[phase]
    end
    --% Gets milestone date for each phase (release, beta, start)
    --:(string) Milestone date  for course
    function course:getPhase()
        checkSelf(self,"getPhase")
        return self.phase
    end
    --%Gets Days to completion of milestone (e.g. 1-> 2)
    --@phase (number) A number indicating a phase (1,2, or 3)
    --:(string) Days to completion
    function course:getDaysToCompletion(phase)
        checkSelf(self,"getDaysToCompletion")
        local days, startDate, endDate
        if phase == 1 then
            startDate = self.startDate
            endDate = self.betaDate
        elseif phase ==2 then
            startDate = self.betaDate
            endDate = self.releaseDate
        elseif phase == 3 then
            startDate = self.startDate
            endDate = self.releaseDate
        end
        if libUtility.checkDate(startDate) and libUtility.checkDate(endDate)
            and (startDate ~= "0000-00-00" and endDate ~= "0000-00-00") then 
            days  =  libUtility.datediff(startDate,endDate,bNeg)
        end 
        -- if days and days > 999 then
            -- mw.log(startDate, endDate)
        -- end
        return days 
    end
    --%Gets reference for each phase
    --@phase (number) A number indicating a phase (1,2, or 3)
    --:(string) A reference
    function course:getRef(phase)
        checkSelf(self,"getRef")
        local ref 
        if phase == 1 then
            ref = self.ref_startDate --Reference
        elseif phase== 2 then
            ref = self.ref_betaDate --Reference
        else
            ref = self.ref_releaseDate  --Reference
        end
 
        return ref or ""
    end
    --%Checks if this is created by Duolingo staff
    --:(boolean) True if staff course
    function course:isStaffCourse()
        checkSelf(self,"isStaffCourse")
        if tStaffCourse[self.L1] then
            return tStaffCourse[self.L1][self.L2]
        end
    end
    --% Checks if this is a reverse course (e.g En-> Es , Es ->En)
    --:(boolean) True if Reverse course
    function course:isReverseCourse()
        checkSelf(self,"isReverseCourse")
        return self.isReverse
    end
    --% Sets a reverse course (e.g En-> Es , Es ->En)
    function course:setReverseCourse(bReverse)
        checkSelf(self,"setReverseCourse")
        self.isReverse = bReverse
    end
    --% Checks if two courses are identical
    --:(boolean) True if same course
    function course:equals(otherCourse)
        checkSelf(self,"otherCourse")
        if self.L1 == otherCourse:getL1() and self.L2 == otherCourse:getL2() then
            return true
        end
    end
 
    course.L1 = L1code or ""
    course.L2 = L2code or ""
    course.startDate = startDate or ""
    course.betaDate = betaDate or ""
    course.releaseDate = releaseDate or ""
    course.ref_startDate = p1Ref --Reference
    course.ref_betaDate = p2Ref --Reference
    course.ref_releaseDate = p3Ref  --Reference
    setPhase(course)
    return course
end
 
return courseClass

Interférence d'un bloqueur de publicité détectée !


Wikia est un site gratuit qui compte sur les revenus de la publicité. L'expérience des lecteurs utilisant des bloqueurs de publicité est différente

Wikia n'est pas accessible si vous avez fait d'autres modifications. Supprimez les règles personnalisées de votre bloqueur de publicité, et la page se chargera comme prévu.