_attendeeObj) { $options['eventId'] = $this->getPrimaryKey(); $this->_attendeeObj = new AttendeeObj($options); } return $this->_attendeeObj; } /** * @param array $data [ * 'registrationStartDate' => string, // Y-m-d * 'registrationEndDate' => string, // Y-m-d * 'registrationStartTime' => string, // H:i:s * 'registrationEndTime' => string, // H:i:s * @return $this */ public function initFromForm(array $data) { if (empty($data['endDate'])) { $data['endDate'] = $data['startDate']; } if ((self::TYPE_REGULAR === $data['type'] || self::TYPE_GROUP === $data['type'])) { if (!empty($data['registrationStartDate'])) { $regStart = new DateTime($data['registrationStartDate'] . ' ' . $data['registrationStartTime']); $data['registrationStart'] = $regStart->format('Y-m-d H:i:s'); } else { $data['registrationStart'] = null; } if (!empty($data['registrationEndDate'])) { $regEnd = new DateTime($data['registrationEndDate'] . ' ' . $data['registrationEndTime']); $data['registrationEnd'] = $regEnd->format('Y-m-d H:i:s'); } else { $data['registrationEnd'] = null; } } else { $data['showWaiver'] = 'n'; } return parent::initFromForm($data); } protected function _addDependenciesFromDb(array &$data) { parent::_addDependenciesFromDb($data); $data['timeRanges'] = $this->_readTimeRanges(); if (self::TYPE_REGULAR === $data['type'] || self::TYPE_GROUP === $data['type']) { if (isset($data['registrationStart'])) { $regStart = new DateTime($data['registrationStart']); $data['registrationStartDate'] = $regStart->format('Y-m-d'); $data['registrationStartTime'] = $regStart->format('H:i:s'); } if (isset($data['registrationEnd'])) { $regEnd = new DateTime($data['registrationEnd']); $data['registrationEndDate'] = $regEnd->format('Y-m-d'); $data['registrationEndTime'] = $regEnd->format('H:i:s'); } } return $this; } protected function _updateDependency() { parent::_updateDependency(); return $this->_saveDependency(); } protected function _insertDependency() { parent::_insertDependency(); return $this->_saveDependency(); } protected function _saveDependency() { $this->_saveTimeRanges($this->_data['startDate'], $this->_data['endDate'], (array)$this->_data['timeRanges']); return $this; } protected function _getFromDbColumns() { $columns = parent::_getFromDbColumns(); $columns['registeredCount'] = $this->getAttendeeObj()->getEventRegisteredCountExpr('e'); return $columns; } protected function _getFromColumns() { $columns = parent::_getFromColumns(); $columns['registeredCount'] = $this->getAttendeeObj()->getEventRegisteredCountExpr('e'); $columns['committeeTitle'] = $this->_getCommitteeTitleExpr(); return $columns; } protected function _getCommitteeTitleExpr() { $select = $this->_db->select() ->from($this->_getPair('Committee', 'c'), array('title')) ->where('c.id = e.committeeId') ->limit(1); return new Zend_Db_Expr('(' . $select . ')'); } protected function _filter(\Zend_Db_Select $select) { $this->_filterByDate($select); return parent::_filter($select); } protected function _filterByDate(\Zend_Db_Select $select) { if ($this->hasFilter() && !empty($this->_filter['date'])) { $date = \DateTime::createFromFormat('Y-m', $this->_filter['date']); $select->where( 'EXTRACT(YEAR_MONTH FROM e.startDate) <= ? AND EXTRACT(YEAR_MONTH FROM e.endDate) >= ?', $date->format('Ym') ); unset($this->_filter['date']); } return $this; } protected function _prepareRow(array &$row) { $this->_prepareRegistrationAllowed($row); return parent::_prepareRow($row); } /** * [ * 'attendType' => 'other', * 'team' => null | [ * 'type' => 'newTeam' | 'existingTeam' | 'individual', * 'teamName' => null | string, * 'teamId' => null | int, * ], * 'attendee' => [ * [ * 'mode' => 'choose', * 'type' => 'member' | 'nonmember', * 'id' => null|int '', * 'firstName' => null|string '', * 'lastName' => null|string '', * 'email' => null|string '', * ] * ] * ] * @param array $data * @throws \Qs_Exception_EmptyPropertyException * @return $this */ public function initFromSignupForm(array $data) { $this->_data = $this->_prepareSignupFormData($data); $dt = new DateTime($data['dateSubmitted'] . ' ' . $data['timeSubmitted']); $this->_data['paid'] = isset($data['paid']) ? $data['paid'] : OrderObj::STATUS_PAID_NO; $this->_data['dateSubmitted'] = $dt->format('Y-m-d H:i:s'); $this->_data['paymentMethod'] = (isset($data['paymentMethod']) && isset(OrderObj::$paymentMethodsTitles[$data['paymentMethod']])) ? $data['paymentMethod'] : OrderObj::PAYMENT_TYPE_PAY_LATER; return $this; } /** * @param array $data * [ * 'paymentMethod' => string, // 'payLater', 'cache', 'check' * 'paid' => string, // 'y', 'n' * 'dateSubmitted' => string, // Y-m-d H:i:s * 'total' => float, * 'attendees' => [ * [ * 'teamId' => int, * 'userId' => int, * 'firstName' => string, * 'lastName' => string, * 'email' => string, * 'amount' => string, * ] * ], * ] * @return int|null * @throws \Exception * @throws \Qs_Exception_EmptyPropertyException */ public function insertAttendee(array $data = null) { $data = (null === $data) ? $this->_data : $data; if (!isset($data['total']) || empty($data['attendees'])) { throw new Exception('Not enough data'); } $this->_clearErrors(); $this->_db->beginTransaction(); try { $event = $this->getEventData(); $total = (float)$data['total']; $attendees = (array)$data['attendees']; $paymentFee = $this->calcFee($total); $summary = Math::Add($total, $paymentFee, 4); $summary = Math::round($summary, 2); $transaction = array( 'paymentType' => $data['paymentMethod'], 'paymentTypeTitle' => OrderObj::$paymentMethodsTitles[$data['paymentMethod']], 'paid' => $data['paid'], 'status' => OrderObj::STATUS_ORDER_NEW, 'subtotal' => $summary, 'tax' => 0, 'total' => $summary, 'enabled' => 'y', 'purchaseDate' => ('y' === $data['paid']) ? $data['dateSubmitted'] : null, 'added' => $data['dateSubmitted'], ); $mainAttendee = reset($attendees); $transaction['billingFirstName'] = $mainAttendee['firstName']; $transaction['billingLastName'] = $mainAttendee['lastName']; $transaction['billingEmail'] = $mainAttendee['email']; $transactionId = $this->_getTable('Transaction')->insert($transaction); $cartId = $this->_getTable('Cart')->insert(array( 'userId' => (empty($mainAttendee['userId'])) ? null : $mainAttendee['userId'], 'transactionId' => $transactionId, 'role' => 'admin', 'roleId' => \App_Admin_Auth::getInstance()->getData('id'), )); $attendeeTable = $this->_getTable('EventAttendee'); // insert main attendee (current user or first attendee in form) unset($attendees[key($attendees)]); $mainAttendee['eventId'] = $this->_primaryKey; $mainAttendee['cartId'] = $cartId; $mainAttendee['approved'] = 'y'; $parentAttendeeId = $attendeeTable->insert($mainAttendee); // insert shopping cart item $this->_getTable('CartItem')->insert(array( 'cartId' => $cartId, 'cartItemType' => \App_ECommerce_Cart_View::ITEM_TYPE_EVENT, 'productId' => $parentAttendeeId, 'title' => $event['title'], 'description' => $event['description'], 'quantity' => 1, 'price' => $total, 'paymentFee' => $paymentFee, )); foreach ($attendees as &$attendee) { $attendee['eventId'] = $this->_primaryKey; $attendee['parentAttendeeId'] = $parentAttendeeId; $attendee['cartId'] = $cartId; $attendee['approved'] = 'y'; } // insert attendees, update field parentAttendeeId $attendeeTable->insertList($attendees); $this->_updateParentAttendeeIds(); $this->_data['parentAttendeeId'] = $parentAttendeeId; // used in notifications $this->_db->commit(); } catch (Exception $e) { $this->_db->rollBack(); Qs_Debug::processException($e); return false; } $includeInvoice = ('n' === $data['paid']); $checkoutView = new CheckoutView(); $checkoutView->setDoc(Zend_Registry::get('doc')); $checkoutView->sendUserPaymentNotification($transactionId, $includeInvoice); return $this->getPrimaryKey(); } }