<?php 
/*
 * PuzzleApp
 * Webemyos
 * Jérôme Oliva
 * GNU Licence
 */

namespace Apps\Mooc\Entity;

use Core\Entity\Entity\Entity;
use Core\Entity\Entity\EntityProperty;
use Core\Entity\Entity\Property;

class MoocLesson extends Entity  
{
    //Entité liée
    protected $Mooc;
    
    //Constructeur
    function __construct($core)
    {
        //Version
        $this->Version ="2.0.0.0"; 

        //Nom de la table 
        $this->Core=$core; 
        $this->TableName="MoocLesson"; 
        $this->Alias = "MoocLesson"; 

        $this->MoocId = new Property("MoocId", "MoocId", NUMERICBOX,  true, $this->Alias); 
        $this->Mooc = new EntityProperty("Apps\Mooc\Entity\MoocMooc", "MoocId"); 
        
        $this->Name = new Property("Name", "Name", TEXTBOX,  true, $this->Alias); 
        $this->Code = new Property("Code", "Code", TEXTBOX,  true, $this->Alias); 
        $this->Description = new Property("Description", "Description", TEXTAREA,  true, $this->Alias); 
        $this->Content = new Property("Content", "Content", TEXTAREA,  false, $this->Alias); 
        $this->Video = new Property("Video", "Video", TEXTBOX,  false, $this->Alias); 
        $this->Actif = new Property("Actif", "Actif", CHECKBOX,  false, $this->Alias); 

        //Creation de l entité 
        $this->Create(); 
    }
    
    function GetContent(){
        $content = $this->Content->Value;
        $content = str_replace(":lt:", "&lt;", $content);
        $content = str_replace(":gt:", "&gt;", $content);
        $content = str_replace(":br:", "<br>", $content);
        $content = str_replace(":q", "'", $content);
        $content = str_replace(":#123;", "&#123;", $content);
        $content = str_replace(":#125;", "&#125;", $content);
        $content = str_replace(":amp;", "&", $content);
        
        //Pour du code PHP
        $content = str_replace("[[", "{{", $content);
        $content = str_replace("]]", "}}", $content);
        

        return $content;
    }


    /***
     * Get elemnt in the current LAng
     */
    function GetLangElement(){
    
        if(!isset($this->LangElement)){
            
            $entityLangElement = \Apps\Lang\Helper\ElementHelper::GetEntityLangElement($this->Core,
            "MoocLesson", 
             $this->IdEntite, 
             $this->Core->GetLang("Id"));

             $this->LangElement = $entityLangElement;
        } 
    
        return $this->LangElement;
    }

    /***
     * Return name mooc in the current lang
     */
    function GetLangTitle(){

        $entityLangElement = $this->GetLangElement();
    
        if($entityLangElement){
            return $entityLangElement->Title->Value;
        }

        return $this->Name->Value;
    }

    /***
     * Return content mooc in the current lang
     */
    function GetLangDescription(){

        $entityLangElement = $this->GetLangElement();
    
        if($entityLangElement){
            return $entityLangElement->Description->Value;
        }

        return $this->Description->Value;
    }

    /***
     * Return content mooc in the current lang
     */
    function GetLangContent(){

        $entityLangElement = $this->GetLangElement();
    
        if($entityLangElement){
            return $entityLangElement->Content->Value;
        }

        return $this->GetContent();
    }
}
?>