00001 <?php
00002
00012 class SDRVersionCache extends ModelBase {
00014 public static $ATTRIBUTES = array(
00015 'cserdId' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_FIRST,
00018 'type' => 'int',
00019 'foreign' => array('table' => 'SDRResource', 'on' => 'cserdId', 'object' => 'cserd')
00020 ),
00021 'versionId' => array(
00022 'nullable' => false,
00023 'commit' => SModel2::COMMIT_CHANGED,
00024 'type' => 'int',
00025 'foreign' => array('table' => 'SDRVersion', 'on' => 'id', 'object' => 'version')
00026 ),
00027 'Title' => array(
00028 'type' => 'string'
00029 ),
00030 'Description' => array(
00031 'type' => 'string'
00032 ),
00033 'MetadataXMLCache' => array(
00034 'type' => 'string'
00035 ),
00036 'created' => array(
00037 'nullable' => false,
00038 'type' => 'time',
00039 'default' => '0000-00-00 00:00:00'
00040 ),
00041 'modified' => array(
00042 'nullable' => false,
00043 'type' => 'time',
00044 'default' => '0000-00-00 00:00:00'
00045 ),
00046 'version' => array(
00047 'commit' => SModel2::COMMIT_FOREIGN,
00048 'type' => 'SDRVersion'
00049 ),
00050 'cserd' => array(
00051 'commit' => SModel2::COMMIT_FOREIGN,
00052 'type' => 'SDRResource'
00053 )
00054 );
00055
00065 public function __construct($constraints = null, $multi = false) {
00066 parent::__construct();
00067
00068 $this->registerAttributes(self::$ATTRIBUTES);
00069 $this->registerTableName('SDRVersionCache');
00070 $this->registerPrimaryKey('versionId');
00071
00072 if($constraints !== null)
00073 $this->populate($constraints, $multi);
00074 }
00075
00085 public static function getAttributesStatic() {
00086 return self::$ATTRIBUTES;
00087 }
00088
00094 public static function getTableNameStatic() {
00095 return 'SDRVersionCache';
00096 }
00097
00109 public static function retrieve($constraints = array(), $checkOnly = false) {
00110 $list = self::getList($constraints, array(1), array(), $checkOnly);
00111 if(!$list || count($list) == 0)
00112 return $checkOnly ? false : null;
00113 else if($checkOnly)
00114 return $list > 0;
00115 else
00116 return $list[0];
00117 }
00118
00127 public static function exists($constraints = array()) {
00128 return self::retrieve($constraints, true);
00129 }
00130
00143 public static function retrieveMulti($constraints = array(), $checkOnly = false, $depth = 1) {
00144 $list = self::getListMulti($constraints, array(1), array(), $checkOnly, $depth);
00145 if(!$list || count($list) == 0)
00146 return $checkOnly ? false : null;
00147 else if($checkOnly)
00148 return $list > 0;
00149 else
00150 return $list[0];
00151 }
00152
00161 public static function existsMulti($constraints = array()) {
00162 return self::retrieveMulti($constraints, true);
00163 }
00164
00178 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00179 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'SDRVersionCache', true);
00180 }
00181
00197 public static function getListMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00198 return parent::getListBaseMulti(self::getDBI(), $constraints, $limit, $order, $count,
00199 'SDRVersionCache', true, $depth);
00200 }
00201
00202
00211 public function getParentCserd() {
00212 return SDRResource::retrieve(array('cserdId' => $this->cserdId));
00213 }
00214
00224 public function getParentCserdMulti($depth = 1) {
00225 return SDRResource::retrieveMulti(array('Base.cserdId' => $this->cserdId), false, $depth);
00226 }
00227
00236 public function getParentVersion() {
00237 return SDRVersion::retrieve(array('id' => $this->versionId));
00238 }
00239
00249 public function getParentVersionMulti($depth = 1) {
00250 return SDRVersion::retrieveMulti(array('Base.id' => $this->versionId), false, $depth);
00251 }
00252
00269 public function listSDRResourceCaches($constraints = array(), $limit = array(), $order = array(), $count = false) {
00270 return parent::getListBase(self::getDBI(),
00271 array_merge($constraints, array('pendingVersionId' => $this->versionId)),
00272 $limit, $order, $count, 'SDRResourceCache', true);
00273 }
00274
00293 public function listSDRResourceCachesMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00294 return parent::getListBaseMulti(self::getDBI(),
00295 array_merge($constraints, array('Base.pendingVersionId' => $this->versionId)),
00296 $limit, $order, $count, 'SDRResourceCache', true, $depth);
00297 }
00298
00319 public function addSDRResourceCache($cserdId, $Url, $AverageReviewRating = null, $ShodorProject = null, $Hierarchy = null, $releaseFlag = '0', $created = '') {
00320 $obj = new SDRResourceCache();
00321
00322 $obj->cserdId = $cserdId;
00323 $obj->releaseFlag = $releaseFlag;
00324 $obj->Url = $Url;
00325 if($AverageReviewRating != '')
00326 $obj->AverageReviewRating = $AverageReviewRating;
00327 if($ShodorProject != '')
00328 $obj->ShodorProject = $ShodorProject;
00329 if($Hierarchy != '')
00330 $obj->Hierarchy = $Hierarchy;
00331 $obj->liveVersionId = $this->versionId;
00332 $obj->devVersionId = $this->versionId;
00333 $obj->pendingVersionId = $this->versionId;
00334 $obj->created = $created;
00335
00336 if(!$obj->commit())
00337 return null;
00338
00339 return $obj;
00340 }
00341 }
00342
00343 ?>