<?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\Caracteristic;

class CaracteristicCategory extends Entity {

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

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

        $this->Name = new Property("Name", "Name", TEXTBOX, false, $this->Alias);
        $this->AppName = new Property("AppName", "AppName", TEXTBOX, false, $this->Alias);

        //Creation de l entité 
        $this->Create();
    }

    /*     * *
     * Get the Caracteristic of a category
     */

    function GetCaracteristics($add = false, $remove = true) {

        $Caracteristic = new Caracteristic($this->Core);
        $Caracteristics = $Caracteristic->Find("CategoryId=" . $this->IdEntite);

        if (count($Caracteristics) == 0) {
            $view = "<div id='competenceCategory-" . $this->IdEntite . "'>";
            
            if($add){
             $view .= "<div style='margin-top:10px'><input placeHolder = 'Enter a value' data-categorie =".$this->IdEntite." class='form-control' id='CaracteristicValue' type='text'></input></div>";
            }
            return $view;
        } else {
            $view = "<div id='competenceCategory-" . $this->IdEntite . "'>";

            foreach ($Caracteristics as $Caracteristic) {
                $icon = "";

                if ($add) {
                    $icon .= "<i class='fa fa-plus addCaracteristicEntity' id='" . $Caracteristic->IdEntite . "'  ></i>";
                }

                if ($remove) {
                    $icon .= "<i class='fa fa-trash removeCaracteristic' id='" . $Caracteristic->IdEntite . "'  ></i>";
                }

                $view .= "<div class='chips'>" . $Caracteristic->Name->Value . $icon . "</i></div>";
            }

            $view .= "</div>";
            return $view;
        }
    }
}

?>