$this->db]))->getList(); } public function getUserEmails($vendorId) { if (empty($vendorId)) { throw new Exception('Vendor ID is not defined'); } return $this->getTable('User')->fetchColumn('email', compact('vendorId')); } protected function initData(array &$data) { $this->getTable()->emptyToNull($data); return $this; } protected function saveDependencies(array $data) { foreach ([AddressEntity::TYPE_BILLING, AddressEntity::TYPE_MAILING] as $type) { $field = $type . 'Address'; if (array_key_exists($field, $data)) { $this->saveAddress($data[$field], $type, $data['id']); } } foreach (['questionnaire', 'partners', 'businessReferences'] as $name) { $method = 'save' . ucfirst($name); if (array_key_exists($name, $data) && method_exists($this, $method)) { $this->$method($data[$name], $data['id']); } } return $this; } private function saveAddress(array $address, $type, $vendorId) { $key = compact('vendorId', 'type'); $this->getTable('VendorAddress')->deleteBy($key); $this->getTable('VendorAddress')->insert(array_merge($key, $address)); return $this; } /** @noinspection PhpUnusedPrivateMethodInspection */ /** * @param array $questions * @param $vendorId * @return $this */ private function saveQuestionnaire(array $questions, $vendorId) { $list = []; foreach ($questions as $question) { $list[] = Qs_Array::map($question, ['questionId' => 'id', 'answer', 'explanation']); } $this->getTable('VendorQuestionnaire')->saveRelations($list, compact('vendorId')); return $this; } /** @noinspection PhpUnusedPrivateMethodInspection */ /** * @param array $partners * @param $vendorId * @return $this */ private function savePartners(array $partners, $vendorId) { $this->getTable('VendorPartner')->saveRelations($partners, compact('vendorId')); return $this; } /** @noinspection PhpUnusedPrivateMethodInspection */ private function saveBusinessReferences(array $references, $vendorId) { array_walk($references, function (array &$ref) { $ref['state'] = ($ref['state']) ?: null; }); $this->getTable('VendorBusinessReference')->saveRelations($references, compact('vendorId')); return $this; } public function getPartners($vendorId) { $columns = ['name', 'title', 'ownershipPercent', 'businessPhone', 'homePhone']; return $this->getTable('VendorPartner')->getList($columns, compact('vendorId')); } public function getBusinessReferences($vendorId) { $columns = ['name', 'address', 'city', 'state', 'zip', 'phone']; return $this->getTable('VendorBusinessReference')->getList($columns, compact('vendorId')); } public function getQuestionnaire($vendorId) { $select = $this->db->select(); $select->from(Qs_Db::getPair('Questionnaire', 'q'), ['id', 'question']); $select->join(Qs_Db::getPair('VendorQuestionnaire', 'vq'), '`vq`.`questionId` = `q`.`id`', ['answer', 'explanation']); $select->where('`vq`.`vendorId` = ?', $vendorId, Qs_Db::INT_TYPE); $select->order('q.sorter'); return $this->db->fetchAll($select); } public function getSoleProprietorNameExpr($alias = null) { if (null === $alias) { $alias = $this->tableShortAlias; } $prefix = $alias ? "`{$alias}`." : ''; return new Zend_Db_Expr( "CONCAT_WS(' ', {$prefix}`soleProprietorFirstName`, {$prefix}`soleProprietorLastName`)" ); } /** * @param array $data * @return void * @throws \Qs_Exception */ public function mapCollections(array &$data) { $states = StateModel::get4Select(); $dropdownMap = [ 'preferredVendorTitle' => ['field' => 'preferredVendor', 'collection' => 'yesNoOptions'], 'organizationTypeTitle' => ['field' => 'organizationTypeId', 'collection' => 'organizationTypes'], 'soleProprietorDlStateTitle' => ['field' => 'soleProprietorDlState', 'collection' => $states], ]; foreach ($dropdownMap as $field => $options) { if (($value = Qs_Array::get($data, $options['field']))) { $collection = is_array($options['collection']) ? $options['collection'] : $this->getConfigArray($options['collection']); $data[$field] = $collection[$value]; } } } public function find(array $key) { if (empty($key)) { return null; } $soleProprietorName = 'CONCAT_WS(" ", `soleProprietorFirstName`, `soleProprietorLastName`)'; $select = $this->getTable()->getListSelect(['*', 'soleProprietorName' => $soleProprietorName], $key); return $select->getAdapter()->fetchRow($select); } public function get($id, $mode = self::ALL_DATA) { if (($data = $this->find(compact('id')))) { $this->mapCollections($data); if ($mode == self::ALL_DATA) { $key = ['vendorId' => $id]; $data['billingAddress'] = $this->getBillingAddress($key); $data['mailingAddress'] = $this->getMailingAddress($key); $data['partners'] = $this->getPartners($id); $data['businessReferences'] = $this->getBusinessReferences($id); $data['questionnaire'] = $this->getQuestionnaire($id); } } return $data; } public static function getAutocopleteNameDbExpr($alias = 'Vendor') { return new Zend_Db_Expr("CONCAT_WS(' - ', `{$alias}`.`dbaName`, `{$alias}`.`businessName`)"); } }