Gets a Site Role by his Id.
@param mixed $nb_site_role A CNabuDataObject containing a field named nb_role_id or a valid Id.
@return CNabuSiteRole|bool Returns the Site Role instance if exists or false if not.
132
public function getSiteRole($nb_site_role)
    {
        if (is_numeric($nb_role_id = nb_getMixedValue($nb_site_role, NABU_ROLE_FIELD_ID))) {
            $retval = $this->getSiteRoles()->getItem($nb_role_id);
        } else {
            $retval = false;
        }

        return $retval;
    }
1069773
function roles()
    {
        $groups = $this->attribute( 'groups' );
        $groups[] = $this->attribute( 'contentobject_id' );
        return eZRole::fetchByUser( $groups );
    }
288463
protected function getSite($siteId)
    {
        try {
            /** @var Site $site */
            $site = $this->getSiteRepo()->findOneBy(['siteId' => $siteId]);
        } catch (\Exception $e) {
            $site = null;
        }

        return $site;
    }
778429
public static function getRoleId($role)
    {
        $map = [
            self::ENUM_ROLE_ADMIN => self::ENUM_ROLE_ADMIN_ID,
            self::ENUM_ROLE_USER  => self::ENUM_ROLE_USER_ID,
        ];

        // do not check if key exist deliberately. If wrong role is given it will cause an error.
        return $map[$role];
    }
351309
public function getCTAs($force = false)
    {
        if ($this->nb_site_target_cta_list->isEmpty() || $force) {
            $this->nb_site_target_cta_list->clear();
            $this->nb_site_target_cta_list->merge(CNabuSiteTargetCTA::getSiteTargetCTAs($this));
            $translations = CNabuSiteTargetCTALanguage::getCTATranslationsForSiteTarget($this);
            if (is_array($translations) && count($translations) > 0) {
                foreach ($translations as $translation) {
                    $nb_site_target_cta = $this->nb_site_target_cta_list->getItem($translation->getSiteTargetCTAId());
                    if ($nb_site_target_cta instanceof CNabuSiteTargetCTA) {
                        $nb_site_target_cta->setTranslation($translation);
                    }
                }
            }
            $roles = CNabuSiteTargetCTARole::getCTARolesForSiteTarget($this);
            if (is_array($roles) && count($roles) > 0) {
                foreach ($roles as $role) {
                    $nb_site_target_cta = $this->nb_site_target_cta_list->getItem($role->getSiteTargetCTAId());
                    if ($nb_site_target_cta instanceof CNabuSiteTargetCTA) {
                        $nb_site_target_cta->addRole($role);
                    }
                }
            }
        }

        return $this->nb_site_target_cta_list;
    }
271745
public function getMentionRolesAttribute()
    {
        $roles = new Collection([], 'id');

        foreach ($this->channel->guild->roles as $role) {
            if (array_search($role->id, $this->attributes['mention_roles']) !== false) {
                $roles->push($role);
            }
        }

        return $roles;
    }
606971
public function getRole() {

		$roleTable			= CoreTables::getTableName( CoreTables::TABLE_ROLE );
		$siteTable			= CoreTables::getTableName( CoreTables::TABLE_SITE );
		$siteMemberTable	= CoreTables::getTableName( CoreTables::TABLE_SITE_MEMBER );

		// TODO: Check why it's not working without appending one() after recent Yii Upgrade
		return Role::find()
			->leftJoin( $siteMemberTable, "$siteMemberTable.roleId = $roleTable.id" )
			->leftJoin( $siteTable, "$siteTable.id = $siteMemberTable.siteId" )
			->where( "$siteMemberTable.userId=:id AND $siteTable.slug=:slug", [ ':id' => $this->id, ':slug' => Yii::$app->core->getSiteSlug() ] )
			->one();
	}
431970
protected function getRolesFromSite($site)
	{
		$newDataSet = new AnyDataset();
		$it = $this->user->getRolesIterator($site);
		while ($it->hasNext()) {
			$sr = $it->moveNext();
			$dataArray = $sr->getFieldArray($this->user->getRolesTable()->Role);
			if (sizeof($dataArray) > 0) {
				foreach ($dataArray as $roles) {
					$siteName = $sr->getField($this->user->getRolesTable()->Site);
					if ($siteName == "_all") {
						$siteName = $this->myWords->Value("TEXT_ALLSITES");
					}
					$newDataSet->appendRow();
					$newDataSet->addField($this->user->getRolesTable()->Site, $siteName);
					$newDataSet->addField($this->user->getRolesTable()->Role, $roles);
				}	
			}
		}
		return $newDataSet;
	}
510468
public function setDomainZoneId(int $nb_domain_zone_id) : CNabuDataObject
    {
        if ($nb_domain_zone_id === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$nb_domain_zone_id")
            );
        }
        $this->setValue('nb_domain_zone_id', $nb_domain_zone_id);
        
        return $this;
    }
745708
public function getRole() : ?string 
    {
        if ( ! $this->hasRole()) {
            $this->setRole($this->getDefaultRole());
        }
        return $this->role;
    }
712322
public function userIsContributor(AccountInterface $account, Site $site = null)
    {
        return $this->userHasRole($account, $site, Access::ROLE_CONTRIB);
    }
387789
public function setZone(string $zone = "B") : CNabuDataObject
    {
        if ($zone === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$zone")
            );
        }
        $this->setValue('nb_site_map_role_zone', $zone);
        
        return $this;
    }
57467
public function getRoles()
    {
        if (is_array($this->_roles)) {
            return $this->_roles;
        }
        if (!$this->id) {
            return $this->_roles = [];
        }
        return $this->_roles = \Cms\Orm\CmsAuthRoleQuery::joinedRoleByAuthId($this->id)
            ->orderAsc('name', 'cms_role')
            ->findPairs('cms_role_id', 'cms_role.name');
    }
1116771
protected function getListRole()
    {
        $id = $this->getParam(0);

        if (!isset($id)) {
            return $this->role->getList(array('limit' => $this->getLimit()));
        }

        if (empty($id) || !is_numeric($id)) {
            $this->errorAndExit($this->text('Invalid argument'));
        }

        $result = $this->role->get($id);

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        return array($result);
    }
1068661
public function listUsersWithRole(Site $site, $role = null, $limit = 100, $offset = 0)
    {
        $q = $this
            ->db
            ->select('ucms_site_access', 'sa')
            ->fields('sa')
            ->fields('u', ['name', 'mail', 'status'])
            ->condition('sa.site_id', $site->id)
        ;

        // @todo
        //  - should we add an added date in the access table?
        //  - return a cursor instead ? with a count() method for paging

        if ($role) {
            $q->condition('sa.role', $role);
        }

        $q->join('users', 'u', "u.uid = sa.uid");

        /* @var $q \SelectQuery */
        $r = $q
            ->range($offset, $limit)
            ->orderBy('sa.uid')
            ->execute()
        ;

        /* @var $r \PDOStatement */
        $r->setFetchMode(\PDO::FETCH_CLASS, SiteAccessRecord::class);

        return $r->fetchAll();
    }
837199
public function addRole(CNabuSiteMapRole $nb_role)
    {
        if ($nb_role->isValueNumeric(NABU_ROLE_FIELD_ID) || $nb_role->isValueGUID(NABU_ROLE_FIELD_ID)) {
            $nb_role->setSiteMap($this);
            $this->nb_site_map_role_list->addItem($nb_role);
        }

        return $nb_role;
    }
1035832
public function getRole()
    {
        $id = $this->getId();

        if (strpos($id, 'ROLE_') === 0) {
            return strtoupper($id);
        }

        return strtoupper('ROLE_' . $this->getId());
    }