Beispiel #1
0
 /**
  * Действие дял редактирования сезона (соревнования)
  * 
  * @param int $id
  */
 public function action_edit($id = null)
 {
     is_null($id) and \Response::redirect_back('admin/competitions/seasons');
     if (!($season = \Model_Season::find($id, array('related' => array('teams'))))) {
         \Session::set_flash('error', 'Could not find Season #' . $id);
         \Response::redirect_back('admin/competitions/seasons');
     }
     $val = \Model_Season::validate('edit');
     if ($val->run()) {
         $season->value = \Input::post('value');
         unset($season->teams);
         if (\Input::post('teams')) {
             foreach (\Input::post('teams') as $item) {
                 $season->teams[] = \Model_Team::find($item);
             }
         }
         if ($season->has_table == 1 and \Input::post('has_table') == 0) {
             $table = \Model_Table::find('first', array('where' => array(array('season_id', '=', $season->id))));
             if ($table) {
                 $table->delete();
             }
             $season->has_table = 0;
         }
         // Если нужно также создать таблицу
         if ($season->has_table == 0 and \Input::post('has_table') == 1) {
             $season->has_table = 1;
             // Массив таблицы результатов
             $arr = array();
             $i = 1;
             foreach ($season->teams as $item) {
                 $arr[] = array('id' => $item->id, 'place' => $i, 'name' => $item->value, 'games' => 0, 'wins' => 0, 'draws' => 0, 'loss' => 0, 'goals_in' => 0, 'goals_out' => 0, 'goals_out' => 0, 'points' => 0);
                 $i++;
             }
             $season->table = \Model_Table::forge(array('results_json' => json_encode($arr), 'show_on_main' => 0));
         }
         if ($season->save()) {
             \Session::set_flash('success', 'Сезон (соревнование) обновлен(о).');
             \Response::redirect_back('admin/competitions/seasons');
         } else {
             \Session::set_flash('error', 'Could not update Season #' . $id);
         }
     } else {
         if (\Input::method() == 'POST') {
             $season->value = $val->validated('value');
             $season->has_table = $val->validated('has_table');
             \Session::set_flash('error', $val->error());
         }
         $this->template->set_global('season', $season, false);
         // Все команды
         $this->template->set_global('teams', \Model_Team::get_teams_for_select(), false);
         // Массив id команд сезона
         $season_teams = array();
         foreach ($season->teams as $item) {
             $season_teams[] = $item->id;
         }
         $this->template->set_global('season_teams', $season_teams, false);
     }
     $this->template->content = \View::forge('competitions/seasons/edit');
 }
Beispiel #2
0
 public function get_search_items()
 {
     /************ Start generating query ***********/
     $items = Model_Team::find(function ($query) {
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where('name', 'like', "%{$value}%");
                         break;
                     case 'featured':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '>=', $date);
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '<=', $date);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }
Beispiel #3
0
 /**
  * Действие для отображения
  */
 public function action_index($season_id)
 {
     // Извлекаем из БД таблицу для главной
     $data['table'] = \Model_Table::find('first', array('related' => 'season', 'where' => array(array('season_id', '=', $season_id))));
     if ($data['table']) {
         $data['table']->results = json_decode($data['table']->results_json);
         // Сортируем по очкам
         usort($data['table']->results, array('Main\\Controller_Table', 'cmp'));
         // Извлекаем команды сезона для получения их картинок
         $season_teams = \Model_Team::find('all', array('related' => 'seasons', 'where' => array(array('seasons.id', '=', $season_id))));
         foreach ($data['table']->results as $key => $result_item) {
             foreach ($season_teams as $team) {
                 if ($result_item->id == $team->id) {
                     $data['table']->results[$key]->logo_uri = $team->logo_uri;
                     break;
                 }
             }
         }
     }
     $this->template->content = \View::forge('table/index', $data, FALSE);
 }
Beispiel #4
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Team::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get content accordions
                 $item->get_accordions = static::lazy_load(function () use($item) {
                     return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'accordions');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
Beispiel #5
0
 /**
  * Удаление команды
  * 
  * @param int $id
  */
 public function action_delete($id = null)
 {
     is_null($id) and \Response::redirect_back('admin/competitions/teams');
     if ($team = \Model_Team::find($id)) {
         if ($team->logo_uri) {
             unlink(DOCROOT . 'assets/img/teams/' . $team->logo_uri);
         }
         $team->delete();
         \Session::set_flash('success', 'Команда удалена.');
     } else {
         \Session::set_flash('error', 'Could not delete Team #' . $id);
     }
     \Response::redirect_back('admin/competitions/teams');
 }