['title']]; protected $_rawDataFields = ['emailNote']; protected $_urlParseFields = ['emailNote']; public function insert(array $data = []) { $data = empty($data) ? $this->_data : $data; $this->_primaryKey = $this->getModel()->insert($data); $this->_handleFiles(); return $this->_primaryKey; } public function update(array $data = []) { $data = empty($data) ? $this->_data : $data; $result = $this->getModel()->update($data, $this->_primaryKey); $this->_handleFiles(); return $result; } protected function _prepareList(&$list) { if (!($ids = array_column($list, 'id'))) { return $this; } $this->_prepareListNaicsCodes($list, $ids); $this->_prepareListVendors($list, $ids); return parent::_prepareList($list); } private function _prepareListNaicsCodes(array &$list, array $ids) { $select = $this->_db->select(); $select->from($this->_getPair('LibraryNaics', 'ln'), ['ln.libraryId', 'naicsCode']); $select->joinLeft( $this->_getPair('Naics', 'n'), '`n`.`id` = `ln`.`naicsCode`', ['naicsCodeTitle' => 'title'] ); $select->where('`ln`.`libraryId` IN (?)', $ids, Qs_Db::INT_TYPE); $map = $this->_db->fetchAll($select, [], Qs_Db::FETCH_GROUP | Qs_Db::FETCH_ASSOC); foreach ($list as &$row) { $row['naicsCodes'] = Qs_Array::fetchColAll(Qs_Array::get($map, $row['id'], []), 'naicsCodeTitle'); } return $this; } private function _prepareListVendors(array &$list, array $ids) { $select = $this->_db->select(); $select->from($this->_getPair('LibraryVendor', 'lv'), ['libraryId']); $select->joinLeft( $this->_getPair('Vendor', 'v'), '`v`.`id` = `lv`.`vendorId`', [ 'vendorName' => 'dbaName', 'isBlacklisted' => (new BlacklistObj())->getIsVendorBlacklistedExpr('v', AclPermission::getAdminTribeId()), ] ); $select->where('`lv`.`libraryId` IN (?)', $ids, Qs_Db::INT_TYPE); $vendors = $this->_db->fetchAll($select, [], Qs_Db::FETCH_GROUP | Qs_Db::FETCH_ASSOC); foreach ($list as &$row) { $row['vendors'] = Qs_Array::get($vendors, $row['id'], []); } return $this; } }