_filterEnabled($select); return $select; } public function getListSelect() { if (null == $this->_select) { parent::getListSelect(); $this->_filterEnabled($this->_select); $this->_filterByRange($this->_select, $this->getRange()); $this->_joinEventType($this->_select); $this->_select->order('e.startDate'); } return $this->_select; } protected function _filterByRange(Zend_Db_Select $select, Range $range) { $select->where('e.startDate <= ?', $range->end->format('Y-m-d')); $select->where('e.endDate >= ?', $range->start->format('Y-m-d')); return $this; } protected function _getFromColumns() { return [ 'id', 'alias', 'title', 'type', 'location', 'mapUrl', 'start' => Model::getStartDateTimeExpr(), 'end' => Model::getEndDateTimeExpr(), 'className' => 'type', ]; } protected function _getFromDbColumns() { $columns = parent::_getFromDbColumns(); $columns['registeredCount'] = Model::getEventRegisteredCountExpr(); $columns['registrationAllowed'] = Model::getRegistrationAllowedExpr(); return $columns; } protected function _addDependenciesFromDb(array &$data) { if ($data['registrationAllowed']) { if ($data['registrationLimit']) { $data['registrationSpots'] = (int) $data['registrationLimit'] - (int) $data['registeredCount']; } $data['allowMembers'] = true; $data['allowNonMembers'] = $this->getNonMembersAllowed($data['type']); } return parent::_addDependenciesFromDb($data); } protected function _prepareList(&$list) { parent::_prepareList($list); if ($this->getListIncludeTimeRanges() && $list) { $timeRanges = Model::readEventTimeRanges(Qs_Array::fetchColAll($list, 'id')); foreach ($list as &$row) { if (array_key_exists($row['id'], $timeRanges)) { $row['timeRanges'] = $timeRanges[$row['id']]; } } } return $this; } protected function _joinEventType(Zend_Db_Select $select) { $select->join( $this->_getPair('EventType', 'et'), 'et.id = e.type', ['typeTitle' => 'title'] ); } /** * @param string|\DateTime $date * @return $this */ public function setDate($date) { if ($date instanceof DateTime) { $this->_date = $date; } else { $this->_date = new DateTime((string) $date); } $this->_date->setTime(0, 0, 0); return $this; } /** * @throws \Qs_Exception_EmptyPropertyException * @return \DateTime */ public function getDate() { if (null == $this->_date) { throw new Qs_Exception_EmptyPropertyException($this, '_date'); } return $this->_date; } public function setUserId($userId) { $this->_userId = (int) $userId; return $this; } public function getUserId() { return $this->_userId; } public function setRange(Range $range) { $this->_range = $range; return $this; } public function getRange() { if (null === $this->_range) { $this->setRange(Range::createMonthRange($this->getDate())); } return $this->_range; } public function setListIncludeTimeRanges($listIncludeTimeRanges = true) { $this->_listIncludeTimeRanges = $listIncludeTimeRanges; return $this; } public function getListIncludeTimeRanges() { return (bool) $this->_listIncludeTimeRanges; } public function getAttendeeObj(array $options = []) { if (null === $this->_attendeeObj || $options) { $options['eventId'] = $this->getPrimaryKey(); $this->_attendeeObj = new AttendeeObj($options); } return $this->_attendeeObj; } }