Example #1
0
 public function handleLikedSubjects()
 {
     $this->tab = 'likedSubjects';
     $res = $this->context->database->table('subject_rating')->select('subject_id, SUM(thumb_up) AS thumb_up, SUM(thumb_down) AS thumb_down')->order('thumb_up DESC, thumb_down')->group('subject_id');
     foreach ($res as $key => $row) {
         $ids[] = $row['subject_id'];
     }
     if (isset($ids)) {
         $this->subjects->where('id', $ids);
         $this->subjects->order('FIND_IN_SET(subject.id,"' . implode(",", $ids) . '")');
     } else {
         $this->subjects->where('id', '-2');
     }
     $this->refresh();
 }
Example #2
0
 public function renderDefault()
 {
     $this->template->subjects = $this->places->order('name')->where('subject.id != 1')->group('subject.id')->having('COUNT(:event.id) > 0');
     $this->template->approvedPlacesCount = $this->approvedPlacesCount;
     $this->template->subject_id = $this->subject_id;
     if ($this->subject_id != 'all') {
         $this->events->where('subject_id', $this->subject_id)->group('event.id')->having('COUNT(:event_time.id) = 0');
     }
     // vyhledavani
     if ($this->q) {
         $this->events->where("event.name LIKE ? OR subject.name LIKE ? OR user.email LIKE ?", "%" . $this->q . "%", "%" . $this->q . "%", "%" . $this->q . "%");
         $this->places->where("subject.name LIKE ?", "%" . $this->q . "%");
         $this['search']['q']->setDefaultValue($this->q);
         $this->template->search = TRUE;
     } else {
         $this->template->search = FALSE;
     }
     if ($this->order == '' && $this->user->isInRole('administrator')) {
         $this->order = 'updated DESC';
     }
     switch ($this->what) {
         case self::ANONYMOUS:
             $this->events->where('subject_id', '1');
             $this->template->what = self::ANONYMOUS;
             break;
         case self::NOTERM:
             $this->events->group('event.id')->having('COUNT(:event_time.id) = 0');
             $this->template->what = self::NOTERM;
             break;
         case self::UPDATED:
             $this->events->group('event.id')->having('DATEDIFF(NOW(), event.changed) < ' . self::TIME_UPDATED);
             $this->template->what = self::UPDATED;
             break;
         case self::RECENT:
             $this->events->group('event.id')->having('DATEDIFF(NOW(), event.created) < ' . self::TIME_RECENT);
             $this->template->what = self::UPDATED;
             break;
         case self::TOREVIEW:
             $this->events->group('event.id')->having('event.reviewed = 0');
             $this->template->what = self::TOREVIEW;
             break;
         case self::NOTAPPROVED:
             $this->events->group('event.id')->having('event.approved = 0');
             $this->template->what = self::NOTAPPROVED;
             break;
         case self::PREFERED:
             $this->events->group('event.id')->having('event.prefered = 1');
             $this->template->what = self::PREFERED;
             break;
         default:
             $this->template->what = self::ALL;
     }
     if ($this->orderBy == '' && $this->user->isInRole('administrator')) {
         $this->orderBy = self::MODIFICATION;
     }
     switch ($this->orderBy) {
         case self::MODIFICATION:
             $this->events->order('changed DESC, created DESC');
             $this->template->orderBy = self::MODIFICATION;
             break;
         case self::ALPHABET:
         default:
             $this->events->order('name');
             $this->template->orderBy = self::ALPHABET;
             break;
     }
     $this->pagerEvents->itemCount = $this->events->count();
     $this->template->events = $this->events->limit($this->pagerEvents->getLimit(), $this->pagerEvents->getOffset());
     if ($this->user->isInRole('administrator')) {
         $this->template->nonaproved = $this->context->createServiceEvents()->where('approved', '0');
     }
 }