Track
| Package | application |
|---|---|
| Inheritance | class Track » VersionedEntity |
| Source Code |
Description of Track
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| catalog | VersionedEntity | ||
| catalog_id | VersionedEntity | ||
| entity | VersionedEntity | ||
| entityType | VersionedEntity | ||
| his_tableName | VersionedEntity |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| Track() | Constructor | Track |
| createNewEntity() | VersionedEntity | |
| deleteOrRevertEntity() | VersionedEntity | |
| getArrEntity() | VersionedEntity | |
| getEntity() | VersionedEntity | |
| getHistoryEntities() | Track | |
| getHistoryEntity() | Track | |
| updateData() | VersionedEntity |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| VersionedEntity() | VersionedEntity | |
| createNewHistoryRecord() | Updates the entity CREATING a new history record | Track |
| entityExistsCurr() | Track | |
| entityExistsHis() | Track | |
| findEntity() | Finds an entity of the table with the most recent history. | Track |
| getMostResentActivatedVersionForEntity() | VersionedEntity | |
| newEntity() | Creates a new entity (saves to database) | Track |
| updateHistoryRecord() | Updates the entity WITHOUT CREATING a new history record | Track |
Method Details
Track()
method
|
public void Track(type $entityId, type $catalogId)
| ||
| $entityId | type | |
| $catalogId | type | |
Source Code: (show)
public function Track($entityId, $catalogId){
$this->his_tableName = 'his_track';
parent::VersionedEntity($entityId, $catalogId);
}
Constructor
createNewHistoryRecord()
method
|
protected BOOLEAN createNewHistoryRecord()
| ||
| {return} | BOOLEAN | |
Source Code: (show)
protected function createNewHistoryRecord() {
$hisRecord = $this->entity->hisTracks[0];
$newHisRecord = new HisTrack();
$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 CurrTrack::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 HisTrack::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 = CurrTrack::model()->with('hisTracks')->find('t.id=:entityId AND hisTracks.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 = CurrTrack::model()->with('hisTracks')->find('t.id=:entityId AND hisTracks.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 HisTrack::model()->findAll('identifier_id=:entityId', array('entityId'=>$this->entity->id));
}
getHistoryEntity()
method
|
public void getHistoryEntity()
|
Source Code: (show)
public function getHistoryEntity() {
return $this->entity->hisTracks[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->hisTracks[0];
return $hisRecord->save();
}
Updates the entity WITHOUT CREATING a new history record