EventEntity::CART_ITEM_TYPE, 'productCategoryId' => $this->getPrimaryKey(), ]; $cartItem = $this->getCart()->find($needle); return false !== $cartItem; } protected function getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } protected function _getFromDbSelect($primaryKey) { $select = parent::_getFromDbSelect($primaryKey); $this->_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; } public function getListStatement4XmlSitemap($columns = ['alias', 'changed']) { $select = parent::getListSelect(); $this->_filterEnabled($select); $this->_joinEventType($select); $select->order('e.startDate'); $select->reset(Zend_Db_Select::COLUMNS)->columns($columns);; return $select->query(); } 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']); } parent::_addDependenciesFromDb($data); $data['areEarlyBirdPricesActual'] = $this->areEarlyBirdPricesActual($data['earlyBirdPrices']); return $this; } private function areEarlyBirdPricesActual($prices) { $date = date('Y-m-d'); foreach ($prices as $price) { if ($price['date'] >= $date) { return true; } } return false; } 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; } /** * @return \DateTime * @throws \Qs_Exception_EmptyPropertyException */ 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; } /** * @param array $options * @return AttendeeObj */ public function getAttendeeObj(array $options = []) { if (null === $this->_attendeeObj || $options) { $options['eventId'] = $this->getPrimaryKey(); $this->_attendeeObj = new AttendeeObj($options); } return $this->_attendeeObj; } public function getPastAnnualMeetingYear() { $select = $this->_db->select(); $select->from($this->_getPair('Event', 'e'), 'YEAR(`e`.`startDate`)'); $select->where('`e`.`showAs` = ?', Entity::ANNUAL_MEETING); $select->where('`e`.`endDate` < CURDATE()'); $select->order('e.endDate DESC'); return $this->_db->fetchOne($select); } }