コード例 #1
0
ファイル: table.php プロジェクト: alexmon1989/fcssadon.ru
 /**
  * Действие для отображения
  */
 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);
 }
コード例 #2
0
ファイル: team.php プロジェクト: EdgeCommerce/edgecommerce
 /**
  * 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;
 }
コード例 #3
0
ファイル: seasons.php プロジェクト: alexmon1989/fcssadon.ru
 /**
  * Действие дял редактирования сезона (соревнования)
  * 
  * @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');
 }
コード例 #4
0
ファイル: team.php プロジェクト: EdgeCommerce/edgecommerce
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Team::find_one_by_id($id)) {
             // Delete other content data like images, files, etc.
             if (!empty($item->images)) {
                 foreach ($item->images as $image) {
                     $this->delete_image($image->image);
                     $image->delete();
                 }
             }
             // if(!empty($item->files))
             // {
             // 	foreach($item->files as $file)
             // 	{
             // 		$this->delete_file($file->file);
             // 		$file->delete();
             // 	}
             // }
             // if(!empty($item->videos))
             // {
             // 	foreach($item->videos as $video)
             // 	{
             // 		$this->delete_image($video->thumbnail, 'video');
             // 		$video->delete();
             // 	}
             // }
             // if(!empty($item->accordions))
             // {
             // 	foreach($item->accordions as $accordion)
             // 	{
             // 		\Request::forge('admin/team/accordion/delete/'.$accordion->id)->execute();
             // 	}
             // }
             try {
                 $item->seo->delete();
                 $item->delete();
                 \Messages::success('Member successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete team</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
コード例 #5
0
ファイル: Contest.php プロジェクト: creat2012/hustoj_official
 public function standing()
 {
     $solutions = $this->solutions();
     /* @var $data Model_Team[] */
     $data = array();
     $start_time = strtotime($this->start_time);
     foreach ($solutions as $item) {
         if (array_key_exists($item->user_id, $data)) {
             $team = $data[$item->user_id];
             $team->add($item->num, strtotime($item->in_date) - $start_time, $item->result);
         } else {
             $team = new Model_Team();
             $team->user_id = $item->user_id;
             $team->add($item->num, strtotime($item->in_date) - $start_time, $item->result);
             $data[$item->user_id] = $team;
         }
     }
     usort($data, function ($a, $b) {
         if ($a->solved > $b->solved) {
             return false;
         }
         if ($a->solved == $b->solved) {
             if ($a->time < $b->time) {
                 return false;
             }
         }
         return true;
     });
     return $data;
 }
コード例 #6
0
ファイル: teams.php プロジェクト: alexmon1989/fcssadon.ru
 /**
  * Удаление команды
  * 
  * @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');
 }