_savePrizeInfo(); $this->_saveUserSocialLinks(); return parent::_insertDependency(); } protected function _updateDependency() { $this->_savePrizeInfo(); $this->_saveUserSocialLinks(); return parent::_updateDependency(); } protected function _deleteDependency() { $this->_deletePrizeInfo(); return parent::_deleteDependency(); } protected function _savePrizeInfo() { $values = []; foreach ($this->_prizeFields as $field) { $values[$field] = Qs_Array::get($this->_data, $field, ''); } $table = $this->_getTable($this->_tableAlias . 'Prize'); if ($table->findRow($this->getPrimaryKey())) { $table->updateByKey($values, $this->getPrimaryKey()); } else { $values['userId'] = $this->getPrimaryKey(); $table->insert($values); } return $this; } protected function _deletePrizeInfo() { $where = [ $this->_db->quoteInto('`userId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE), ]; $this->_getTable($this->_tableAlias . 'Prize')->delete($where); return $this; } protected function _addDependenciesFromDb(array &$data) { $prizeInfo = $this->_getTable($this->_tableAlias . 'Prize')->findRow($this->getPrimaryKey()); if ($prizeInfo) { $prizeInfo = $prizeInfo->toArray(); unset($prizeInfo['added'], $prizeInfo['changed']); $data = array_merge($data, $prizeInfo); } return parent::_addDependenciesFromDb($data); } protected function _addSocialLinks(&$data) { $ownSocialLinks = $this->_getOwnSocialLinks(); foreach ($ownSocialLinks as $socialLink) { $data['socialLink' . $socialLink['linkId']] = $socialLink['link']; } return $this; } public function getFilterFields() { if (!$this->_filterFields) { $filterFields = $this->getConfig('filterFields'); $this->_filterFields = ($filterFields) ? $filterFields->toArray() : []; } return $this->_filterFields; } protected function _filter(\Zend_Db_Select $select) { $select->where('`' . $this->_tableAlias . '`.`bought` = "y"'); return parent::_filter($select); } public function getExportColumns() { $columns = $this->getConfig('export')->fields->toArray(); foreach ($columns as $key => $title) { if ('' == $title) { if (strtolower($key) === $key) { $title = ucfirst($key); } else { $title = ucfirst(Qs_String::decamelize($key)); } $columns[$key] = $title; } } return $columns; } public function getList4ExportStatement() { $select = $this->_db->select(); $select->from($this->_getPair()); $select->joinLeft( $this->_getPair($this->_tableAlias . 'Status', 's'), '`s`.`id` = `User`.`status`', ['status' => 'title'] ); $select->joinLeft( $this->_getPair('MembershipType', 'mt'), '`mt`.`id` = `User`.`membershipTypeId`', ['membershipType' => 'title'] ); $select->joinLeft( $this->_getPair($this->_tableAlias . 'Prize', 'up'), '`up`.`userId` = `User`.`id`', $this->_prizeFields ); $select->where('`User`.`bought` = "y"'); $this->_filter($select); $this->_applySelectOptions($select, $this->_selectOptions); return $select->query(); } public function prepareExportRow(array &$data) { $this->_prepareBio($data['bio']); // prepare addresses $this->_addAddressesFromDb($data); if (array_key_exists(Entity::ADDRESS_SHIPPING, $data) && 'y' == Qs_Array::get($data[Entity::ADDRESS_SHIPPING], 'asBilling') ) { $data[Entity::ADDRESS_SHIPPING] = array_merge( $data[Entity::ADDRESS_SHIPPING], $data[Entity::ADDRESS_BILLING] ); } else { $data[Entity::ADDRESS_SHIPPING]['asBilling'] = 'n'; } foreach ([Entity::ADDRESS_CONTACT, Entity::ADDRESS_BILLING, Entity::ADDRESS_SHIPPING] as $type) { if (array_key_exists($type, $data)) { foreach ($data[$type] as $key => $val) { $index = $type . ucfirst($key); $data[$index] = $val; } } } // prepare photo link if (!empty($data['photoH'])) { $data['photoH'] = BASE_URL . '/' . Qs_ImageFs::get($data['photoH']); } if (!empty($data['photoV'])) { $data['photoV'] = BASE_URL . '/' . Qs_ImageFs::get($data['photoV']); } return $this; } protected function _prepareBio(&$bio) { $bio = strip_tags($bio); $bio = preg_replace("/[\n\r]+/", "\n", $bio); $bio = preg_replace("/\s+/", " ", $bio); return $this; } }