00001 <?php
00022 class SUser extends SModel {
00023
00025 const ANONYMOUS = "anonymous";
00027 const ADMIN = "admin";
00028
00030 const NOT_ACTIVE = 0;
00031
00033 protected $id;
00035 protected $userName;
00037 protected $firstName;
00039 protected $lastName;
00041 protected $role = SUser::ANONYMOUS;
00043 protected $flash = array();
00045 protected $sessionData = array();
00047 protected $active;
00048
00049
00050
00051
00052
00053 public function doc() {
00054 return "An instance of this class represents a the most generic "
00055 . "user using a SWAT website - to be extended by projects.";
00056 }
00057
00061 public function getAttributes() {
00062 return array('id', 'userName', 'firstName', 'lastName', 'role', 'active');
00063 }
00064
00068 public function getUniqueAttributes() {
00069 return array('id', 'userName');
00070 }
00071
00072
00073
00074
00075
00084 public function setFlash($flash) {
00085 array_push($this->flash, $flash);
00086 }
00087
00093 public function flash($flash) {
00094 $this->setFlash($flash);
00095 }
00096
00104 public function getFlash() {
00105 return $this->flash;
00106 }
00107
00112 public function clearFlash() {
00113 $this->flash = array();
00114 }
00115
00126 public function setSessionData($key, $value) {
00127 $this->sessionData[$key] = $value;
00128 }
00129
00138 public function getSessionData($key) {
00139 if (!isset($this->sessionData[$key])){
00140 $this->setPrettyWarning("getSessionData", "Session data has no value for key $key");
00141 return null;
00142 }
00143 return $this->sessionData[$key];
00144 }
00145
00156 public function clearSessionData($key = null) {
00157 if ($key != null) {
00158 if (!isset($this->sessionData[$key])){
00159 $this->setPrettyWarning("getSessionData", "Session data has no value for key $key");
00160 return false;
00161 }
00162 unset($this->sessionData[$key]);
00163 }
00164 else {
00165 $this->sessionData = array();
00166 }
00167 }
00168
00175 public function issetSessionData($key) {
00176 return (isset($this->sessionData[$key]));
00177 }
00178
00186 public function getName() {
00187 return $this->getFirstName() . " " . $this->getLastName();
00188 }
00189
00195 public function reset() {
00196 parent::reset();
00197 $this->setRole(SUser::ANONYMOUS);
00198 }
00199
00205 public function isAnonymous() {
00206 return ($this->getRole() == SUser::ANONYMOUS);
00207 }
00208
00214 public function isAdmin() {
00215 return ($this->getRole() == SUser::ADMIN);
00216 }
00217 }
00218 ?>