/**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     $authService = $this->userService->getAuthService();
     if (!$authService->hasIdentity()) {
         return array($this->getDefaultRole());
     }
     // get roles associated with the logged in user
     $sql = new Sql($this->adapter);
     $select = $sql->select()->columns(array('role_id' => 'roleId'))->from(array('roles' => 'user_role'))->join(array('linker' => $this->tableName), 'roles.id = linker.role_id', array())->where(array('linker.user_id = ?' => $authService->getIdentity()->getId()));
     $results = $sql->prepareStatementForSqlObject($select)->execute();
     $roles = array();
     foreach ($results as $i) {
         $roles[] = $i['role_id'];
     }
     return $roles;
 }
 /**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     $authService = $this->userService->getAuthService();
     if (!$authService->hasIdentity()) {
         return array($this->getDefaultRole());
     }
     // get roles associated with the logged in user
     $sql = new Sql($this->adapter);
     $select = $sql->select()->from($this->tableName);
     $where = new Where();
     $where->equalTo('user_id', $authService->getIdentity()->getId());
     $results = $sql->prepareStatementForSqlObject($select->where($where))->execute();
     $roles = array();
     foreach ($results as $i) {
         $roles[] = $i['role_id'];
     }
     return $roles;
 }
 /**
  * {@inheritDoc}
  */
 public function getIdentityRoles()
 {
     $authService = $this->userService->getAuthService();
     if (!$authService->hasIdentity()) {
         return array($this->getDefaultRole());
     }
     // get roles associated with the logged in user
     $sql = new Select();
     $sql->from($this->tableName);
     // @todo these fields should eventually be configurable
     $sql->join('user_role', 'user_role.id = ' . $this->tableName . '.role_id');
     $sql->where(array('user_id' => $authService->getIdentity()->getId()));
     $results = $this->tableGateway->selectWith($sql);
     $roles = array();
     foreach ($results as $role) {
         $roles[] = $role['role_id'];
     }
     return $roles;
 }
Exemple #4
0
 /**
  * @covers ZfcUser\Service\User::getAuthService
  */
 public function testGetAuthService()
 {
     $this->serviceManager->expects($this->once())->method('get')->with('zfcuser_auth_service')->will($this->returnValue($this->authService));
     $service = new Service();
     $service->setServiceManager($this->serviceManager);
     $this->assertInstanceOf('Zend\\Authentication\\AuthenticationServiceInterface', $service->getAuthService());
 }