00001 <?php
00002
00012 class SDRResource extends ModelBase {
00014 public static $ATTRIBUTES = array(
00015 'pk' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'cserdId' => array(
00021 'nullable' => false,
00022 'type' => 'int'
00023 ),
00024 'url' => array(
00025 'nullable' => false,
00026 'type' => 'string'
00027 ),
00028 'releaseFlag' => array(
00029 'nullable' => false,
00030 'type' => 'int',
00031 'default' => 0
00032 ),
00033 'primaryProject' => array(
00034 'nullable' => false,
00035 'commit' => SModel2::COMMIT_FIRST,
00036 'type' => 'int'
00037 ),
00038 'AverageReviewRating' => array(
00039 'type' => 'float',
00040 'default' => null
00041 ),
00042 'cache' => array(
00043 'type' => 'string'
00044 ),
00045 'created' => array(
00046 'nullable' => false,
00047 'commit' => SModel2::COMMIT_CHANGED,
00048 'type' => 'time',
00049 'default' => ''
00050 )
00051 );
00052
00062 public function __construct($constraints = null, $multi = false) {
00063 parent::__construct();
00064
00065 $this->registerAttributes(self::$ATTRIBUTES);
00066 $this->registerTableName('SDRResource');
00067 $this->registerPrimaryKey('pk', true);
00068
00069 if($constraints !== null)
00070 $this->populate($constraints, $multi);
00071 }
00072
00082 public static function getAttributesStatic() {
00083 return self::$ATTRIBUTES;
00084 }
00085
00091 public static function getTableNameStatic() {
00092 return 'SDRResource';
00093 }
00094
00106 public static function retrieve($constraints = array(), $checkOnly = false) {
00107 $list = self::getList($constraints, array(1), array(), $checkOnly);
00108 if(!$list || count($list) == 0)
00109 return $checkOnly ? false : null;
00110 else if($checkOnly)
00111 return $list > 0;
00112 else
00113 return $list[0];
00114 }
00115
00124 public static function exists($constraints = array()) {
00125 return self::retrieve($constraints, true);
00126 }
00127
00140 public static function retrieveMulti($constraints = array(), $checkOnly = false, $depth = 1) {
00141 $list = self::getListMulti($constraints, array(1), array(), $checkOnly, $depth);
00142 if(!$list || count($list) == 0)
00143 return $checkOnly ? false : null;
00144 else if($checkOnly)
00145 return $list > 0;
00146 else
00147 return $list[0];
00148 }
00149
00158 public static function existsMulti($constraints = array()) {
00159 return self::retrieveMulti($constraints, true);
00160 }
00161
00175 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00176 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'SDRResource', true);
00177 }
00178
00194 public static function getListMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00195 return parent::getListBaseMulti(self::getDBI(), $constraints, $limit, $order, $count,
00196 'SDRResource', true, $depth);
00197 }
00198
00199
00208 public function getParentPrimaryProject() {
00209 return SDRProject::retrieve(array('id' => $this->primaryProject));
00210 }
00211
00221 public function getParentPrimaryProjectMulti($depth = 1) {
00222 return SDRProject::retrieveMulti(array('Base.id' => $this->primaryProject), false, $depth);
00223 }
00224
00241 public function listSDRVersionCaches($constraints = array(), $limit = array(), $order = array(), $count = false) {
00242 return parent::getListBase(self::getDBI(),
00243 array_merge($constraints, array('cserdId' => $this->cserdId)),
00244 $limit, $order, $count, 'SDRVersionCache', true);
00245 }
00246
00265 public function listSDRVersionCachesMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00266 return parent::getListBaseMulti(self::getDBI(),
00267 array_merge($constraints, array('Base.cserdId' => $this->cserdId)),
00268 $limit, $order, $count, 'SDRVersionCache', true, $depth);
00269 }
00270
00290 public function addSDRVersionCache($version, $Title = '', $Description = '', $MetadataXMLCache = '', $created = '0000-00-00 00:00:00', $modified = '0000-00-00 00:00:00') {
00291 $obj = new SDRVersionCache();
00292
00293 $obj->cserdId = $this->cserdId;
00294 if(is_object($version))
00295 $obj->version = $version;
00296 else
00297 $obj->versionId = $version;
00298 if($Title != '')
00299 $obj->Title = $Title;
00300 if($Description != '')
00301 $obj->Description = $Description;
00302 if($MetadataXMLCache != '')
00303 $obj->MetadataXMLCache = $MetadataXMLCache;
00304 $obj->created = $created;
00305 $obj->modified = $modified;
00306
00307 if(!$obj->commit())
00308 return null;
00309
00310 return $obj;
00311 }
00312
00329 public function listSDRSearchWordCounts($constraints = array(), $limit = array(), $order = array(), $count = false) {
00330 return parent::getListBase(self::getDBI(),
00331 array_merge($constraints, array('cserdId' => $this->cserdId)),
00332 $limit, $order, $count, 'SDRSearchWordCount', true);
00333 }
00334
00353 public function listSDRSearchWordCountsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00354 return parent::getListBaseMulti(self::getDBI(),
00355 array_merge($constraints, array('Base.cserdId' => $this->cserdId)),
00356 $limit, $order, $count, 'SDRSearchWordCount', true, $depth);
00357 }
00358
00375 public function addSDRSearchWordCount($searchWord, $field, $count) {
00376 $obj = new SDRSearchWordCount();
00377
00378 if(is_object($searchWord))
00379 $obj->searchWord = $searchWord;
00380 else
00381 $obj->searchWordId = $searchWord;
00382 $obj->cserdId = $this->cserdId;
00383 if(is_object($field))
00384 $obj->field = $field;
00385 else
00386 $obj->fieldId = $field;
00387 $obj->count = $count;
00388
00389 if(!$obj->commit())
00390 return null;
00391
00392 return $obj;
00393 }
00394
00411 public function listSDRResourceProjects($constraints = array(), $limit = array(), $order = array(), $count = false) {
00412 return parent::getListBase(self::getDBI(),
00413 array_merge($constraints, array('cserdId' => $this->cserdId)),
00414 $limit, $order, $count, 'SDRResourceProject', true);
00415 }
00416
00435 public function listSDRResourceProjectsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00436 return parent::getListBaseMulti(self::getDBI(),
00437 array_merge($constraints, array('Base.cserdId' => $this->cserdId)),
00438 $limit, $order, $count, 'SDRResourceProject', true, $depth);
00439 }
00440
00455 public function addSDRResourceProject($project) {
00456 $obj = new SDRResourceProject();
00457
00458 $obj->cserdId = $this->cserdId;
00459 if(is_object($project))
00460 $obj->project = $project;
00461 else
00462 $obj->projectId = $project;
00463
00464 if(!$obj->commit())
00465 return null;
00466
00467 return $obj;
00468 }
00469
00486 public function listSDRVersions($constraints = array(), $limit = array(), $order = array(), $count = false) {
00487 return parent::getListBase(self::getDBI(),
00488 array_merge($constraints, array('cserdId' => $this->cserdId)),
00489 $limit, $order, $count, 'SDRVersion', true);
00490 }
00491
00510 public function listSDRVersionsMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00511 return parent::getListBaseMulti(self::getDBI(),
00512 array_merge($constraints, array('Base.cserdId' => $this->cserdId)),
00513 $limit, $order, $count, 'SDRVersion', true, $depth);
00514 }
00515
00536 public function addSDRVersion($parent = null, $createdAgent, $modifiedAgent, $state = '', $comment = '', $created = '', $modified = '0000-00-00 00:00:00') {
00537 $obj = new SDRVersion();
00538
00539 if($parent != '')
00540 $obj->parent = $parent;
00541 $obj->cserdId = $this->cserdId;
00542 if($state != '')
00543 $obj->state = $state;
00544 if($comment != '')
00545 $obj->comment = $comment;
00546 $obj->created = $created;
00547 if(is_object($createdAgent))
00548 $obj->createdAgent = $createdAgent;
00549 else
00550 $obj->createdAgentId = $createdAgent;
00551 $obj->modified = $modified;
00552 if(is_object($modifiedAgent))
00553 $obj->modifiedAgent = $modifiedAgent;
00554 else
00555 $obj->modifiedAgentId = $modifiedAgent;
00556
00557 if(!$obj->commit())
00558 return null;
00559
00560 return $obj;
00561 }
00562 }
00563
00564 ?>