Commit faa5763a authored by zYne's avatar zYne

--no commit message

--no commit message
parent da437ddf
......@@ -21,7 +21,7 @@
/**
* Doctrine_Record_Filter
* Filters and prepares the record data
* Filters the record getters and setters
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......@@ -31,7 +31,7 @@
* @since 1.0
* @version $Revision: 1298 $
*/
class Doctrine_Record_Filter extends Doctrine_Object
class Doctrine_Record_Filter
{
/**
* @var Doctrine_Record $_record the record object this filter belongs to
......@@ -56,115 +56,19 @@ class Doctrine_Record_Filter extends Doctrine_Object
return $this->_record;
}
/**
* setDefaultValues
* sets the default values for records internal data
* filterSet
* defines an implementation for filtering the set() method of Doctrine_Record
*
* @param boolean $overwrite whether or not to overwrite the already set values
* @return boolean
* @param mixed $name name of the property or related component
*/
public function assignDefaultValues($data, $overwrite = false)
{
$table = $this->_record->getTable();
if ( ! $table->hasDefaultValues()) {
return false;
}
$modified = array();
foreach ($data as $column => $value) {
$default = $table->getDefaultValueOf($column);
if ($default === null) {
$default = self::$_null;
}
if ($value === self::$_null || $overwrite) {
$this->_record->rawSet($column, $default);
$modified[] = $column;
$this->_record->state(Doctrine_Record::STATE_TDIRTY);
}
}
$this->_record->setModified($modified);
}
abstract public function filterSet($key, $value)
{ }
/**
* prepareIdentifiers
* prepares identifiers for later use
* filterGet
* defines an implementation for filtering the get() method of Doctrine_Record
*
* @param boolean $exists whether or not this record exists in persistent data store
* @return void
* @param mixed $name name of the property or related component
*/
private function prepareIdentifiers($exists = true)
{
$id = $this->_table->getIdentifier();
$this->_id = array();
if (count($id) > 1) {
foreach ($id as $name) {
if ($this->_data[$name] === self::$_null) {
$this->_id[$name] = null;
} else {
$this->_id[$name] = $this->_data[$name];
}
}
} else {
if (isset($this->_data[$id]) && $this->_data[$id] !== self::$_null) {
$this->_id[$id] = $this->_data[$id];
}
}
}
/**
* getPrepared
*
* returns an array of modified fields and values with data preparation
* adds column aggregation inheritance and converts Records into primary key values
*
* @param array $array
* @return array
*/
public function getPrepared(array $array = array()) {
$a = array();
if (empty($array)) {
$array = $this->_modified;
}
foreach ($array as $k => $v) {
$type = $this->_table->getTypeOf($v);
if ($this->_data[$v] === self::$_null) {
$a[$v] = null;
continue;
}
switch ($type) {
case 'array':
case 'object':
$a[$v] = serialize($this->_data[$v]);
break;
case 'gzip':
$a[$v] = gzcompress($this->_data[$v],5);
break;
case 'boolean':
$a[$v] = $this->getTable()->getConnection()->convertBooleans($this->_data[$v]);
break;
case 'enum':
$a[$v] = $this->_table->enumIndex($v,$this->_data[$v]);
break;
default:
if ($this->_data[$v] instanceof Doctrine_Record) {
$this->_data[$v] = $this->_data[$v]->getIncremented();
}
$a[$v] = $this->_data[$v];
}
}
$map = $this->_table->inheritanceMap;
foreach ($map as $k => $v) {
$old = $this->get($k, false);
if ((string) $old !== (string) $v || $old === null) {
$a[$k] = $v;
$this->_data[$k] = $v;
}
}
return $a;
}
abstract public function filterGet($key)
{ }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment