My FIU Curriculum Class Reference. Yii Framework

# Set

Package | application
Inheritance | class Set » VersionedEntity
Source Code |

Description of Set

## 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
--- | --- | ---
Set() | Constructor | Set
createNewEntity() |  | VersionedEntity
deleteOrRevertEntity() |  | VersionedEntity
getArrEntity() |  | VersionedEntity
getEntity() |  | VersionedEntity
getHistoryEntities() |  | Set
getHistoryEntity() |  | Set
updateData() |  | VersionedEntity

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
VersionedEntity() |  | VersionedEntity
createNewHistoryRecord() | Updates the entity CREATING a new history record | Set
entityExistsCurr() |  | Set
entityExistsHis() |  | Set
findEntity() | Finds an entity of the table with the most recent history. | Set
getMostResentActivatedVersionForEntity() |  | VersionedEntity
newEntity() | Creates a new entity (saves to database) | Set
updateHistoryRecord() | Updates the entity WITHOUT CREATING a new history record | Set

## Method Details

Set() method

public void Set(type $entityId, type $catalogId)
$entityId | type |
$catalogId | type |

Source Code: (show)
`public function Set($entityId, $catalogId){
$this->his_tableName = 'his_set';
parent::VersionedEntity($entityId, $catalogId);
}`

Constructor

createNewHistoryRecord() method

protected BOOLEAN createNewHistoryRecord()
{return} | BOOLEAN |

Source Code: (show)
`protected function createNewHistoryRecord() {
$hisRecord = $this->entity->hisSets[0];
$newHisRecord = new HisSet();
$newHisRecord->setAttributes($hisRecord->attributes);
$newHisRecord->unsetAttributes(array('id'));
$newHisRecord->setIsNewRecord(true);
$newHisRecord->catalog_id = $this->catalog_id;
return $newHisRecord->save();
}`

Updates the entity CREATING a new history record

entityExistsCurr() method

protected static void entityExistsCurr(AR $model)
$model | AR |

Source Code: (show)
`protected static function entityExistsCurr($model) {
return CurrSet::model()->exists('id=:id', array(':id'=>$model->id));
}`

entityExistsHis() method

protected static void entityExistsHis($model)
$model |  |

Source Code: (show)
`protected static function entityExistsHis($model) {
return HisSet::model()->exists('id=:id', array(':id'=>$model->id));
}`

findEntity() method

protected AR findEntity(type $entityId)
$entityId | type |
{return} | AR | entity with most recent history

Source Code: (show)
`protected function findEntity($entityId) {
//SELECT * FOROM curr_table, his_table
// WHERE id = $entityId AND his_table.catalog_id=$$versionId
$entity = CurrSet::model()->with('hisSets')->find('t.id=:entityId AND hisSets.catalog_id=:versionId',
array(':entityId'=>$entityId, ':versionId'=> $this->catalog_id ));
//if version of history does not exists, find the most reasent one
if(is_null($entity)){
//get the most resent active version on the his_table
$mostResentActiveVersion = $this->getMostResentActivatedVersionForEntity($entityId, $this->his_tableName);
//SELECT * FOROM curr_table, his_table
// WHERE id = $entityId AND his_table.catalog_id=$mostResentActiveVersion['id']
$entity = CurrSet::model()->with('hisSets')->find('t.id=:entityId AND hisSets.catalog_id=:versionId',
array(':entityId'=>$entityId, ':versionId'=> $mostResentActiveVersion['id']));
}
//Return the entity Active Record
return $entity;
}`

Finds an entity of the table with the most recent history. It is used by a wrapper on the parent class to set the member entity.

getHistoryEntities() method

public void getHistoryEntities()

Source Code: (show)
`public function getHistoryEntities() {
return HisSet::model()->findAll('identifier_id=:entityId', array('entityId'=>$this->entity->id));
}`

getHistoryEntity() method

public void getHistoryEntity()

Source Code: (show)
`public function getHistoryEntity() {
return $this->entity->hisSets[0];
}`

newEntity() method

protected static int newEntity(AR $currModel, AR $hisModel)
$currModel | AR |
$hisModel | AR |
{return} | int | Id of new entity

Source Code: (show)
`protected static function newEntity($currModel, $hisModel) {
// create identifier (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");
}
}`

Creates a new entity (saves to database) creates the identifier record (curr_table), and then the data (his_table)

updateHistoryRecord() method

protected BOOLEAN updateHistoryRecord()
{return} | BOOLEAN |

Source Code: (show)
`protected function updateHistoryRecord() {
$hisRecord = $this->entity->hisSets[0];
return $hisRecord->save();
}`

Updates the entity WITHOUT CREATING a new history record

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