<?php

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

namespace Apps\Forms\Entity;

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

use Apps\Forms\Entity\FormQuestion;
use Apps\Forms\Entity\FormResponse;

class FormForm extends Entity {

    // Propriété
    protected $User;

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

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

        //proprietes
        $this->Libelle = new Property("Libelle", "Libelle", TEXTBOX, true, $this->Alias);
        $this->Code = new Property("Code", "Code", TEXTBOX, true, $this->Alias);

        $this->Commentaire = new Property("Commentaire", "Commentaire", TEXTAREA, false, $this->Alias);
        $this->Actif = new Property("Actif", "Actif", CHECKBOX, false, $this->Alias);

        //Categorie
        $this->UserId = new Property("UserId", "UserId", TEXTBOX, false, $this->Alias);
        $this->User = new EntityProperty("Core\Entity\User", "UserId");

        $this->AddSharedProperty();

        $this->Create();
    }

    /***
     * The Questiojn of the Form
     */
    function GetQuestions(){
        $question = new FormQuestion($this->Core);
        $questions = $question->Find("FormId=" . $this->IdEntite);
        return $questions;  
    }

    function GetNumberUserResponse(){
        return "12";
    }
    
    function ToCompleteArray(){
        
        $data["form"] = $this->ToArray();
        
        $question = new FormQuestion($this->Core);
        $questions = $question->Find("FormId=" . $this->IdEntite);
        
        foreach($questions as $question){
            $data["questions"][$question->IdEntite] = $question->ToArray(); 
            
            $response = new FormResponse($this->Core);
            $responses = $response->Find("QuestionId=" . $question->IdEntite);
            $data["questions"][$question->IdEntite]["Responses"] = $response->ToAllArray($responses);
        }
        
        return $data;
    }
}
