Gets the Admin User instance of this server instance.
@param bool $force If true forces to reload instance from the database storage.
@return CNabuUser Retuns a User instance if a user is assigned or null if none.
552344
public function getAdminUser($force = false) {

        if ($this->nb_admin_user === null || $force) {
            $this->nb_admin_user = null;
            if ($this->isValueNumeric('nb_server_admin_user_id')) {
                $nb_user = new CNabuUser($this->getAdminUserId());
                if ($nb_user->isFetched()) {
                    $this->nb_admin_user = $nb_user;
                }
            }
        }

        return $this->nb_admin_user;
    }
1226702
public function getMediotecas($force = false)
    {
        if ($this->nb_medioteca_list->isEmpty() || $force) {
            $this->nb_medioteca_list->clear();
            $this->nb_medioteca_list->merge(CNabuMedioteca::getAllMediotecas($this));
        }

        return $this->nb_medioteca_list->getItems();
    }
70760
public function getUser($user) {
            if ($user instanceof TokenInterface) {
                $id = $user->getService();
            } else if (is_array($user)) {
                $id = $user['service'];
            } else {
                $id = $user;
            }

            if (!isset($this->users[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->users[$id])) {
                $this->users[$id] = $this->container->get($this->users[$id]);
            }

            if ($user instanceof TokenInterface) {
                $this->users[$id]->setTokenData($user);
            } else if (is_array($user)) {
                $this->users[$id]->setOptions($user);
            }

            return $this->users[$id];
        }
520452
public function getIContact($force = false)
    {
        if ($this->nb_icontact === null || $force) {
            $this->nb_icontact = null;
            if ($this instanceof CNabuDataObject &&
                !$this->isBuiltIn()
                && $this->isValueNumeric(NABU_ICONTACT_FIELD_ID)
            ) {
                $nb_icontact = new CNabuIContact($this->getValue(NABU_ICONTACT_FIELD_ID));
                if ($nb_icontact->isFetched()) {
                    $this->nb_icontact = $nb_icontact;
                }
            }
        }

        return $this->nb_icontact;
    }
458641
public static function createAdminRole($force = false)
    {
        if(!$force) {
            if(Permission::exists('global', 'admin')) {
                return false;
            }
        }

        return self::createRole(
            'Admin', true, [[
            'app' => 'global',
            'key' => 'admin'
            ]]
        );
    }
409764
public function getActiveServices($force = false)
    {
        if ($this->nb_messaging_service_list === null) {
            $this->nb_messaging_service_list = new CNabuMessagingServiceList();
        }

        if ($this->nb_messaging_service_list->isEmpty() || $force) {
            $this->nb_messaging_service_list->clear();
            $this->nb_messaging_service_list->merge(CNabuMessagingService::getActiveMessagingServices($this));
            $this->nb_messaging_service_list->iterate(function($key, CNabuMessagingService $nb_service) {
                $nb_service->setMessaging($this);
                return true;
            });
        }

        return $this->nb_messaging_service_list;
    }
180984
public function canDo($permission, $force = false)
    {
        if (! is_null($this->getUser())) {
            return $this->getUser()->canDo($permission, $force);
        }

        return false;
    }
1283033
function getAllRoles($force = false)
    {
        if ($force == false and ! is_null($this->_cache_perms)) {
            return $this->_cache_perms;
        }
        $this->_cache_perms = array();
        // load group permissions
        $this->_cache_perms = (array) $this->get_roles_list();
        return $this->_cache_perms;
    }
86671
public function getAttachments(bool $force = false) : CNabuIContactProspectAttachmentList
    {
        if ($this->nb_attachment_list->isEmpty() || $force) {
            $this->nb_attachment_list->clear();
            $this->nb_attachment_list->merge(CNabuIContactProspectAttachment::getAttachmentsForProspect($this));
        }

        return $this->nb_attachment_list;
    }
173422
public function get()
    {
        if ($this->adminUser instanceof AdminUserInterface) {
            return $this->adminUser;
        }

        $token = $this->tokenStorage instanceof TokenStorageInterface
            ? $this->tokenStorage->getToken()
            : null;

        $this->adminUser = ($token instanceof UsernamePasswordToken)
            ? $token->getUser()
            : $this
                ->adminUserFactory
                ->create();

        return $this->adminUser;
    }
706172
function getManager($force=false)
    {
        // Extract the YadisServiceManager for this object's URL and
        // suffix from the session.

        $manager_str = $this->session->get($this->getSessionKey());
        /** @var Auth_Yadis_Manager $manager */
        $manager = null;

        if ($manager_str !== null) {
            $loader = new Auth_Yadis_ManagerLoader();
            $manager = $loader->fromSession(unserialize($manager_str));
        }

        if ($manager && ($manager->forURL($this->url) || $force)) {
            return $manager;
        }
        return null;
    }
669586
public function info($force = null) {
		if (isset ( $force )) {
			$displayInfoAsString = ($force === true) ? true : false;
		} else {
			$displayInfoAsString = $this->_displayInfoAsString ();
		}
		return $this->loadView ( $this->_getFiles ()->getViewInfo (), [ "connected" => USession::get ( $this->_getUserSessionKey () ),"authURL" => $this->getBaseUrl (),"bodySelector" => $this->_getBodySelector () ], $displayInfoAsString );
	}
1194647
public function getNaturalLanguages(bool $force = false) : CNabuLanguageList
    {
        $nb_natural = new CNabuLanguageList();
        $this->getLanguages($force)->iterate(function ($key, CNabuLanguage $nb_language) use ($nb_natural) {
            if ($nb_language->isNaturalLanguage()) {
                $nb_natural->addItem($nb_language);
            }
            return true;
        });

        return $nb_natural;
    }
1135804
public function read($force = false)
	{
		// initialize the session
		$this->data = array();
		$this->keys = array();
		$this->flash = array();

		// get the session cookie
		$payload = $this->_get_cookie();

		// validate it
		if ($force)
		{
			// a forced session reset
		}
		elseif ($payload === false)
		{
			// no cookie found
		}
		elseif ( ! isset($payload[0]) or ! is_array($payload[0]))
		{
			logger('DEBUG', 'Error: not a valid cookie payload!');
		}
		elseif ($payload[0]['updated'] + $this->config['expiration_time'] <= $this->time->get_timestamp())
		{
			logger('DEBUG', 'Error: session id has expired!');
		}
		elseif ($this->config['match_ip'] and $payload[0]['ip_hash'] !== md5(\Input::ip().\Input::real_ip()))
		{
			logger('DEBUG', 'Error: IP address in the session doesn\'t match this requests source IP!');
		}
		elseif ($this->config['match_ua'] and $payload[0]['user_agent'] !== \Input::user_agent())
		{
			logger('DEBUG', 'Error: User agent in the session doesn\'t match the browsers user agent string!');
		}
		else
		{
			// session is valid, retrieve the payload
			if (isset($payload[0]) and is_array($payload[0])) $this->keys  = $payload[0];
			if (isset($payload[1]) and is_array($payload[1])) $this->data  = $payload[1];
			if (isset($payload[2]) and is_array($payload[2])) $this->flash = $payload[2];
		}

		return parent::read();
	}
718245
public function squash($force = false) {
        if ($this->cache !== null && !$force) return $this->cache;
        if ($this->parent) {
            return $this->cache = array_merge($this->parent->squash($force), $this->data);
        } else {
            return $this->cache = $this->data;
        }
    }
337838
private function getEntityManager($force = false)
    {
        /** @var EntityManager $em */
        $em = $this->doctrine->getManagerForClass($this->entityClass);
        if ($force) {
            if (!$em->isOpen()) {
                $this->resetEntityManager();
                $em = $this->doctrine->getManagerForClass($this->entityClass);
            } else {
                /**
                 * ensure that the transaction is fully rolled back
                 * in case if a nested transaction is rolled back but the entity manager is not closed
                 * this may happen if the EntityManager::rollback() method is called
                 * without the call of EntityManager::close() method
                 * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html#exception-handling
                 */
                $connection = $em->getConnection();
                if ($connection->getTransactionNestingLevel() > 0 && $connection->isRollbackOnly()) {
                    while ($connection->getTransactionNestingLevel() > 0) {
                        $connection->rollBack();
                    }
                }
            }
        }

        return $em;
    }
444289
public static function createEditorRole($force = false)
    {
        if(!$force) {
            if(Permission::exists('global', 'editor')) {
                return false;
            }
        }

        return self::createRole(
            'Editor', true, [[
            'app' => 'global',
            'key' => 'editor'
            ]]
        );
    }