00001 <?php
00002
00012 class CSERDuser extends CSERDModelBase {
00014 public static $ATTRIBUTES = array(
00015 'userId' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'userName' => array(
00021 'nullable' => false,
00022 'type' => 'string'
00023 ),
00024 'gecos' => array(
00025 'type' => 'string',
00026 'default' => null
00027 ),
00028 'firstName' => array(
00029 'type' => 'string',
00030 'default' => null
00031 ),
00032 'lastName' => array(
00033 'type' => 'string',
00034 'default' => null
00035 ),
00036 'password' => array(
00037 'type' => 'string',
00038 'default' => null
00039 ),
00040 'phone' => array(
00041 'type' => 'string',
00042 'default' => null
00043 ),
00044 'institution' => array(
00045 'type' => 'string',
00046 'default' => null
00047 ),
00048 'email' => array(
00049 'nullable' => false,
00050 'type' => 'string'
00051 ),
00052 'role' => array(
00053 'type' => 'string'
00054 ),
00055 'active' => array(
00056 'type' => 'int',
00057 'default' => null
00058 ),
00059 'created' => array(
00060 'nullable' => false,
00061 'commit' => SModel2::COMMIT_CHANGED,
00062 'type' => 'time',
00063 'default' => ''
00064 ),
00065 'accredited' => array(
00066 'nullable' => false,
00067 'type' => 'int',
00068 'default' => 0
00069 ),
00070 'solicited' => array(
00071 'type' => 'int',
00072 'default' => null
00073 ),
00074 'transaction' => array(
00075 'type' => 'string',
00076 'default' => null
00077 ),
00078 );
00079
00081 protected $sessionData = array();
00082
00083
00092 public function __construct($constraints = null) {
00093 parent::__construct();
00094
00095 $this->registerAttributes(self::$ATTRIBUTES);
00096 $this->registerTableName('user');
00097 $this->registerPrimaryKey('userId', true);
00098 if($constraints !== null)
00099 $this->populate($constraints);
00100 }
00101
00113 public static function retrieve($constraints = array(), $checkOnly = false) {
00114 $list = self::getList($constraints, array(1), array(), $checkOnly);
00115 if(!$list || count($list) == 0)
00116 return $checkOnly ? false : null;
00117 else if($checkOnly)
00118 return $list > 0;
00119 else
00120 return $list[0];
00121 }
00122
00131 public static function exists($constraints = array()) {
00132 return self::retrieve($constraints, true);
00133 }
00134
00148 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00149 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'CSERDuser', true);
00150 }
00151
00161 public static function getAttributesStatic() {
00162 return self::$ATTRIBUTES;
00163 }
00164
00170 public static function getTableNameStatic() {
00171 return 'user';
00172 }
00173
00174
00191 public function listuserLoginLogs($constraints = array(), $limit = array(), $order = array(), $count = false) {
00192 return parent::getListBase(self::getDBI(),
00193 array_merge($constraints, array('userId' => $this->userId)),
00194 $limit, $order, $count, 'CSERDuserLoginLog', true);
00195 }
00196
00215 public function listuserLoginLogsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00216 return parent::getListBaseMulti(self::getDBI(),
00217 array_merge($constraints, array('Base.userId' => $this->userId)),
00218 $limit, $order, $count, 'CSERDuserLoginLog', true, $depth);
00219 }
00220
00235 public function adduserLoginLog($loginTime = '') {
00236 $obj = new CSERDuserLoginLog();
00237
00238 $obj->userId = $this->userId;
00239 $obj->loginTime = $loginTime;
00240
00241 if(!$obj->commit())
00242 return null;
00243
00244 return $obj;
00245 }
00246
00263 public function listcomments($constraints = array(), $limit = array(), $order = array(), $count = false) {
00264 return parent::getListBase(self::getDBI(),
00265 array_merge($constraints, array('authorId' => $this->userId)),
00266 $limit, $order, $count, 'CSERDcomment', true);
00267 }
00268
00287 public function listcommentsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00288 return parent::getListBaseMulti(self::getDBI(),
00289 array_merge($constraints, array('Base.authorId' => $this->userId)),
00290 $limit, $order, $count, 'CSERDcomment', true, $depth);
00291 }
00292
00309 public function addcomment($review, $comment = '', $timestamp = '') {
00310 $obj = new CSERDcomment();
00311
00312 if($comment != '')
00313 $obj->comment = $comment;
00314 $obj->timestamp = $timestamp;
00315 if(is_object($review))
00316 $obj->review = $review;
00317 else
00318 $obj->reviewId = $review;
00319 $obj->ownerId = $this->userId;
00320 $obj->authorId = $this->userId;
00321
00322 if(!$obj->commit())
00323 return null;
00324
00325 return $obj;
00326 }
00327
00344 public function listreviews($constraints = array(), $limit = array(), $order = array(), $count = false) {
00345 return parent::getListBase(self::getDBI(),
00346 array_merge($constraints, array('ownerId' => $this->userId)),
00347 $limit, $order, $count, 'CSERDreview', true);
00348 }
00349
00368 public function listreviewsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00369 return parent::getListBaseMulti(self::getDBI(),
00370 array_merge($constraints, array('Base.ownerId' => $this->userId)),
00371 $limit, $order, $count, 'CSERDreview', true, $depth);
00372 }
00373
00396 public function addreview($active = null, $type, $cserdId = null, $solicited = null, $state = '', $created = '', $modified = '0000-00-00 00:00:00', $cache = '', $project = '') {
00397 $obj = new CSERDreview();
00398
00399 if($state != '')
00400 $obj->state = $state;
00401 if($active != '')
00402 $obj->active = $active;
00403 $obj->type = $type;
00404 if($cserdId != '')
00405 $obj->cserdId = $cserdId;
00406 $obj->authorId = $this->userId;
00407 $obj->ownerId = $this->userId;
00408 $obj->created = $created;
00409 $obj->modified = $modified;
00410 if($solicited != '')
00411 $obj->solicited = $solicited;
00412 if($cache != '')
00413 $obj->cache = $cache;
00414 if($project != '')
00415 $obj->project = $project;
00416
00417 if(!$obj->commit())
00418 return null;
00419
00420 return $obj;
00421 }
00422
00439 public function listuserDetails($constraints = array(), $limit = array(), $order = array(), $count = false) {
00440 return parent::getListBase(self::getDBI(),
00441 array_merge($constraints, array('userId' => $this->userId)),
00442 $limit, $order, $count, 'CSERDuserDetail', true);
00443 }
00444
00463 public function listuserDetailsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00464 return parent::getListBaseMulti(self::getDBI(),
00465 array_merge($constraints, array('Base.userId' => $this->userId)),
00466 $limit, $order, $count, 'CSERDuserDetail', true, $depth);
00467 }
00468
00484 public function adduserDetail($detail, $data = null) {
00485 $obj = new CSERDuserDetail();
00486
00487 if(is_object($detail))
00488 $obj->detail = $detail;
00489 else
00490 $obj->detailId = $detail;
00491 $obj->userId = $this->userId;
00492 if($data != '')
00493 $obj->data = $data;
00494
00495 if(!$obj->commit())
00496 return null;
00497
00498 return $obj;
00499 }
00500
00517 public function listuserPageviewLogs($constraints = array(), $limit = array(), $order = array(), $count = false) {
00518 return parent::getListBase(self::getDBI(),
00519 array_merge($constraints, array('userId' => $this->userId)),
00520 $limit, $order, $count, 'CSERDuserPageviewLog', true);
00521 }
00522
00541 public function listuserPageviewLogsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00542 return parent::getListBaseMulti(self::getDBI(),
00543 array_merge($constraints, array('Base.userId' => $this->userId)),
00544 $limit, $order, $count, 'CSERDuserPageviewLog', true, $depth);
00545 }
00546
00562 public function adduserPageviewLog($URL = null, $pageviewTime = '') {
00563 $obj = new CSERDuserPageviewLog();
00564
00565 $obj->userId = $this->userId;
00566 if($URL != '')
00567 $obj->URL = $URL;
00568 $obj->pageviewTime = $pageviewTime;
00569
00570 if(!$obj->commit())
00571 return null;
00572
00573 return $obj;
00574 }
00575
00576 public function reset(){
00577 $this->userId = null;
00578 $this->userName = null;
00579 $this->firstName = null;
00580 $this->lastName = null;
00581 $this->role = 'anonymous';
00582 return(true);
00583 }
00584
00585 public function isAnonymous(){
00586 return(!$this->attributeExists('role') || $this->role === 'anonymous');
00587 }
00588
00589 public function getFullName() {
00590 return $this->firstName . ' ' . $this->lastName;
00591 }
00592
00593
00594
00595 public function setSessionData($key, $value) {
00596 $this->sessionData[$key] = $value;
00597 }
00598
00607 public function getSessionData($key) {
00608 if (!isset($this->sessionData[$key])){
00609 $this->setPrettyWarning("getSessionData", "Session data has no value for key $key");
00610 return null;
00611 }
00612 return $this->sessionData[$key];
00613 }
00614
00625 public function clearSessionData($key = null) {
00626 if ($key != null) {
00627 if (!isset($this->sessionData[$key])){
00628 $this->setPrettyWarning("getSessionData", "Session data has no value for key $key");
00629 return false;
00630 }
00631 unset($this->sessionData[$key]);
00632 }
00633 else {
00634 $this->sessionData = array();
00635 }
00636 }
00637
00644 public function issetSessionData($key) {
00645 return (isset($this->sessionData[$key]));
00646 }
00647 }
00648 ?>