Пример #1
0
 /**
  * Сохраняет скриншоты и связи между играми и жанрами после сохранения
  * игры
  */
 public function afterSave()
 {
     //если запись уже существует, то перед обновлением удаляем все связанные данные
     if (!$this->isNewRecord) {
         $this->dbConnection->createCommand('DELETE FROM ygs_games_types WHERE gt_game_id=' . $this->g_id)->execute();
         //скриншоты удаляем только если updateScreenshots == true
         if ($this->updateScreenshots) {
             $this->dbConnection->createCommand('DELETE FROM ygs_screenshots WHERE s_game_id=' . $this->g_id)->execute();
         }
     }
     //сохраняем жанры
     foreach ($this->g_types as $type) {
         if (($t = Types::model()->findByPk($type)) !== null) {
             $this->dbConnection->createCommand('INSERT INTO ygs_games_types (gt_game_id, gt_type_id) VALUES (' . $this->g_id . ',' . $type . ')')->execute();
         }
     }
     //сохраняем скриншоты
     if ($this->updateScreenshots) {
         $command = $this->dbConnection->createCommand('INSERT INTO ygs_screenshots (s_game_id, s_image, s_thumbnail) VALUES (:s_game_id, :s_image, :s_thumbnail)');
         foreach ($this->g_screenshots as $screenshot) {
             $command->bindParam(':s_game_id', $this->g_id, PDO::PARAM_INT);
             $command->bindParam(':s_image', $screenshot->IMAGE, PDO::PARAM_STR);
             $command->bindParam(':s_thumbnail', $screenshot->THUMBNAIL, PDO::PARAM_STR);
             $command->execute();
         }
     }
 }
Пример #2
0
 /**
  * Метод предназначен для преобразования значения в поле g_rate
  * таблицы ygs_games в массив соответствующих жанров
  * @return array массив с жанрами 
  */
 public function _decodeTypes($value)
 {
     if (count($this->_allTypes) == 0) {
         //получаем список жанров
         $this->_allTypes = Types::model()->findAll();
     }
     $types = array();
     //перебираем все жанры и проверяем указаны ли они в поле жанра игры
     //для этого используется логическая операция "И"
     foreach ($this->_allTypes as $type) {
         if ((int) $value & (int) $type->t_id) {
             $types[] = $type;
         }
     }
     //возвращаем массив с жанрами
     return $types;
 }
Пример #3
0
 /**
  * Возвращает жанр по его id, если он не найден - 404-ую ошибку
  * id может быть указан в первом параметре или в массиве $_GET
  * 
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable
  */
 public function loadTypes($id = null)
 {
     if ($this->_model === null) {
         if ($id !== null || isset($_GET['id'])) {
             $this->_model = Types::model()->findbyPk($id !== null ? $id : $_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
Пример #4
0
 public function run()
 {
     $types = Types::model()->findAll();
     $this->render('typesMenu', array('types' => $types));
 }