_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) { $this->_credentialTreatment = '?'; } $credentialExpression = new Zend_Db_Expr( '(CASE WHEN ' . $this->_zendDb->quoteInto( $this->_zendDb->quoteIdentifier($this->_credentialColumn, true) . ' = ' . $this->_credentialTreatment, $this->_credential ) . ' THEN 1 ELSE 0 END) AS ' . $this->_zendDb->quoteIdentifier( $this->_zendDb->foldCase('zend_auth_credential_match') ) ); // get select $dbSelect = clone $this->getDbSelect(); $dbSelect->from([$this->_tableAlias => $this->_tableName], array('*', $credentialExpression)); $this->_joinCompany($dbSelect); $dbSelect->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity); $dbSelect->where('`bought` = "y"'); return $dbSelect; } protected function _autologinCodeAuthenticateCreateSelect() { $credentialExpression = new Zend_Db_Expr('1 AS `zend_auth_credential_match`'); $dbSelect = clone $this->getDbSelect(); $dbSelect->from([$this->_tableAlias => $this->_tableName], array('*', $credentialExpression)); $this->_joinCompany($dbSelect); $dbSelect->where($this->_zendDb->quoteIdentifier($this->_autologinColumn, true) . ' = ?', $this->_autologinCode); $dbSelect->where('`bought` = "y"'); return $dbSelect; } protected function _joinCompany(Zend_Db_Select $select) { $select->join( Qs_Db::getPair('Company'), '`Company`.`id` = `' . $this->_tableAlias . '`.`companyId`', ['companyStatus' => 'status', 'companyType' => 'type', 'companyName' => 'name'] ); $select->joinLeft( Qs_Db::getPair('CompanyPermission'), '`CompanyPermission`.`companyId` = `Company`.`id` AND `CompanyPermission`.`userId` = `' . $this->_tableAlias . '`.`id`', ['hasPermission' => new Zend_Db_Expr('IF (`CompanyPermission`.`userId` IS NULL, FALSE, TRUE)')] ); $select->where( '`Company`.`type` IN (?)', [CompanyEntity::TYPE_REGULAR, CompanyEntity::TYPE_AFFILIATE, CompanyEntity::TYPE_ASSOCIATE] ); return $this; } protected function _authenticateCreateSelect() { if (isset($this->_autologinCode)) { $dbSelect = $this->_autologinCodeAuthenticateCreateSelect(); } else { $dbSelect = $this->_passwordAuthenticateCreateSelect(); } return $dbSelect; } }