<?php

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

namespace Plugins\CaracteristicPlugin\Entity;

use Core\Entity\Entity\Entity;
use Core\Entity\Entity\Property;
use Core\Entity\Entity\EntityProperty;
use Plugins\CaracteristicPlugin\Entity\CaracteristicEntity;
use Plugins\CaracteristicPlugin\Entity\CaracteristicCategory;


class CaracteristicEntity extends Entity {

    //Constructeur
    function __construct($core) {
        //Version
        $this->Version = "2.0.0.0";

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

        $this->EntityName = new Property("EntityName", "EntityName", TEXTBOX, false, $this->Alias);
        $this->EntityId = new Property("EntityId", "EntityId", TEXTBOX, false, $this->Alias);
        $this->CaracteristicId = new Property("CaracteristicId", "CaracteristicId", TEXTBOX, false, $this->Alias);
        $this->Description = new Property("Description", "Description", TEXTBOX, false, $this->Alias);
    
        //Creation de l entité 
        $this->Create();
    }
    
    /***
     * 
     */
    function GetTitle(){
       
        if($this->Description->Value != null){
            
            $category = new CaracteristicCategory($this->Core);
            $category->GetById($this->CaracteristicId->Value);
            return $category->Name->Value . ":" .$this->Description->Value;
        } 
        else {
          
            $CaracteristicEntity = new Caracteristic($this->Core);
            $CaracteristicEntity->Select("CaracteristicCategory.Name", "CategoryName");
            $CaracteristicEntity->Join("CaracteristicCategory", "CaracteristicCategory", "left", "Caracteristic.CategoryId = CaracteristicCategory.Id");
            $Caracteristics = $CaracteristicEntity->Find("Caracteristic.Id=" . $this->CaracteristicId->Value);
         
            return $Caracteristics[0]->CategoryName->Value  . ":".  $Caracteristics[0]->Name->Value ;
        } 
    }
    
    function GetFrontTitle(){
        
            if($this->Description->Value != null){
            
            $category = new CaracteristicCategory($this->Core);
            $category->GetById($this->CaracteristicId->Value);
            return "<b>" .$category->Name->Value . "</b> : <label> " .$this->Description->Value ."</label>";
        } 
        else {
          
            $CaracteristicEntity = new Caracteristic($this->Core);
            $CaracteristicEntity->Select("CaracteristicCategory.Name", "CategoryName");
            $CaracteristicEntity->Join("CaracteristicCategory", "CaracteristicCategory", "left", "Caracteristic.CategoryId = CaracteristicCategory.Id");
            $Caracteristics = $CaracteristicEntity->Find("Caracteristic.Id=" . $this->CaracteristicId->Value);
         
            return "<b>" .$Caracteristics[0]->CategoryName->Value  . "</b> : <label>".  $Caracteristics[0]->Name->Value ."</label>";
        }
    }
}

?>