00001 <?php
00002
00012 class AuthUser extends AuthModelBase {
00014 public static $ATTRIBUTES = array(
00015 'id' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'ldapUserId' => array(
00021 'type' => 'int'
00022 ),
00023 'salt' => array(
00024 'nullable' => false,
00025 'type' => 'string'
00026 ),
00027 'password' => array(
00028 'nullable' => false,
00029 'type' => 'string'
00030 ),
00031 'username' => array(
00032 'nullable' => false,
00033 'type' => 'string'
00034 ),
00035 'hashTypeId' => array(
00036 'nullable' => false,
00037
00038 'type' => 'int',
00039
00040 ),
00041 'firstName' => array(
00042 'nullable' => false,
00043 'type' => 'string'
00044 ),
00045 'lastName' => array(
00046 'nullable' => false,
00047 'type' => 'string'
00048 ),
00049 'email' => array(
00050 'nullable' => false,
00051 'type' => 'string'
00052 ),
00053 'emailConfirmed' => array(
00054 'nullable' => false,
00055 'type' => 'int',
00056 'default' => false
00057 ),
00058 'hashType' => array(
00059 'commit' => SModel2::COMMIT_FOREIGN,
00060 'type' => 'AuthHashType'
00061 )
00062 );
00063
00073 public function __construct($constraints = null, $multi = false) {
00074 parent::__construct();
00075
00076 $this->registerAttributes(self::$ATTRIBUTES);
00077 $this->registerTableName('User');
00078 $this->registerPrimaryKey('id', true);
00079
00080 if($constraints !== null)
00081 $this->populate($constraints, $multi);
00082 }
00083
00093 public static function getAttributesStatic() {
00094 return self::$ATTRIBUTES;
00095 }
00096
00102 public static function getTableNameStatic() {
00103 return 'User';
00104 }
00105
00117 public static function retrieve($constraints = array(), $checkOnly = false) {
00118 $list = self::getList($constraints, array(1), array(), $checkOnly);
00119 if(!$list || count($list) == 0)
00120 return $checkOnly ? false : null;
00121 else if($checkOnly)
00122 return $list > 0;
00123 else
00124 return $list[0];
00125 }
00126
00135 public static function exists($constraints = array()) {
00136 return self::retrieve($constraints, true);
00137 }
00138
00151 public static function retrieveMulti($constraints = array(), $checkOnly = false, $depth = 1) {
00152 $list = self::getListMulti($constraints, array(1), array(), $checkOnly, $depth);
00153 if(!$list || count($list) == 0)
00154 return $checkOnly ? false : null;
00155 else if($checkOnly)
00156 return $list > 0;
00157 else
00158 return $list[0];
00159 }
00160
00169 public static function existsMulti($constraints = array()) {
00170 return self::retrieveMulti($constraints, true);
00171 }
00172
00186 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00187 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'AuthUser', true);
00188 }
00189
00205 public static function getListMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00206 return parent::getListBaseMulti(self::getDBI(), $constraints, $limit, $order, $count,
00207 'AuthUser', true, $depth);
00208 }
00209
00210
00219 public function getParentHashType() {
00220 return AuthHashType::retrieve(array('HashType.id' => $this->hashTypeId));
00221 }
00222
00232 public function getParentHashTypeMulti($depth = 1) {
00233 return AuthHashType::retrieveMulti(array('Base.id' => $this->hashTypeId), $depth);
00234 }
00235
00252 public function listConfirmEmails($constraints = array(), $limit = array(), $order = array(), $count = false) {
00253 return parent::getListBase(self::getDBI(),
00254 array_merge($constraints, array('ConfirmEmail.userId' => $this->id)),
00255 $limit, $order, $count, 'AuthConfirmEmail', true);
00256 }
00257
00276 public function listConfirmEmailsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00277 return parent::getListBaseMulti(self::getDBI(),
00278 array_merge($constraints, array('Base.userId' => $this->id)),
00279 $limit, $order, $count, 'AuthConfirmEmail', true, $depth);
00280 }
00281
00297 public function addConfirmEmail($hash, $requestTime = '') {
00298 $obj = new AuthConfirmEmail();
00299
00300 $obj->userId = $this->id;
00301 $obj->hash = $hash;
00302 if($requestTime != '')
00303 $obj->requestTime = $requestTime;
00304
00305 if(!$obj->commit())
00306 return null;
00307
00308 return $obj;
00309 }
00310
00327 public function listUserConfigs($constraints = array(), $limit = array(), $order = array(), $count = false) {
00328 return parent::getListBase(self::getDBI(),
00329 array_merge($constraints, array('UserConfig.userId' => $this->id)),
00330 $limit, $order, $count, 'AuthUserConfig', true);
00331 }
00332
00351 public function listUserConfigsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00352 return parent::getListBaseMulti(self::getDBI(),
00353 array_merge($constraints, array('Base.userId' => $this->id)),
00354 $limit, $order, $count, 'AuthUserConfig', true, $depth);
00355 }
00356
00374 public function addUserConfig($opt, $page, $value, $project = '*') {
00375 $obj = new AuthUserConfig();
00376
00377 $obj->userId = $this->id;
00378 $obj->opt = $opt;
00379 $obj->page = $page;
00380 $obj->value = $value;
00381 $obj->project = $project;
00382
00383 if(!$obj->commit())
00384 return null;
00385
00386 return $obj;
00387 }
00388
00405 public function listUserToGenGroups($constraints = array(), $limit = array(), $order = array(), $count = false) {
00406 return parent::getListBase(self::getDBI(),
00407 array_merge($constraints, array('UserToGenGroup.userId' => $this->id)),
00408 $limit, $order, $count, 'AuthUserToGenGroup', true);
00409 }
00410
00429 public function listUserToGenGroupsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00430 return parent::getListBaseMulti(self::getDBI(),
00431 array_merge($constraints, array('Base.userId' => $this->id)),
00432 $limit, $order, $count, 'AuthUserToGenGroup', true, $depth);
00433 }
00434
00449 public function addUserToGenGroup($genGroup) {
00450 $obj = new AuthUserToGenGroup();
00451
00452 $obj->userId = $this->id;
00453 if(is_object($genGroup))
00454 $obj->genGroup = $genGroup;
00455 else
00456 $obj->genGroupId = $genGroup;
00457
00458 if(!$obj->commit())
00459 return null;
00460
00461 return $obj;
00462 }
00463
00480 public function listResetPasswords($constraints = array(), $limit = array(), $order = array(), $count = false) {
00481 return parent::getListBase(self::getDBI(),
00482 array_merge($constraints, array('ResetPassword.userId' => $this->id)),
00483 $limit, $order, $count, 'AuthResetPassword', true);
00484 }
00485
00504 public function listResetPasswordsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00505 return parent::getListBaseMulti(self::getDBI(),
00506 array_merge($constraints, array('Base.userId' => $this->id)),
00507 $limit, $order, $count, 'AuthResetPassword', true, $depth);
00508 }
00509
00525 public function addResetPassword($hash, $requestTime = '') {
00526 $obj = new AuthResetPassword();
00527
00528 $obj->userId = $this->id;
00529 $obj->hash = $hash;
00530 if($requestTime != '')
00531 $obj->requestTime = $requestTime;
00532
00533 if(!$obj->commit())
00534 return null;
00535
00536 return $obj;
00537 }
00538
00555 public function listUserToProjects($constraints = array(), $limit = array(), $order = array(), $count = false) {
00556 return parent::getListBase(self::getDBI(),
00557 array_merge($constraints, array('UserToProject.userId' => $this->id)),
00558 $limit, $order, $count, 'AuthUserToProject', true);
00559 }
00560
00579 public function listUserToProjectsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00580 return parent::getListBaseMulti(self::getDBI(),
00581 array_merge($constraints, array('Base.userId' => $this->id)),
00582 $limit, $order, $count, 'AuthUserToProject', true, $depth);
00583 }
00584
00599 public function addUserToProject($project) {
00600 $obj = new AuthUserToProject();
00601
00602 $obj->userId = $this->id;
00603 if(is_object($project))
00604 $obj->project = $project;
00605 else
00606 $obj->projectId = $project;
00607
00608 if(!$obj->commit())
00609 return null;
00610
00611 return $obj;
00612 }
00613
00630 public function listUserToPermissions($constraints = array(), $limit = array(), $order = array(), $count = false) {
00631 return parent::getListBase(self::getDBI(),
00632 array_merge($constraints, array('UserToPermission.userId' => $this->id)),
00633 $limit, $order, $count, 'AuthUserToPermission', true);
00634 }
00635
00654 public function listUserToPermissionsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00655 return parent::getListBaseMulti(self::getDBI(),
00656 array_merge($constraints, array('Base.userId' => $this->id)),
00657 $limit, $order, $count, 'AuthUserToPermission', true, $depth);
00658 }
00659
00674 public function addUserToPermission($permission) {
00675 $obj = new AuthUserToPermission();
00676
00677 $obj->userId = $this->id;
00678 if(is_object($permission))
00679 $obj->permission = $permission;
00680 else
00681 $obj->permissionId = $permission;
00682
00683 if(!$obj->commit())
00684 return null;
00685
00686 return $obj;
00687 }
00688 }
00689
00690 ?>