public static function InitializeUser() { global $argv; if (QApplication::$Session->User) { QApplication::$User = QApplication::$Session->User; } elseif (is_array($argv) && array_search('--user', $argv) !== false) { QApplication::$User = NarroUser::LoadByUserId((int) $argv[array_search('--user', $argv) + 1]); } if (!QApplication::$User instanceof NarroUser) { QApplication::$User = NarroUser::LoadAnonymousUser(); QApplication::$Session->User = QApplication::$User; } if (!QApplication::$User instanceof NarroUser) { // @todo add handling here throw new Exception('Could not create an instance of NarroUser'); } }
} if (array_search('--project', $argv) !== false) { $intProjectId = $argv[array_search('--project', $argv) + 1]; } if (array_search('--template-lang', $argv) !== false) { $strSourceLanguage = $argv[array_search('--template-lang', $argv) + 1]; } else { $strSourceLanguage = NarroLanguage::SOURCE_LANGUAGE_CODE; } if (array_search('--translation-lang', $argv) !== false) { $strTargetLanguage = $argv[array_search('--translation-lang', $argv) + 1]; } if (array_search('--user', $argv) !== false) { $intUserId = $argv[array_search('--user', $argv) + 1]; } $objUser = NarroUser::LoadByUserId($intUserId); if (!$objUser instanceof NarroUser) { NarroLogger::LogInfo(sprintf('User id=%s does not exist in the database, will try to use the anonymous user.', $intUserId)); $objUser = NarroUser::LoadAnonymousUser(); if (!$objUser instanceof NarroUser) { NarroLogger::LogInfo(sprintf('The anonymous user id=%s does not exist in the database.', $intUserId)); return false; } } QApplication::$User = $objUser; $objProject = NarroProject::Load($intProjectId); if (!$objProject instanceof NarroProject) { NarroLogger::LogInfo(sprintf('Project with id=%s does not exist in the database.', $intProjectId)); return false; } $objLanguage = NarroLanguage::LoadByLanguageCode($strTargetLanguage);
public static function LoadAnonymousUser() { $objCache = new NarroCache('user', self::ANONYMOUS_USER_ID); $objUser = $objCache->GetData(); if (!$objUser instanceof NarroUser) { $objUser = NarroUser::LoadByUserId(self::ANONYMOUS_USER_ID); $arrUserRole = NarroUserRole::LoadArrayByUserId(self::ANONYMOUS_USER_ID); foreach ($arrUserRole as $objRole) { $arrRolePermission = NarroRolePermission::LoadArrayByRoleId($objRole->RoleId); foreach ($arrRolePermission as $objRolePermission) { $objUser->arrPermissions[$objRolePermission->Permission->PermissionName . '-' . $objRole->LanguageId . '-' . $objRole->ProjectId] = $objRolePermission; } } $objCache->SaveData($objUser); } return $objUser; }