00001 <?php
00002
00012 class AuthUserConfig extends AuthModelBase {
00014 public static $ATTRIBUTES = array(
00015 'userId' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_CHANGED,
00018 'type' => 'int',
00019 'foreign' => array('table' => 'User', 'on' => 'id', 'object' => 'user')
00020 ),
00021 'opt' => array(
00022 'nullable' => false,
00023 'commit' => SModel2::COMMIT_CHANGED,
00024 'type' => 'string'
00025 ),
00026 'page' => array(
00027 'nullable' => false,
00028 'commit' => SModel2::COMMIT_CHANGED,
00029 'type' => 'string'
00030 ),
00031 'value' => array(
00032 'nullable' => false,
00033 'type' => 'string'
00034 ),
00035 'project' => array(
00036 'nullable' => false,
00037 'commit' => SModel2::COMMIT_CHANGED,
00038 'type' => 'string',
00039 'default' => '*'
00040 ),
00041 'user' => array(
00042 'commit' => SModel2::COMMIT_FOREIGN,
00043 'type' => 'AuthUser'
00044 )
00045 );
00046
00056 public function __construct($constraints = null, $multi = false) {
00057 parent::__construct();
00058
00059 $this->registerAttributes(self::$ATTRIBUTES);
00060 $this->registerTableName('UserConfig');
00061 $this->registerPrimaryKey(array('project', 'userId', 'page', 'opt'), false);
00062
00063 if($constraints !== null)
00064 $this->populate($constraints, $multi);
00065 }
00066
00076 public static function getAttributesStatic() {
00077 return self::$ATTRIBUTES;
00078 }
00079
00085 public static function getTableNameStatic() {
00086 return 'UserConfig';
00087 }
00088
00100 public static function retrieve($constraints = array(), $checkOnly = false) {
00101 $list = self::getList($constraints, array(1), array(), $checkOnly);
00102 if(!$list || count($list) == 0)
00103 return $checkOnly ? false : null;
00104 else if($checkOnly)
00105 return $list > 0;
00106 else
00107 return $list[0];
00108 }
00109
00118 public static function exists($constraints = array()) {
00119 return self::retrieve($constraints, true);
00120 }
00121
00134 public static function retrieveMulti($constraints = array(), $checkOnly = false, $depth = 1) {
00135 $list = self::getListMulti($constraints, array(1), array(), $checkOnly, $depth);
00136 if(!$list || count($list) == 0)
00137 return $checkOnly ? false : null;
00138 else if($checkOnly)
00139 return $list > 0;
00140 else
00141 return $list[0];
00142 }
00143
00152 public static function existsMulti($constraints = array()) {
00153 return self::retrieveMulti($constraints, true);
00154 }
00155
00169 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00170 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'AuthUserConfig', true);
00171 }
00172
00188 public static function getListMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00189 return parent::getListBaseMulti(self::getDBI(), $constraints, $limit, $order, $count,
00190 'AuthUserConfig', true, $depth);
00191 }
00192
00193
00202 public function getParentUser() {
00203 return AuthUser::retrieve(array('User.id' => $this->userId));
00204 }
00205
00215 public function getParentUserMulti($depth = 1) {
00216 return AuthUser::retrieveMulti(array('Base.id' => $this->userId), $depth);
00217 }
00218 }
00219
00220 ?>