/** Returns a list of available perspectives for the given user * @param Model\User $user * @return array */ public static function getAvailablePerspectives($user) { $currentConfigName = null; $masterConfig = self::getPerspectivesConfig()->toArray(); if ($user instanceof Model\User) { if ($user->isAdmin()) { $config = self::getPerspectivesConfig()->toArray(); } else { $config = []; $roleIds = $user->getRoles(); $userIds = [$user->getId()]; $userIds = array_merge($userIds, $roleIds); foreach ($userIds as $userId) { if (in_array($userId, $roleIds)) { $userOrRoleToCheck = Model\User\Role::getById($userId); } else { $userOrRoleToCheck = Model\User::getById($userId); } $perspectives = $userOrRoleToCheck->getPerspectives(); if ($perspectives) { foreach ($perspectives as $perspectiveName) { $masterDef = $masterConfig[$perspectiveName]; if ($masterDef) { $config[$perspectiveName] = $masterDef; } } } } if (!$config) { $config = self::getPerspectivesConfig()->toArray(); } } if ($config) { $tmpConfig = []; $validPerspectiveNames = array_keys($config); // sort the stuff foreach ($masterConfig as $masterConfigName => $masterConfiguration) { if (in_array($masterConfigName, $validPerspectiveNames)) { $tmpConfig[$masterConfigName] = $masterConfiguration; } } $config = $tmpConfig; } $currentConfigName = $user->getActivePerspective(); if ($config && !in_array($currentConfigName, array_keys($config))) { $currentConfigName = reset(array_keys($config)); } } else { $config = self::getPerspectivesConfig()->toArray(); } $result = []; foreach ($config as $configName => $configItem) { $item = ["name" => $configName, "icon" => isset($configItem["icon"]) ? $configItem["icon"] : null, "iconCls" => isset($configItem["iconCls"]) ? $configItem["iconCls"] : null]; if ($user) { $item["active"] = $configName == $currentConfigName; } $result[] = $item; } return $result; }
/** * @param Model\User $user * @return $this */ public function setUser(Model\User $user) { $this->user = $user; \Zend_Registry::set("pimcore_admin_user", $this->user); $this->setLanguage($this->user->getLanguage()); // update perspective settings $requestedPerspective = $this->getParam("perspective"); if ($requestedPerspective) { if ($requestedPerspective != $user->getActivePerspective()) { $existingPerspectives = array_keys(Config::getPerspectivesConfig()->toArray()); if (!in_array($requestedPerspective, $existingPerspectives)) { $requestedPerspective = null; } } } if (!$requestedPerspective) { $requestedPerspective = $user->getActivePerspective(); } //TODO check if perspective is still allowed if ($requestedPerspective != $user->getActivePerspective()) { $user->setActivePerspective($requestedPerspective); $user->save(); } return $this; }
/** * @param Model\User $user * @return $this */ public function setUser(Model\User $user) { $this->user = $user; \Zend_Registry::set("pimcore_admin_user", $this->user); $this->setLanguage($this->user->getLanguage()); // update perspective settings $requestedPerspective = $this->getParam("perspective"); if ($requestedPerspective) { if ($requestedPerspective != $user->getActivePerspective()) { $existingPerspectives = array_keys(Config::getPerspectivesConfig()->toArray()); if (!in_array($requestedPerspective, $existingPerspectives)) { $requestedPerspective = null; } } } if (!$requestedPerspective || !$user->isAllowed($requestedPerspective, "perspective")) { //choose active perspective or a first allowed $requestedPerspective = $user->isAllowed($user->getActivePerspective(), "perspective") ? $user->getActivePerspective() : $user->getFirstAllowedPerspective(); } if ($requestedPerspective != $user->getActivePerspective()) { $user->setActivePerspective($requestedPerspective); $user->save(); } return $this; }