_db->select(); $select->from($this->_getPair(), new Zend_Db_Expr('1')); $select->where('`l`.`id` = ?', $licenseId, Qs_Db::INT_TYPE); $select->where('`l`.`vendorId` = ?', $vendorId, Qs_Db::INT_TYPE); return '1' === $this->_db->fetchOne($select); } public function getListSelect() { if (null == $this->_select) { $this->_select = parent::getListSelect(); $this->_select->reset(Zend_Db_Select::FROM); $this->_select->reset(Zend_Db_Select::COLUMNS); $this->_select->reset(Zend_Db_Select::WHERE); $this->_select->union([ $this->_getLicensesSelect(), $this->_getPremiumLicensesSelect(), ]); } return $this->_select; } protected function _getLicensesSelect() { $select = $this->_db->select(); $columns = [ '*', 'type' => new Zend_Db_Expr('"' . Entity::USER_TYPE_LICENSE . '"'), 'typeTitle' => $this->getModel()->getUserLicenceTypeTitleExpr(Entity::USER_TYPE_LICENSE), 'tribeId' => new Zend_Db_Expr('NULL'), 'tribeTitle' => new Zend_Db_Expr('NULL'), 'tribeStatus' => new Zend_Db_Expr('status'), 'totalTitle' => new Zend_Db_Expr('total'), 'approvedDate' => new Zend_Db_Expr('added'), 'expiredOnDate' => new Zend_Db_Expr('expiredOn'), ]; $select->from($this->_getPair(), $columns); $select->where('`l`.`vendorId` = ?', $this->_filter['vendorId'], Qs_Db::INT_TYPE); return $select; } protected function _getPremiumLicensesSelect() { $select = $this->_db->select(); $columns = [ '*', 'type' => new Zend_Db_Expr('"' . Entity::USER_TYPE_PREMIUM . '"'), 'typeTitle' => $this->getModel()->getUserLicenceTypeTitleExpr(Entity::USER_TYPE_PREMIUM), 'tribeId' => new Zend_Db_Expr('`lt`.`tribeId`'), 'tribeTitle' => new Zend_Db_Expr('`t`.`title`'), 'tribeStatus' => $this->getModel()->getLicenseStatus4TribeExpr(), 'totalTitle' => $this->getModel()->getPremiumLicenseTotalTitleExpr(), 'approvedDate' => $this->getModel()->getPremiumLicenseApprovedDateExpr(), 'expiredOnDate' => $this->getModel()->getPremiumLicenseExpiredOnDateExpr(), ]; $select->from($this->_getPair(), $columns); $select->joinLeft( $this->_getPair('LicenseTribe', 'lt'), '`lt`.`licenseId` = `l`.`id`', [] ); $select->joinLeft( $this->_getPair('Tribe', 't'), '`lt`.`tribeId` = `t`.`id`', [] ); $select->where('`l`.`vendorId` = ?', $this->_filter['vendorId'], Qs_Db::INT_TYPE); return $select; } }