_select) { parent::getListSelect(); $this->_select->join($this->_getPair('Admin', 'a'), '`a`.`id` = `vb`.`adminId`', [ 'adminName' => self::EXPR_ADMIN_NAME, ]); $this->_select->joinLeft($this->_getPair('Tribe', 't'), '`t`.`id` = `a`.`tribeId`', [ 'tribeTitle' => self::EXPR_TRIBE_TITLE, ]); $this->_select->join($this->_getPair('Vendor', 'v'), '`v`.`id` = `vb`.`vendorId`', [ 'vendorName' => 'dbaName', ]); } return $this->_select; } protected function _markVendorBlacklistedByAdmin($value, $vendorId) { $this->_getTable('Vendor')->updateDataByKey(['blacklistedByAdmin' => $value], $vendorId); } protected function _addVendorTribesToBlackList(array $tribes, $vendorId) { $this->_getTable('VendorTribeBlacklist')->saveRelationIds($tribes, 'tribeId', compact('vendorId')); return $this; } protected function _removeVendorTribesFromBlackList(array $tribes, $vendorId) { $where[] = $this->_db->quoteInto('`vendorId` = ?', $vendorId, Qs_Db::INT_TYPE); $where[] = $this->_db->quoteInto('`tribeId` IN (?)', $tribes); $this->_getTable('VendorTribeBlacklist')->delete($where); return $this; } protected function _insertDependency() { return $this->_saveDependency(); } private function _saveDependency() { if (isset($this->_data['tribeIds']) && !empty($this->_data['tribeIds'])) { if ($this->_data['status'] == Entity::STATUS_BLACKLIST) { //add to blacklist if (isset($this->_data['vendorId'])) { $this->_addVendorTribesToBlackList($this->_data['tribeIds'], $this->_data['vendorId']); } } else if ($this->_data['status'] == Entity::STATUS_WHITELIST) { //remove from blacklist if (isset($this->_data['vendorId'])) { $this->_removeVendorTribesFromBlackList($this->_data['tribeIds'], $this->_data['vendorId']); } } } else { if ($this->_data['status'] == Entity::STATUS_BLACKLIST) { //mark as blacklisted if (isset($this->_data['vendorId'])) { $this->_markVendorBlacklistedByAdmin('y', $this->_data['vendorId']); } } else if ($this->_data['status'] == Entity::STATUS_WHITELIST) { //unmark as blacklisted if (isset($this->_data['vendorId'])) { $this->_markVendorBlacklistedByAdmin('n', $this->_data['vendorId']); } } } return $this; } public function getIsVendorBlacklistedExpr($tableAlias = 'v', $tribeId = null) { if ($tribeId) { $select = $this->_db->select(); $select->from($this->_getPair('VendorTribeBlacklist', 'vtb'), [new Zend_Db_Expr('1')]); $select->where("`vtb`.`vendorId` = `{$tableAlias}`.`id`"); $select->where("`vtb`.`tribeId` = ?", $tribeId, Qs_Db::INT_TYPE); $select->limit(1); return new Zend_Db_Expr( "(IF((`{$tableAlias}`.`blacklistedByAdmin` = 'y') OR (EXISTS({$select})), 'y', 'n'))"); } else { return new Zend_Db_Expr( "(IF(`{$tableAlias}`.`blacklistedByAdmin` = 'y', 'y', 'n'))"); } } }