00001 <?php
00002
00012 class SDRProject extends ModelBase {
00014 public static $ATTRIBUTES = array(
00015 'id' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'name' => array(
00021 'nullable' => false,
00022 'type' => 'string'
00023 )
00024 );
00025
00034 public function __construct($constraints = null) {
00035 parent::__construct();
00036
00037 $this->registerAttributes(self::$ATTRIBUTES);
00038 $this->registerTableName('SDRProject');
00039 $this->registerPrimaryKey('id', true);
00040
00041 if($constraints !== null)
00042 $this->populate($constraints);
00043 }
00044
00056 public static function retrieve($constraints = array(), $checkOnly = false) {
00057 $list = self::getList($constraints, array(1), array(), $checkOnly);
00058 if(!$list || count($list) == 0)
00059 return $checkOnly ? false : null;
00060 else if($checkOnly)
00061 return $list > 0;
00062 else
00063 return $list[0];
00064 }
00065
00074 public static function exists($constraints = array()) {
00075 return self::retrieve($constraints, true);
00076 }
00077
00091 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00092 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'SDRProject', true);
00093 }
00094
00104 public static function getAttributesStatic() {
00105 return self::$ATTRIBUTES;
00106 }
00107
00113 public static function getTableNameStatic() {
00114 return 'SDRProject';
00115 }
00116
00117
00134 public function listSDRResources($constraints = array(), $limit = array(), $order = array(), $count = false) {
00135 return parent::getListBase(self::getDBI(),
00136 array_merge($constraints, array('primaryProject' => $this->id)),
00137 $limit, $order, $count, 'SDRResource', true);
00138 }
00139
00158 public function listSDRResourcesMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00159 return parent::getListBaseMulti(self::getDBI(),
00160 array_merge($constraints, array('Base.primaryProject' => $this->id)),
00161 $limit, $order, $count, 'SDRResource', true, $depth);
00162 }
00163
00183 public function addSDRResource($cserdId, $url, $AverageReviewRating = null, $releaseFlag = '0', $cache = '', $created = '') {
00184 $obj = new SDRResource();
00185
00186 $obj->cserdId = $cserdId;
00187 $obj->url = $url;
00188 $obj->releaseFlag = $releaseFlag;
00189 $obj->primaryProject = $this->id;
00190 if($AverageReviewRating != '')
00191 $obj->AverageReviewRating = $AverageReviewRating;
00192 if($cache != '')
00193 $obj->cache = $cache;
00194 $obj->created = $created;
00195
00196 if(!$obj->commit())
00197 return null;
00198
00199 return $obj;
00200 }
00201
00218 public function listSDRResourceProjects($constraints = array(), $limit = array(), $order = array(), $count = false) {
00219 return parent::getListBase(self::getDBI(),
00220 array_merge($constraints, array('projectId' => $this->id)),
00221 $limit, $order, $count, 'SDRResourceProject', true);
00222 }
00223
00242 public function listSDRResourceProjectsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00243 return parent::getListBaseMulti(self::getDBI(),
00244 array_merge($constraints, array('Base.projectId' => $this->id)),
00245 $limit, $order, $count, 'SDRResourceProject', true, $depth);
00246 }
00247
00262 public function addSDRResourceProject($cserd) {
00263 $obj = new SDRResourceProject();
00264
00265 if(is_object($cserd))
00266 $obj->cserd = $cserd;
00267 else
00268 $obj->cserdId = $cserd;
00269 $obj->projectId = $this->id;
00270
00271 if(!$obj->commit())
00272 return null;
00273
00274 return $obj;
00275 }
00276
00293 public function listSDRProjectFields($constraints = array(), $limit = array(), $order = array(), $count = false) {
00294 return parent::getListBase(self::getDBI(),
00295 array_merge($constraints, array('projectId' => $this->id)),
00296 $limit, $order, $count, 'SDRProjectField', true);
00297 }
00298
00317 public function listSDRProjectFieldsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00318 return parent::getListBaseMulti(self::getDBI(),
00319 array_merge($constraints, array('Base.projectId' => $this->id)),
00320 $limit, $order, $count, 'SDRProjectField', true, $depth);
00321 }
00322
00339 public function addSDRProjectField($field, $indexOrder, $required = '') {
00340 $obj = new SDRProjectField();
00341
00342 $obj->projectId = $this->id;
00343 if(is_object($field))
00344 $obj->field = $field;
00345 else
00346 $obj->fieldId = $field;
00347 $obj->indexOrder = $indexOrder;
00348 if($required != '')
00349 $obj->required = $required;
00350
00351 if(!$obj->commit())
00352 return null;
00353
00354 return $obj;
00355 }
00356 }
00357
00358 ?>