_filterFields['u'] = array('memberId', $this->_getAttendeeNameExpr()); parent::_init(); } protected function _getFromColumns() { $columns = parent::_getFromColumns(); $columns['attendeeName'] = $this->_getAttendeeNameExpr(); $columns['attendeeEmail'] = $this->_getAttendeeEmailExpr(); return $columns; } protected function _getFromDbSelect($primaryKey) { $select = parent::_getFromDbSelect($primaryKey); $this->_joinParentAttendee($select); $this->_joinUser($select); $this->_joinTransaction($select); return $select; } public function getListSelect() { if (null == $this->_select) { parent::getListSelect(); $this->_joinParentAttendee($this->_select); $this->_joinUser($this->_select); $this->_joinTeam($this->_select); $this->_joinTransaction($this->_select); } return $this->_select; } protected function _joinUser(\Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('User', 'u'), '`u`.`id` = `ea`.`userId`', array('userMemberId' => 'IFNULL(memberId, "-")') ); return $this; } protected function _joinTeam(\Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('EventTeam', 'et'), '`et`.`eventId` = `ea`.`eventId` AND `et`.`id` = `ea`.`teamId`', array('teamName' => 'title') ); return $this; } protected function _joinParentAttendee(\Zend_Db_Select $select) { $select->join( $this->_getPair('EventAttendee', 'pa'), '`pa`.`id` = `ea`.`parentAttendeeId`', array() ); return $this; } protected function _joinTransaction(\Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('Cart', 'c'), '`c`.`id` = `ea`.`cartId`', array() ); $select->joinLeft( $this->_getPair('Transaction', 't'), '`t`.`id` = `c`.`transactionId`', array('transactionId' => 'id', 'paymentType', 'paymentTypeTitle', 'paid') ); return $this; } /** * @param bool $paid * @param string $paymentMethod * @return bool */ public function switchPaid($paid, $paymentMethod) { $this->_clearErrors(); return $this->_updatePaidField($paid ? 'y' : 'n', $paymentMethod); } /** * @param string $paid 'y'|'n' * @param null $paymentMethod * @return bool|int */ protected function _updatePaidField($paid, $paymentMethod = null) { $data = $this->getData(); if ($data && $data['transactionId'] && OrderObj::PAYMENT_TYPE_AUTHORIZE !== $data['paymentType']) { $update = array('paid' => $paid); if ('y' === $paid) { $update['purchaseDate'] = date('Y-m-d H:i:s'); } if (isset($paymentMethod)) { if (isset(OrderObj::$paymentMethodsTitles[$paymentMethod])) { $update['paymentType'] = $paymentMethod; $update['paymentTypeTitle'] = OrderObj::$paymentMethodsTitles[$paymentMethod]; } else { $this->_addError('Wrong Payment Method "' . $paymentMethod . '"'); return false; } } return (bool) $this->_getTable('Transaction')->update($update, array('id = ?' => $data['transactionId']) ); } return false; } public function getAttendeeEmails($parentAttendeeId) { $select = $this->_db->select(); $select->from($this->_getPair(), array('email' => $this->_getAttendeeEmailExpr())); $select->joinLeft($this->_getPair('User', 'u'), '`u`.`id` = `ea`.`userId`', array()); $select->where('ea.eventId = ?', $this->getEventId(), Qs_Db::INT_TYPE); $select->where('ea.parentAttendeeId = ?', $parentAttendeeId, Qs_Db::INT_TYPE); $this->where($select, 'ea'); return $this->_db->fetchCol($select); } }