00001 <?php
00017 class CSERDUser extends SUser {
00018
00019 # DB Values
00020 protected $userId = "";
00021 protected $userName = null;
00022 protected $firstName = null;
00023 protected $lastName = null;
00024 protected $email = null;
00025 protected $password = null;
00026 protected $phone = null;
00027 protected $institution = null;
00028 protected $role = "anonymous";
00029 protected $active = 0;
00030 protected $solicited = 0;
00031 protected $created = null;
00032
00033 # Retained objects
00034 protected $userDetail = null;
00035
00036 # Constants
00037 # - Status
00038 const NOT_ACTIVE = 0;
00039 const ACTIVE = 1;
00040 const NOT_ACCREDITED = 2;
00041 const ACCREDITED = 3;
00042 # - Role
00043 const REVIEWER = "reviewer";
00044 const EDITOR = "editor";
00045
00046
00047
00048
00049
00057 public function doc() {
00058 return "Represents a CSERD project user.";
00059 }
00060
00068 public function getAttributes() {
00069 return array('userId', 'userName', 'firstName', 'lastName', 'email', 'password',
00070 'phone', 'institution', 'role', 'active', 'solicited', 'created');
00071 }
00072
00080 public function getUniqueAttributes() {
00081 return array('userId', 'userName');
00082 }
00083
00091 public function getEntity() {
00092 return 'user';
00093 }
00094
00102 public function getId() { return $this->getUserId(); }
00111 public function setId($id) { return $this->setUserId($id); }
00112
00113
00114
00115
00116
00125 public function setEmail($a) {
00126 if (!preg_match("/.*\@.*\./", $a) && $a != null) {
00127 $this->setError("Email address '" . $a . "' does not conform to valid specification.");
00128 return (false);
00129 }
00130 $this->email = $a;
00131 }
00132
00141 public function setActive($active = "") {
00142 if ($active == ""){
00143 $this->active = CSERDUser::ACTIVE;
00144 } else {
00145 $this->active = $active;
00146 }
00147 }
00148
00156 public function setAccredited() {
00157 $this->active = CSERDUser::ACCREDITED;
00158 }
00159
00167 public function setNotAccredited() {
00168 $this->active = CSERDUser::NOT_ACCREDITED;
00169 }
00170
00171
00172
00173
00174
00182 public function isEditor() {
00183 return ($this->getRole() == CSERDUser::EDITOR);
00184 }
00185
00193 public function isReviewer() {
00194 return ($this->getRole() == CSERDUser::REVIEWER);
00195 }
00196
00204 public function hasEditor() {
00205 return ($this->isEditor() || $this->isAdmin());
00206 }
00207
00208
00209
00210
00211
00219 public function isActive() {
00220 if ($this->getActive() >= CSERDUser::ACTIVE) return (true);
00221 else return (false);
00222 }
00223
00231 public function isAccredited() {
00232 if ($this->getActive() == CSERDUser::ACCREDITED) return (true);
00233 else return (false);
00234 }
00235
00243 public function reset() {
00244 parent::reset();
00245 # Clear all of the user parameters
00246 $this->setId(null);
00247 $this->setUserName(null);
00248 $this->setFirstName(null);
00249 $this->setLastName(null);
00250 $this->setEmail(null);
00251 $this->setPassword(null);
00252 $this->setInstitution(null);
00253 $this->setPhone(null);
00254 $this->setActive(0);
00255 return (true);
00256 }
00257
00258 public function getFullName() {
00259 return $this->getFirstName() . ' ' . $this->getLastName();
00260 }
00261
00270 public static function exists($constraints = array()) {
00271 return self::retrieve($constraints, true);
00272 }
00273
00285 public static function retrieve($constraints = array(), $checkOnly = false) {
00286 $list = self::getList($constraints, array(1), array(), $checkOnly);
00287 if(!$list || count($list) == 0)
00288 return $checkOnly ? false : null;
00289 else if($checkOnly)
00290 return $list > 0;
00291 else
00292 return $list[0];
00293 }
00294 }
00295 ?>