_filterEnabled($select); return $select; } public function getListSelect() { if (null == $this->_select) { parent::getListSelect(); $this->_filterEnabled($this->_select); $this->_filterShowing($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(), // переписується в View::_prepareCalendarList() 'end' => Model::getEndDateTimeExpr(), // переписується в View::_prepareCalendarList() 'className' => 'type', ]; } protected function _getFromDbColumns() { $columns = parent::_getFromDbColumns(); $columns['tradeShowAlias'] = Model::getEventTradeShowAliasExpr(false); $columns['registeredCount'] = Model::getEventRegisteredCountExpr(); $columns['registrationAllowed'] = Model::getRegistrationAllowedExpr(); return $columns; } protected function _addDependenciesFromDb(array &$data) { self::prepareEventData($data); return parent::_addDependenciesFromDb($data); } public static function prepareEventData(array &$data) { if (!array_key_exists('registrationAllowed', $data)) { throw new \Exception('Required property "registrationAllowed" is missing'); } if (!array_key_exists('registeredCount', $data)) { throw new \Exception('Required property "registeredCount" is missing'); } $typeRule = new TypeRule($data['type']); $data['registrationAllowed'] = $data['registrationAllowed'] && $typeRule->featureRegister; if ($typeRule->featureEbPricing && 'y' == Qs_Array::get($data, 'hasEbDeadline')) { if ($data['ebDeadline'] < date('Y-m-d H:i:s')) { $data['ebDeadlineReached'] = true; $data['memberPrice'] = bcadd($data['memberPrice'], $data['ebdIncreaseAmount'], 4); $data['nonmemberPrice'] = bcadd($data['nonmemberPrice'], $data['ebdIncreaseAmount'], 4); } } if ($data['registrationAllowed']) { if ($data['registrationLimit']) { $data['registrationSpots'] = (int) $data['registrationLimit'] - (int) $data['registeredCount']; } $data['allowMembers'] = $typeRule->featureRegisterMember; if ($data['type'] == Entity::TYPE_WORKSHOP) { $allowNonMembers = ($data['allowedAttendeeType'] == Entity::REGISTRATION_ALLOWED_ALL) ? $typeRule->featureRegisterNonmember : false; } else { $allowNonMembers = $typeRule->featureRegisterNonmember; } $data['allowNonMembers'] = $allowNonMembers; } } protected function _prepareList(&$list) { parent::_prepareList($list); if ($this->getListIncludeTimeRanges() && $list) { $eventsTime = Model::readEventTimeRanges(Qs_Array::fetchColAll($list, 'id')); $dateRanges = Model::readEventDateRanges(Qs_Array::fetchColAll($list, 'id')); foreach ($list as &$row) { if (array_key_exists($row['id'], $eventsTime)) { $row['eventTime'] = $eventsTime[$row['id']]; } if (array_key_exists($row['id'], $dateRanges)) { $row['dateRanges'] = $dateRanges[$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; } }