Пример #1
0
 protected function buildFrom()
 {
     $this->_selectBuilder->from->add(Gpf_Db_Table_LoginsHistory::getName(), 'l');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'u', 'l.accountuserid=u.accountuserid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'u.authid=au.authid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), 'r', 'r.roleid=u.roleid');
 }
Пример #2
0
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_Users::getName(), 'u');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(),
         'gu', 'u.accountuserid=gu.accountuserid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(),
         'au', 'au.authid=gu.authid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Accounts::getName(),
         'a', 'a.accountid=gu.accountid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Roles::getName(),
         'r', 'r.roleid=gu.roleid');
 }
 /**
  * Return count of online users per role
  *
  * @service online_user read
  * @param Gpf_Rpc_Params $params
  */
 public function getOnlineRolesCount(Gpf_Rpc_Params $params)
 {
     $sql = new Gpf_SqlBuilder_SelectBuilder();
     $sql->from->add(Gpf_Db_Table_Roles::getName(), 'r');
     $sql->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'u', 'u.roleid=r.roleid');
     $sql->from->addInnerJoin(Gpf_Db_Table_LoginsHistory::getName(), 'l', 'l.accountuserid=u.accountuserid');
     $sql->select->add(Gpf_Db_Table_Roles::NAME, Gpf_Db_Table_Roles::NAME, 'r');
     $sql->select->add('count(*)', 'usersCount');
     $sql->where->add(Gpf_Db_Table_LoginsHistory::LOGOUT, 'is', 'NULL', 'AND', false);
     $sql->where->add(Gpf_Db_Table_LoginsHistory::LAST_REQUEST, '>', "('" . $this->createDatabase()->getDateString() . "' - INTERVAL 1800 SECOND)", 'AND', false);
     Gpf_Plugins_Engine::extensionPoint('Gpf_Report_OnlineUsersGadget.getOnlineRolesCount', $sql->where);
     $sql->groupBy->add('r.' . Gpf_Db_Table_Roles::ID);
     return $this->translateRoleNames($sql->getAllRows());
 }
Пример #4
0
 public function loadByRoleType($roleType, $application)
 {
     $query = new Gpf_SqlBuilder_SelectBuilder();
     $query->select->addAll(Gpf_Db_Table_Users::getInstance(), 'u');
     $query->from->add(Gpf_Db_Table_Users::getName(), "u");
     $query->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), "r", "r.roleid = u.roleid");
     $query->from->addInnerJoin(Gpf_Db_Table_Accounts::getName(), "a", "u.accountid = a.accountid");
     $query->where->add('u.authid', '=', $this->getAuthId());
     $query->where->add('u.accountid', '=', $this->getAccountId());
     $query->where->add('a.application', '=', $application);
     $query->where->add('r.roletype', '=', $roleType);
     $record = $query->getOneRow();
     $this->fillFromRecord($record);
 }
 /**
  * Validate Db_Row
  *
  * @param Gpf_DbEngine_Row $row
  * @throws Gpf_DbEngine_Row_ConstraintException
  */
 public function validate(Gpf_DbEngine_Row $row)
 {
     $role = new Gpf_Db_Role();
     $role->setId($row->getRoleId());
     $role->load();
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('r.' . Gpf_Db_Table_Roles::TYPE);
     $select->from->add(Gpf_Db_Table_Users::getName(), 'u');
     $select->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), 'r', 'u.' . Gpf_Db_Table_Users::ROLEID . '=r.' . Gpf_Db_Table_Roles::ID);
     $select->where->add('u.' . Gpf_Db_Table_Users::AUTHID, '=', $row->getAuthId());
     $select->where->add('u.' . Gpf_Db_Table_Users::ACCOUNTID, '=', $row->getAccountId());
     $select->where->add('r.' . Gpf_Db_Table_Roles::TYPE, '=', $role->getRoleType());
     $select->where->add('u.' . Gpf_Db_Table_Users::ID, '<>', $row->getPrimaryKeyValue());
     try {
         $select->getOneRow();
     } catch (Gpf_DbEngine_NoRowException $e) {
         return;
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
     }
     throw new Gpf_DbEngine_Row_ConstraintException('username', $this->_('Selected username already exists'));
 }
	/**
	 * @return Gpf_SqlBuilder_SelectBuilder
	 */
	protected function createSelectBuilder() {
		$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
		$selectBuilder->select->add(Gpf_Db_Table_Roles::ID, self::ID);
		$selectBuilder->select->add(Gpf_Db_Table_Roles::NAME, self::VALUE);
		$selectBuilder->from->add(Gpf_Db_Table_Roles::getName());

		$accountCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
        if (Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ) ||
        Gpf_Session::getAuthUser()->hasPrivilege(Pap_Privileges::ROLE_NAME, Pap_Privileges::P_READ)) {
            $accountCondition->add(Gpf_Db_Table_Accounts::ID, '!=', '', 'OR');
        } else {
            $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', Gpf_Session::getInstance()->getAuthUser()->getAccountId(), 'OR');
        }
		$accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', null, 'OR');
		$selectBuilder->where->addCondition($accountCondition);
		$selectBuilder->where->add(Gpf_Db_Table_Roles::TYPE, '=', Pap_Application::ROLETYPE_MERCHANT);
		$selectBuilder->orderBy->add(Gpf_Db_Table_Accounts::ID);
		$selectBuilder->orderBy->add(Gpf_Db_Table_Roles::NAME);

		return $selectBuilder;
	}
Пример #7
0
 /**
  * Get list of roles
  *
  * @service
  * @anonym
  * @param Gpf_Rpc_Params $parmas
  */
 public function getRolesList(Gpf_Rpc_Params $params)
 {
     if (!Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ) && !Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Pap_Privileges::P_READ_OWN)) {
         throw new Gpf_Rpc_PermissionDeniedException('Gpf_Db_Table_Roles', 'getRolesList');
     }
     $sql = new Gpf_SqlBuilder_SelectBuilder();
     $sql->from->add(Gpf_Db_Table_Roles::getName());
     $sql->select->addAll(Gpf_Db_Table_Roles::getInstance());
     $accountCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
     if (Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ)) {
         $accountCondition->add(Gpf_Db_Table_Accounts::ID, '!=', '', 'OR');
     } else {
         $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', Gpf_Session::getInstance()->getAuthUser()->getAccountId(), 'OR');
     }
     $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', null, 'OR');
     $sql->where->addCondition($accountCondition);
     if ($params->exists('roleTypes') && $params->get('roleTypes') !== '') {
         $sql->where->add(Gpf_Db_Table_Roles::TYPE, 'IN', explode(',', $params->get('roleTypes')));
     }
     $sql->orderBy->add(Gpf_Db_Table_Accounts::ID);
     $sql->orderBy->add(Gpf_Db_Table_Roles::NAME);
     return $sql->getAllRows();
 }
Пример #8
0
 public function isExists()
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('au.' . Gpf_Db_Table_AuthUsers::ID, Gpf_Db_Table_AuthUsers::ID);
     $select->from->add(Gpf_Db_Table_Users::getName(), 'u');
     $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'u.' . Gpf_Db_Table_Users::AUTHID . '=au.' . Gpf_Db_Table_AuthUsers::ID);
     $select->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), 'r', 'u.' . Gpf_Db_Table_Users::ROLEID . '=r.' . Gpf_Db_Table_Roles::ID);
     $select->where->add('au.' . Gpf_Db_Table_AuthUsers::ID, '=', $this->authId);
     $select->where->add('u.' . Gpf_Db_Table_Roles::ID, '=', $this->roleid);
     $select->where->add('u.' . Gpf_Db_Table_Users::ACCOUNTID, '=', $this->accountid);
     try {
         $select->getOneRow();
         return true;
     } catch (Gpf_Exception $e) {
     }
     return false;
 }
Пример #9
0
 /**
  *
  * @param Gpf_Auth_Info $authInfo
  * @return Gpf_Data_RecordSet
  */
 public static function getAccounts(Gpf_Auth_Info $authInfo)
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('a.accountid', 'accountid');
     $select->select->add('a.name', 'name');
     $select->from->add(Gpf_Db_Table_AuthUsers::getName(), 'au');
     $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'u', 'au.authid=u.authid');
     $select->from->addInnerJoin(self::getName(), 'a', 'a.accountid=u.accountid');
     $select->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), 'r', 'u.roleid=r.roleid');
     $authInfo->addWhere($select);
     $select->where->add('a.rstatus', 'IN', array(Gpf_Db_Account::APPROVED, Gpf_Db_Account::SUSPENDED));
     return $select->getAllRows();
 }
Пример #10
0
	/**
	 * @param String $userName
	 * @param String $password
	 *
	 * @return Gpf_SqlBuilder_SelectBuilder
	 */
	private function loadUser($userName, $password) {
		$select = new Gpf_SqlBuilder_SelectBuilder();

		$select->select->add('pu.'.Pap_Db_Table_Users::ID, 'userid');
		$select->select->add('gu.'.Gpf_Db_Table_Users::ROLEID, 'roleid');

		$select->from->add(Pap_Db_Table_Users::getName(), 'pu');
		$select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu',
		  'pu.'.Pap_Db_Table_Users::ACCOUNTUSERID.'=gu.'.Gpf_Db_Table_Users::ID);
		$select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(),
		  'au', 'gu.'.Gpf_Db_Table_Users::AUTHID.'=au.'.Gpf_Db_Table_AuthUsers::ID);
		$select->from->addInnerJoin(Gpf_Db_Table_Roles::getName(), 'r',
		  'gu.'.Gpf_Db_Table_Users::ROLEID.'=r.'.Gpf_Db_Table_Roles::ID);

		$select->where->add('au.'.Gpf_Db_Table_AuthUsers::USERNAME, '=', $userName);
		$select->where->add('au.'.Gpf_Db_Table_AuthUsers::PASSWORD, '=', $password);

		return $select;
	}