00001 <?php
00002
00012 class AuthProject extends AuthModelBase {
00013 const SHODOR_INTERNAL = 'Shodor Internal';
00014 const CSERD = 'CSERD';
00015 const NCSI = 'NCSI';
00016 const SHERPA = 'SHERPA';
00018 public static $ATTRIBUTES = array(
00019 'name' => array(
00020 'nullable' => false,
00021 'type' => 'string'
00022 ),
00023 'id' => array(
00024 'nullable' => false,
00025 'commit' => SModel2::COMMIT_NEVER,
00026 'type' => 'int'
00027 )
00028 );
00029
00038 public function __construct($constraints = null) {
00039 parent::__construct();
00040
00041 $this->registerAttributes(self::$ATTRIBUTES);
00042 $this->registerTableName('Project');
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, 'AuthProject', true);
00097 }
00098
00108 public static function getAttributesStatic() {
00109 return self::$ATTRIBUTES;
00110 }
00111
00117 public static function getTableNameStatic() {
00118 return 'Project';
00119 }
00120
00121
00138 public function listUserToProjects($constraints = array(), $limit = array(), $order = array(), $count = false) {
00139 return parent::getListBase(self::getDBI(),
00140 array_merge($constraints, array('UserToProject.projectId' => $this->id)),
00141 $limit, $order, $count, 'AuthUserToProject', true);
00142 }
00143
00162 public function listUserToProjectsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00163 return parent::getListBaseMulti(self::getDBI(),
00164 array_merge($constraints, array('Base.projectId' => $this->id)),
00165 $limit, $order, $count, 'AuthUserToProject', true, $depth);
00166 }
00167
00182 public function addUserToProject($user) {
00183 $obj = new AuthUserToProject();
00184
00185 if(is_object($user))
00186 $obj->user = $user;
00187 else
00188 $obj->userId = $user;
00189 $obj->projectId = $this->id;
00190
00191 if(!$obj->commit())
00192 return null;
00193
00194 return $obj;
00195 }
00196 }
00197
00198 ?>