<?php
interface IPersistentBehavior {
public function getPersistentVariable();
}
?>
<?php
class XActiveRecord extends CActiveRecord {
/**
* Creates an active record with the given attributes.
* This method is internally used by the find methods.
* @param array $attributes attribute values (column name=>column value)
* @param boolean $callAfterFind whether to call {@link afterFind} after the record is populated.
* @return CActiveRecord the newly created active record. The class of the object is the same as the model class.
* Null is returned if the input data is false.
*/
public function populateRecord($attributes, $callAfterFind = true) {
if ($attributes !== false) {
$record = $this->instantiate($attributes);
$recordBehaviors = $record->behaviors();
$behaviors = $this->getBehaviors();
foreach ($behaviors as $name => $behavior) {
if (isset($recordBehaviors[$name]) && $behavior instanceof IPersistentBehavior) {
$oldConfig = $this->getBehavior($name)->getPersistentVariable();
$recordBehaviors[$name] = CMap::mergeArray($recordBehaviors[$name], $oldConfig);
}
}
$record->setScenario('update');
$record->init();
$md = $record->getMetaData();
foreach ($attributes as $name => $value) {
if (property_exists($record, $name))
$record->$name = $value;
else if (isset($md->columns[$name]))
$record->_attributes[$name] = $value;
}
$record->_pk = $record->getPrimaryKey();
$record->attachBehaviors($recordBehaviors);
if ($callAfterFind)
$record->afterFind();
return $record;
}
else
return null;
}
}
?>
<?php
class XLocalizerBehavior extends CActiveRecordBehavior implements IPersistentBehavior {
public $langId = null;
public $loadAllLocale = null;
public $copyVirtualAttributes = null;
public function getPersistentVariable() {
return array(
'langId' => $this->langId,
'loadAllLocale' => $this->loadAllLocale,
'copyVirtualAttributes' => $this->copyVirtualAttributes
);
}
}
?>