Blame view

protected/controllers/CalendarSectionController.php 3.59 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  <?php
  
  class CalendarSectionController extends NodeSectionController
  {
      public function actionCalendar($category = 'all', $country = 'all', $year = null)
      {
  
          /** @var $sportRoot SportRoot */
          $sportRoot = SportRoot::model()->with('i18n')->findByPk($this->getRootNode()->data_id);
          $this->headerGalleryId = $sportRoot->header_gallery_id;
  
          /** @var $calendarSection CalendarSection */
          $calendarSection = CalendarSection::model()->with('i18n')->findByPk($this->getNode()->data_id);
  
          $this->sectionGalleryId = $calendarSection->header_gallery_id;
  
          $this->pageName = $calendarSection->i18n->page_name;
          $this->setSEOParams($calendarSection->i18n->title, $calendarSection->i18n->keywords, $calendarSection->i18n->description);
  
          /** @var $categories SportEventCategory[] */
          $categories = SportEventCategory::model()->with('i18n')->findAll(
              array('order' => 'rank asc',
                  'condition' => 'calendar_section_id = ' . $this->getNode()->data_id));
          if (count($categories) == 1 && $category == 'all') $category = $categories[0]->id;
          $categoryIds = array();
          foreach ($categories as $item) $categoryIds[] = $item->id;
  
          $year = isset($year) ? $year : $calendarSection->year;
          //$years = array(2011, 2012, 2013);
  
          $cmd = Yii::app()->db->createCommand()
              ->selectDistinct('YEAR(start_date)')
              ->from(SportEvent::model()->tableName());
          if ($category != 'all') {
              $cmd->where('sport_event_category_id = :category', array(':category' => $category));
          } else {
              $cmd->where(array('in', 'sport_event_category_id', $categoryIds));
          }
          $years1 = $cmd->queryColumn();
          $cmd = Yii::app()->db->createCommand()
              ->selectDistinct('YEAR(end_date)')
              ->from(SportEvent::model()->tableName());
          if ($category != 'all') {
              $cmd->where('sport_event_category_id = :category', array(':category' => $category));
          } else {
              $cmd->where(array('in', 'sport_event_category_id', $categoryIds));
          }
          $years2 = $cmd->queryColumn();
  
          $t = array((string)(date('Y') - 1), date('Y'), (string)(date('Y') + 1));
          $years = array_intersect($t, array_unique(array_merge($years1, $years2)));
  
  
          $criteria = new CDbCriteria(array(
              'index' => 'id',
              'condition' => 'sportEventCategory.calendar_section_id = ' . $calendarSection->id,
          ));
          $criteria->with = array('sportEventCategory');
          $criteria->addCondition('start_date <= :year_end');
          $criteria->addCondition('end_date >= :year_begin');
          $criteria->params[':year_begin'] = date($year . '-01-01');
          $criteria->params[':year_end'] = date('Y-m-d', mktime(0, 0, 1, 1, 0, (int)($year) + 1));
          if ($category != 'all') {
              $criteria->addCondition('sport_event_category_id = :category');
              $criteria->params[':category'] = $category;
          }
          if ($country != 'all') {
              $criteria->addCondition('country_id = :country');
              $criteria->params[':country'] = $country;
          }
          $events = SportEvent::model()->with('i18n')->findAll($criteria);
  
          $this->render('calendar', array(
              'links_block' => $calendarSection->i18n->links_block,
              'content' => $calendarSection->i18n->content,
              'events' => $events,
              'categories' => $categories,
              'category' => $category,
              'country' => $country,
              'year' => $year,
              'years' => $years,
          ));
      }
  
  }