public function findQuestionsForAccountType($accountType) { $sql = ' SELECT `question`.* FROM ' . BOL_QuestionDao::getInstance()->getTableName() . ' as `question` INNER JOIN ' . $this->getTableName() . ' as `atq` ON ( `atq`.`questionName` = `question`.`name` ) INNER JOIN ' . BOL_QuestionAccountTypeDao::getInstance()->getTableName() . ' as `account` ON ( `account`.`name` = `atq`.`accountType` ) WHERE `atq`.`accountType` = :accountType '; return $this->dbo->queryForObjectList($sql, BOL_QuestionDao::getInstance()->getDtoClassName(), array('accountType' => $accountType)); }
public function addRoleByAccountType(BOL_QuestionAccountType $accountType) { if (empty($accountType)) { return; } $sql = " REPLACE INTO `" . BOL_AuthorizationUserRoleDao::getInstance()->getTableName() . "` ( `userId`, `roleId` ) " . "SELECT u.id, :role FROM " . BOL_UserDao::getInstance()->getTableName() . " u " . " INNER JOIN " . BOL_QuestionAccountTypeDao::getInstance()->getTableName() . " `accountType` ON ( accountType.name = u.accountType ) " . " WHERE u.accountType = :account "; $this->dbo->query($sql, array('account' => $accountType->name, 'role' => $accountType->roleId)); }
public function addUsersRoleByAccountType(BOL_QuestionAccountType $accountType) { if (empty($accountType)) { return; } /* @var $defaultRole BOL_AuthorizationRole */ $defaultRole = BOL_AuthorizationService::getInstance()->getDefaultRole(); if ($accountType->roleId == $defaultRole->id) { return; } $this->accountDao->addRoleByAccountType($accountType); }
/** * @param $userId * @return int */ public function getUserAccountTypeId($userId) { if (!$userId) { return null; } $user = BOL_UserService::getInstance()->findUserById($userId); if (!$user) { return null; } $accTypeName = $user->getAccountType(); $accTypeList = BOL_QuestionAccountTypeDao::getInstance()->findAccountTypeByNameList(array($accTypeName)); $accountTypeId = isset($accTypeList[0]) ? $accTypeList[0]->id : null; return $accountTypeId; }
public function findViewQuestionsForAccountType($accountType) { if ($accountType === null) { return array(); } $accountTypeName = trim($accountType); $sql = " SELECT `question`.* FROM `" . $this->getTableName() . "` as `question`\n\n LEFT JOIN `" . BOL_QuestionSectionDao::getInstance()->getTableName() . "` as `section`\n ON ( `question`.`sectionName` = `section`.`name` AND `question`.`sectionName` != '' AND `question`.`sectionName` IS NOT NULL )\n\n LEFT JOIN " . BOL_QuestionAccountTypeDao::getInstance()->getTableName() . " as `account` ON( `account`.`name` = `question`.`accountTypeName` )\n\n WHERE ( `account`.`name` IS NULL OR `question`.`accountTypeName` = :accountTypeName OR :accountTypeName = 'all' )\n AND `question`.`onView` = '1' \n ORDER BY IF( `section`.`name` IS NULL, 0, 1 ), `section`.`sortOrder`, `question`.`sortOrder` "; return $this->dbo->queryForList($sql, array('accountTypeName' => $accountTypeName)); }
/** * @param $name * @return BOL_QuestionAccountType */ public function findAccountTypeByName($name) { if (!mb_strlen($name)) { return null; } $types = $this->accountDao->findAccountTypeByNameList(array($name)); if (!$types) { return null; } $res = array(); foreach ($types as $type) { $res[$type->name] = $type; } return isset($res[$name]) ? $res[$name] : null; }