My FIU Curriculum Class Reference. Yii Framework

# VersionedEntity

Package | application
Inheritance | abstract class VersionedEntity
Subclasses | Course, CoursePrefix, Dgu, Group, Major, Set, Track
Source Code |

Description of VersionedEntity

## Protected Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
catalog |  |  | VersionedEntity
catalog_id |  |  | VersionedEntity
entity |  |  | VersionedEntity
entityType |  |  | VersionedEntity
his_tableName |  |  | VersionedEntity

## Public Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
createNewEntity() |  | VersionedEntity
deleteOrRevertEntity() |  | VersionedEntity
getArrEntity() |  | VersionedEntity
getEntity() |  | VersionedEntity
getHistoryEntities() |  | VersionedEntity
getHistoryEntity() |  | VersionedEntity
updateData() |  | VersionedEntity

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
VersionedEntity() |  | VersionedEntity
createNewHistoryRecord() |  | VersionedEntity
findEntity() |  | VersionedEntity
getMostResentActivatedVersionForEntity() |  | VersionedEntity
updateHistoryRecord() |  | VersionedEntity

## Property Details

catalog property
protected $catalog;

catalog_id property
protected $catalog_id;

entity property
protected $entity;

entityType property
protected $entityType;

his_tableName property
protected $his_tableName;

## Method Details

VersionedEntity() method

protected void VersionedEntity($entityId, $catalogId)
$entityId |  |
$catalogId |  |

Source Code: (show)
`protected function VersionedEntity($entityId, $catalogId){
$this->catalog_id = $catalogId;
$this->catalog = Catalog::model()->findByPk($catalogId);
//initialize
$this->init($entityId);
}`

createNewEntity() method

public static void createNewEntity($currModel, $hisModel)
$currModel |  |
$hisModel |  |

Source Code: (show)
`public static function createNewEntity($currModel, $hisModel){
if(static::entityExistsCurr($currModel))
throw new Exception('Entity exist, dont override it. use different id');
// create base
if($currModel->save()){
$hisModel->identifier_id = $currModel->id;
if($hisModel->save()){
return $currModel->id;
}
else{
throw new Exception("cannot create hisModel for identifier: ".$currModel->id);
}
}
else{
throw new Exception("cannot create currModel");
}
}`

createNewHistoryRecord() method

abstract protected void createNewHistoryRecord()

Source Code: (show)
`protected abstract function createNewHistoryRecord();`

deleteOrRevertEntity() method

public void deleteOrRevertEntity()

Source Code: (show)
`public function deleteOrRevertEntity(){
$hisEntity = $this->getHistoryEntity();
if(!Yii::app()->getModule('catalog')->isCatalogActivated($hisEntity->catalog_id)){
if($this->getHisCount() <= 1)
return $this->deleteEntity();
else
return $this->revertEntity();
}
else
return false;
}`

findEntity() method

abstract protected void findEntity($entityId)
$entityId |  |

Source Code: (show)
`protected abstract function findEntity($entityId);`

getArrEntity() method

public void getArrEntity()

Source Code: (show)
`public function getArrEntity(){
$entityIdentifier = $this->entity;
$entityData = $this->getHistoryEntity();
$arrEntity = array_merge( array('type'=>$this->entityType),
$entityIdentifier->attributes,
$entityData->attributes);
return $arrEntity;
}`

getEntity() method

public void getEntity()

Source Code: (show)
`public function getEntity(){
return $this->entity;
}`

getHistoryEntities() method

abstract public void getHistoryEntities()

Source Code: (show)
`public abstract function getHistoryEntities();`

getHistoryEntity() method

abstract public void getHistoryEntity()

Source Code: (show)
`public abstract function getHistoryEntity();`

getMostResentActivatedVersionForEntity() method

protected void getMostResentActivatedVersionForEntity($entityId)
$entityId |  |

Source Code: (show)
`protected function getMostResentActivatedVersionForEntity($entityId){
$sql = 'SELECT DISTINCT id FROM catalog WHERE '.
'activated=1 AND id IN'.
'(SELECT catalog_id FROM '.$this->his_tableName.' WHERE '.
'identifier_id= :identifier)'.
' ORDER BY startingDate;';
$result = Yii::app()->db->createCommand($sql)->query(
array(':identifier'=>$entityId));
return $result->read();
}`

updateData() method

public void updateData()

Source Code: (show)
`public function updateData(){
//if activated save directly
if ($this->catalog->activated == 1){
echo "<h2> catalog activated-></h2>";
$this->updateHistoryRecord();
}
else{
echo "<h2> catalog NOT activated-></h2>";
if($this->doesEntityBelongsToCurrentVersion()){
echo "<h2> Update</h2>";
$this->updateHistoryRecord();
}
else {echo "<h2> New</h2>";
$this->createNewHistoryRecord();
}
}
}`

updateHistoryRecord() method

abstract protected void updateHistoryRecord()

Source Code: (show)
`protected abstract function updateHistoryRecord();`

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.