コード例 #1
0
 /**
  * Initialize the ModifyController class and their parents
  */
 public function init()
 {
     try {
         parent::init();
     } catch (Exception $e) {
         throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage());
     }
     if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) {
         $url = Tools::getInstance()->request_url;
         $controller = Tools::getInstance()->getUrl_controller($url);
         if ($controller == 'ModifyController') {
             if (file_exists(_SEASONS_MODELS_ . '/' . $this->model_name . 'Model.php')) {
                 if (file_exists(_SEASONS_VIEWS_ . '/' . $this->view_name . '.tpl')) {
                     try {
                         require_once _SEASONS_MODELS_ . '/' . $this->model_name . 'Model.php';
                         $id = Tools::getInstance()->getUrl_id($url);
                         $data = \Season\DisplayModel::getInstance()->display_season($id);
                         echo $this->twig->render($this->view_name . '.tpl', array('season' => $data[0], 'bootstrapPath' => _BOOTSTRAP_FILE_));
                     } catch (Exception $e) {
                         throw new Exception('Une erreur est survenue durant la récupération des données: ' . $e->getMessage());
                     }
                 } else {
                     throw new Exception('Le template "' . $this->view_name . '" n\'existe pas dans "' . _SEASONS_VIEWS_ . '"!');
                 }
             } else {
                 throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _SEASONS_MODELS_ . '"!');
             }
         } else {
             throw new Exception('Une erreur est survenue durant la phase de routage!');
         }
     } else {
         throw new Exception('L\'URL n\'est pas évaluable!');
     }
 }
コード例 #2
0
 /**
  * Initialize the DisplayController class and their parents
  */
 public function init()
 {
     try {
         parent::init();
     } catch (Exception $e) {
         throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage());
     }
     if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) {
         $url = Tools::getInstance()->request_url;
         $controller = Tools::getInstance()->getUrl_controller($url);
         if ($controller == 'DisplayController') {
             if (file_exists(_RENTALS_MODELS_ . '/' . $this->model_name . 'Model.php') && file_exists(_RENTALS_MODELS_ . '/' . $this->model_name . 'Model.php') && file_exists(_LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php') && file_exists(_SEASONS_MODELS_ . '/' . $this->model_name . 'Model.php') && file_exists(_CARAVANS_MODELS_ . '/' . $this->model_name . 'Model.php')) {
                 if (file_exists(_RENTALS_VIEWS_ . '/' . $this->view_nameAll . '.tpl') && file_exists(_RENTALS_VIEWS_ . '/' . $this->view_nameId . '.tpl')) {
                     try {
                         require_once _RENTALS_MODELS_ . '/' . $this->model_name . 'Model.php';
                         require_once _LOCATIONS_MODELS_ . '/' . $this->model_name . 'Model.php';
                         require_once _SEASONS_MODELS_ . '/' . $this->model_name . 'Model.php';
                         require_once _CARAVANS_MODELS_ . '/' . $this->model_name . 'Model.php';
                         $id = Tools::getInstance()->getUrl_id($url);
                         switch ($id) {
                             case 'all':
                                 $data = \Rental\DisplayModel::getInstance()->display_rentals();
                                 echo $this->twig->render($this->view_nameAll . '.tpl', array('rentals' => $data, 'bootstrapPath' => _BOOTSTRAP_FILE_));
                                 break;
                             default:
                                 if (\Rental\DisplayModel::getInstance()->has_rental($id) == 1) {
                                     $rentals = \Rental\DisplayModel::getInstance()->display_rental($id);
                                     $seasons = array();
                                     $caravans = array();
                                     $locations = array();
                                     $buffer = null;
                                     for ($i = 0; $i < count($rentals); $i++) {
                                         $buffer = \Season\DisplayModel::getInstance()->get_SeasonByRental($rentals[$i]['rent_id']);
                                         if (count($buffer) > 0) {
                                             $seasons = array_merge($seasons, $buffer);
                                         }
                                         $buffer = null;
                                         $buffer = \Caravan\DisplayModel::getInstance()->get_caravanByRental($rentals[$i]['rent_id']);
                                         if (count($buffer) > 0) {
                                             $caravans = array_merge($caravans, $buffer);
                                         }
                                         $buffer = null;
                                         $buffer = \Location\DisplayModel::getInstance()->get_LocationByRental($rentals[$i]['rent_id']);
                                         if (count($buffer) > 0) {
                                             $locations = array_merge($locations, $buffer);
                                         }
                                         $buffer = null;
                                     }
                                     echo $this->twig->render($this->view_nameId . '.tpl', array('rental' => $rentals, 'seasons' => $seasons, 'caravans' => $caravans, 'locations' => $locations, 'bootstrapPath' => _BOOTSTRAP_FILE_));
                                 } else {
                                     header('Location: /Cas-M-Ping/errors/404');
                                 }
                                 break;
                         }
                     } catch (Exception $e) {
                         throw new Exception('Une erreur est survenue durant la récupération des données: ' . $e->getMessage());
                     }
                 } else {
                     throw new Exception('Le template "' . $this->view_nameAll . '" ou "' . $this->view_nameId . '" n\'existe pas dans "' . _RENTALS_VIEWS_ . '"!');
                 }
             } else {
                 throw new Exception('Le modèle "' . $this->model_name . '" n\'existe pas dans "' . _RENTALS_MODELS_ . '"!');
             }
         } else {
             throw new Exception('Une erreur est survenue durant la phase de routage!');
         }
     } else {
         throw new Exception('L\'URL n\'est pas évaluable!');
     }
 }