<?php

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

namespace Apps\Courses\Module\Front;

use Core\Control\Button\Button;
use Core\Controller\Controller;
use Core\View\View;
use Core\View\ElementView;

use Apps\Courses\Entity\CourseCour;

/*
 * 
 */
 class FrontController extends Controller
 {
    /**
     * Constructeur
     */
    function _construct($core="")
    {
          $this->Core = $core;
    }

    /**
     * Create
     */
    function Create()
    {
    }

    /**
     * Init
     */
    function Init()
    {
    }

    /**
     * Render
     */
    function Show($all=true)
    {
         return $this->Index();
    }
    
    /*
    * Get the home page
    */
   function Index()
   {
       $view = new View(__DIR__."/View/index.tpl", $this->Core);

       $this->Core->MasterView->Set("Title", $this->Core->GetCode("Cours"));
    
       $cour = new CourseCour($this->Core);
    
       $cours = $cour->Find("1=1 Order by Id Desc");
       $view->AddElement(new ElementView("Cours", $cours));
    
       return $view->Render();
   }

    /***
    * Detail of a cour
    */
    function Cour($courCode){
        $cour = new CourseCour($this->Core);
        $cour = $cour->GetByCode($courCode);
  
        if($cour){
          $view = new View(__DIR__."/View/cour.tpl", $this->Core);
     
          $this->Core->MasterView->Set("Title", $this->Core->GetCode("cours") . " | " .$cour->Name->Value);
          $this->Core->MasterView->Set("Description", $cour->ShortDescription->Value);
  
          $view->AddElement(new ElementView("Cour", $cour));

          $commentPlugin = \Apps\EeApp\Helper\AppHelper::GetPluginType($this->Core, "Courses", "Comment");

          $view->AddElement(new ElementView("hasCommentPlugin", $commentPlugin != null));
          $view->AddElement(new ElementView("commentPluginScript",  $commentPlugin ? $commentPlugin->GetRegisterPlugin() : ""));
          $view->AddElement(new ElementView("commentPlugin",  $commentPlugin ? $commentPlugin->Render("CoursesCour", $cour->IdEntite) : ""));

          $bookingPlugin = \Apps\EeApp\Helper\AppHelper::GetPluginType($this->Core, "Courses", "Booking");

          $view->AddElement(new ElementView("hasBookingPlugin", $bookingPlugin != null));
          $view->AddElement(new ElementView("bookingPluginScript",  $bookingPlugin ? $bookingPlugin->GetRegisterPlugin() : ""));
          $view->AddElement(new ElementView("bookingPlugin",  $bookingPlugin ? $bookingPlugin->Render("CoursesCour", $cour->IdEntite) : ""));


  
        } else {
          $this->Core->MasterView->Set("Title", $this->Core->GetCode("Cours"));
      
          $view = new View(__DIR__."/View/nocour.tpl", $this->Core);
        }
  
        return $view->Render();
     }
    
          
          /*action*/
 }?>