00001 <?php
00002
00012 class AuthPermission extends AuthModelBase {
00014 public static $ATTRIBUTES = array(
00015 'id' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'value' => array(
00021 'nullable' => false,
00022 'type' => 'int',
00023 'default' => false
00024 ),
00025 'name' => array(
00026 'type' => 'string'
00027 )
00028 );
00029
00038 public function __construct($constraints = null) {
00039 parent::__construct();
00040
00041 $this->registerAttributes(self::$ATTRIBUTES);
00042 $this->registerTableName('Permission');
00043 $this->registerPrimaryKey('id', true);
00044
00045 if($constraints !== null)
00046 $this->populate($constraints);
00047 }
00048
00060 public static function retrieve($constraints = array(), $checkOnly = false) {
00061 $list = self::getList($constraints, array(1), array(), $checkOnly);
00062 if(!$list || count($list) == 0)
00063 return $checkOnly ? false : null;
00064 else if($checkOnly)
00065 return $list > 0;
00066 else
00067 return $list[0];
00068 }
00069
00078 public static function exists($constraints = array()) {
00079 return self::retrieve($constraints, true);
00080 }
00081
00095 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00096 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'AuthPermission', true);
00097 }
00098
00108 public static function getAttributesStatic() {
00109 return self::$ATTRIBUTES;
00110 }
00111
00117 public static function getTableNameStatic() {
00118 return 'Permission';
00119 }
00120
00121
00138 public function listGenGroupToPermissions($constraints = array(), $limit = array(), $order = array(), $count = false) {
00139 return parent::getListBase(self::getDBI(),
00140 array_merge($constraints, array('GenGroupToPermission.permissionId' => $this->id)),
00141 $limit, $order, $count, 'AuthGenGroupToPermission', true);
00142 }
00143
00162 public function listGenGroupToPermissionsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00163 return parent::getListBaseMulti(self::getDBI(),
00164 array_merge($constraints, array('Base.permissionId' => $this->id)),
00165 $limit, $order, $count, 'AuthGenGroupToPermission', true, $depth);
00166 }
00167
00182 public function addGenGroupToPermission($genGroup) {
00183 $obj = new AuthGenGroupToPermission();
00184
00185 if(is_object($genGroup))
00186 $obj->genGroup = $genGroup;
00187 else
00188 $obj->genGroupId = $genGroup;
00189 $obj->permissionId = $this->id;
00190
00191 if(!$obj->commit())
00192 return null;
00193
00194 return $obj;
00195 }
00196
00213 public function listUserToPermissions($constraints = array(), $limit = array(), $order = array(), $count = false) {
00214 return parent::getListBase(self::getDBI(),
00215 array_merge($constraints, array('UserToPermission.permissionId' => $this->id)),
00216 $limit, $order, $count, 'AuthUserToPermission', true);
00217 }
00218
00237 public function listUserToPermissionsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00238 return parent::getListBaseMulti(self::getDBI(),
00239 array_merge($constraints, array('Base.permissionId' => $this->id)),
00240 $limit, $order, $count, 'AuthUserToPermission', true, $depth);
00241 }
00242
00257 public function addUserToPermission($user) {
00258 $obj = new AuthUserToPermission();
00259
00260 if(is_object($user))
00261 $obj->user = $user;
00262 else
00263 $obj->userId = $user;
00264 $obj->permissionId = $this->id;
00265
00266 if(!$obj->commit())
00267 return null;
00268
00269 return $obj;
00270 }
00271 }
00272
00273 ?>