00001 <?php
00009 class SWATSession extends SObject {
00010
00011 protected $globalUser; # represents the currently logged-in user
00012 protected $projectUsers = array();
00013 protected $transaction; # represents the transaction object
00014 protected $swat;
00015 protected $data;
00016 protected $curProject = null;
00017 protected $curProjectUser = null;
00018
00019
00020
00021
00022
00030 public function __construct($swat) {
00031 # Retain a link to the parent SWAT object
00032 $this->swat = $swat;
00033
00034 # Attempt to create and store the user object
00035 $this->globalUser = $this->createGlobalUser();
00036 if ($this->globalUser == null || $this->globalUser->hasError()) {
00037 $this->setPrettyError("construct", "Could not create user object");
00038 return false;
00039 }
00040
00041 # Attempt to create and store the transaction object
00042 $this->getTransaction();
00043 if ($this->transaction == null || $this->transaction->hasError()) {
00044 $this->setPrettyError("construct", "Could not create transaction object");
00045 return false;
00046 }
00047
00048 return true;
00049 }
00050
00051
00052
00053
00054
00063 protected function createGlobalUser() {
00064 $userClass = SConfig::getOption('swat.globalUserClass');
00065 return new $userClass();
00066 }
00067
00072 public function getGlobalUser() {
00073 return $this->globalUser;
00074 }
00075
00076
00077
00078
00079
00086 public function getProjectUser($project = "") {
00087 if ($project == "") $project = SConfig::getOption('swat.currentProject');
00088
00089 # if the project has changed since this function was last called,
00090 # reset the cached project user.
00091 if ($this->curProject != $project) {
00092 $this->curProject = $project;
00093 $this->curProjectUser = null;
00094 }
00095
00096 # if no user is cached, cache a user in the local variable
00097 if ($this->curProjectUser == null) {
00098 if (isset($this->projectUsers[$project])){
00099 $this->curProjectUser = unserialize($this->projectUsers[$project]);
00100 }
00101 }
00102 return $this->curProjectUser;
00103 }
00104
00110 public function setProjectUser($user, $project = "") {
00111 if ($project == "") $project = SConfig::getOption('swat.currentProject');
00112 $this->curProjectUser = $user;
00113 $this->projectUsers[$project] = serialize($user);
00114 }
00115
00119 public function sync() {
00120 $this->projectUsers[$this->curProject] = serialize($this->curProjectUser);
00121 $this->curProjectUser = null;
00122 $this->curProject = null;
00123 }
00124
00125
00126
00127
00128
00133 public function getTransaction() {
00134 if ($this->transaction == null) { $this->transaction = new STransaction(); }
00135 return $this->transaction;
00136 }
00137
00138
00139
00140
00141
00146 public function getSWAT() {
00147 return $this->swat;
00148 }
00149
00154 public function setSWAT($swat) {
00155 $this->swat = $swat;
00156 }
00157
00158
00159
00160
00161
00167 public function addData($name, $data) {
00168 $this->data[$name] = $data;
00169 }
00170
00176 public function getData($name) {
00177 if(isset($this->data[$name]))
00178 return $this->data[$name];
00179 else
00180 return null;
00181 }
00182 }
00183
00184 ?>