<?php

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

namespace Apps\Courses;

use Core\Core\Core;
use Apps\Base\Base;
use Core\Core\Request;
use Core\Core\Response;

use Apps\Courses\Module\Admin\AdminController;
use Apps\Courses\Module\Front\FrontController;


class Courses extends Base {

    /**
     * Author and version
     * */
    public $Author = 'Webemyos';
    public $Version = '1.0.0';

    /**
     * Constructeur
     * */
    function __construct() {
        $this->Core = Core::getInstance();
        parent::__construct($this->Core, "Courses");
    }

    /**
     * Set public route
     */
    function GetRoute($routes = "") {
        $this->Route->SetPublic(array( "cours/" =>  "Cour"));

        return $this->Route;
    }

    /*     * *
     * Execute action after install
     */

    function PostInstall() {
        \Apps\EeApp\Helper\AppHelper::UpdateAppParams($this->Core,
                "Courses",
                $this->Version,
                "", // Add Description of the app
                0, // Set 1 if the App have a AdminWidgetDashBoard
                0  // Set 1 if the App have a Member Module
        );
    }

    /**
     * Start Admin
     */
    function Run() {
        echo parent::RunApp($this->Core, "Courses", "Courses");
    }

    /***
     * Save a cour
     */
    function SaveCour(){

      $adminController = new AdminController($this->Core);
      $result = $adminController->SaveCour(Request::GetPosts());

      if ($result === true) {
          return Response::Success($adminController->GetTabCours());
      } else {
          return Response::Error();
      }
    }

     /***
     * Delete a cour
     */
    function DeleteCour() {

      $adminController = new AdminController($this->Core);
      $result = $adminController->DeleteCour(Request::GetPost("CourId"));

      if ($result === true) {
          return Response::Success($adminController->GetTabCours());
      } else {
          return Response::Error();
      }
    }

    /*     * *
     * Detail of a cours
     */

    function Cour($eventCode) {
        if($eventCode == ""){
            $frontController = new FrontController($this->Core);
            return $frontController->Index();
        } else {

            $frontController = new FrontController($this->Core);
            return $frontController->Cour($eventCode);
        }
    }

    /*     * *
     * Run member Controller
     * 
     * /
      /*function RunMember(){
      $memberController = new MemberController($this->Core);
      return $memberController->Index();
      } */

    /**
     * Get The siteMap 
     */
    /* public function GetSiteMap(){
      return SitemapHelper::GetSiteMap($this->Core);
      } */

    /*     * *
     * Get the widget
     */
    /* public function GetWidget($type = "", $params = "") {

      switch ($type) {
      case "AdminDashboard" :
      $widget = new \Apps\Courses\Widget\AdminDashBoard\AdminDashBoard($this->Core);
      break;
      }

      return $widget->Render();
      } */

    /*     * *
     * Get Forum Addable widget
     */
    /* public function GetListWidget(){
      return array(array("Name" => "LastMessage",
      "Description" => $this->Core->GetCode("Courses.DescriptionLastMessageWidget")),
      );
      } */
}
