How to extend user session variable?

You can extend user session variable (=preference) of application by creating class that extend 'CIISONLINE_UserSession' class. Prefix your class name with '0' (zero) and must has suffix with '.class.php' Place your new class under /System/Session/User.

You must register this session variable to the system as shown in the first statement of the example below.

Here is '0BackgroundImage.class.php' user session file for your example:


<?php

CIISONLINE_System::RegisterUserSession("BackgroundImage");

class BackgroundImage extends CIISONLINE_UserSession {

static function GetCode() {
}

static function GetDefault() {
return GetSystemConfig("sBackgroundPageFileName");
}

static function SetToDefault($valid=false) {
self::SetValue(self::GetDefault(),$valid);
}

static function SetValue($Value,$valid=false) {
SetSessionValue ("BackgroundImage_CurrentUser", $Value);
if ($valid) {
self::MakeValid();
}
}

static function GetValue() {
if (!GetSessionValue("Is__BackgroundImage_CurrentUser__Valid")) {
SetSessionValue ("BackgroundImage_CurrentUser",
(string)(GetUserConfigWithDefault(GetSessionValue("AccessAsUserID_CurrentUser"),
GetUserConfigPreferenceConst("iUserConfigBackgroundFile"), self::GetDefault())));
SetSessionValue ("Is__BackgroundImage_CurrentUser__Valid", true);
}
return GetSessionValue("BackgroundImage_CurrentUser");
}

static function Invalidate() {
SetSessionValue ("Is__BackgroundImage_CurrentUser__Valid", false);
}

static function MakeValid() {
SetSessionValue ("Is__BackgroundImage_CurrentUser__Valid", true);
}

static function IsValid() {
return GetSessionValue("Is__BackgroundImage_CurrentUser__Valid");
}
}


?>



You will access the value of user session variable like below:

$var = GetCurrentUserConfig('BackgroundImage');

You can set current session like below:

SetCurrentUserConfig('BackgroundImage','<\<a value>');

No comments:

Post a Comment

CommentLuv Enabled

Followers