|
From: <gem...@li...> - 2012-12-06 11:50:42
|
Revision: 1053
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1053&view=rev
Author: mennodekker
Date: 2012-12-06 11:50:35 +0000 (Thu, 06 Dec 2012)
Log Message:
-----------
Added onLoad for date fields + make save call the onload for the return values
Modified Paths:
--------------
branches/receptioncodes/library/classes/MUtil/Model/DatabaseModelAbstract.php
branches/receptioncodes/library/classes/MUtil/Model/JoinModel.php
branches/receptioncodes/library/classes/MUtil/Model/ModelAbstract.php
branches/receptioncodes/library/classes/MUtil/Model/TableModel.php
Modified: branches/receptioncodes/library/classes/MUtil/Model/DatabaseModelAbstract.php
===================================================================
--- branches/receptioncodes/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-11-30 14:45:28 UTC (rev 1052)
+++ branches/receptioncodes/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-12-06 11:50:35 UTC (rev 1053)
@@ -332,6 +332,7 @@
$finfo['type'] = MUtil_Model::TYPE_DATE;
$this->set($name, 'storageFormat', 'yyyy-MM-dd');
$this->setOnSave($name, array($this, 'formatSaveDate'));
+ $this->setOnLoad($name, array($this, 'formatLoadData'));
break;
case 'datetime':
@@ -339,12 +340,14 @@
$finfo['type'] = MUtil_Model::TYPE_DATETIME;
$this->set($name, 'storageFormat', 'yyyy-MM-dd HH:mm:ss');
$this->setOnSave($name, array($this, 'formatSaveDate'));
+ $this->setOnLoad($name, array($this, 'formatLoadData'));
break;
case 'time':
$finfo['type'] = MUtil_Model::TYPE_TIME;
$this->set($name, 'storageFormat', 'HH:mm:ss');
$this->setOnSave($name, array($this, 'formatSaveDate'));
+ $this->setOnLoad($name, array($this, 'formatLoadData'));
break;
case 'int':
@@ -670,6 +673,32 @@
throw new MUtil_Model_ModelException("Cannot create UniqueValue validator as no table was defined for field $name.");
}
+
+ /**
+ * A ModelAbstract->setOnLoad() function that takes care of transforming a
+ * dateformat read from the database to a Zend_Date format
+ *
+ * If empty or Zend_Db_Expression (after save) it will return just the value
+ * currently there are no checks for a valid date format.
+ *
+ * @see MUtil_Model_ModelAbstract
+ *
+ * @param mixed $value The value being saved
+ * @param boolean $isNew True when a new item is being saved
+ * @param string $name The name of the current field
+ * @param array $context Optional, the other values being saved
+ * @return MUtil_Date|Zend_Db_Expr|string
+ */
+ public function formatLoadDate($value, $isNew = false, $name = null, array $context = array())
+ {
+ // If not empty or zend_db_expression and not already a zend date, we
+ // transform to a Zend_Date using the ISO_8601 format
+ if (!empty($value) && !($value instanceof Zend_Date) && !($value instanceof Zend_Db_Expr)) {
+ $tmpDate = new MUtil_Date($value, Zend_Date::ISO_8601);
+ return $tmpDate;
+ }
+ return $value;
+ }
/**
* A ModelAbstract->setOnSave() function that returns the input
Modified: branches/receptioncodes/library/classes/MUtil/Model/JoinModel.php
===================================================================
--- branches/receptioncodes/library/classes/MUtil/Model/JoinModel.php 2012-11-30 14:45:28 UTC (rev 1052)
+++ branches/receptioncodes/library/classes/MUtil/Model/JoinModel.php 2012-12-06 11:50:35 UTC (rev 1053)
@@ -367,6 +367,9 @@
if ($this->getChanged() > $oldChanged) {
$this->setChanged(++$oldChanged);
}
+
+ // Handle possible onLoad
+ $newValues = $this->processAfterLoad($newValues);
return $newValues;
}
Modified: branches/receptioncodes/library/classes/MUtil/Model/ModelAbstract.php
===================================================================
--- branches/receptioncodes/library/classes/MUtil/Model/ModelAbstract.php 2012-11-30 14:45:28 UTC (rev 1052)
+++ branches/receptioncodes/library/classes/MUtil/Model/ModelAbstract.php 2012-12-06 11:50:35 UTC (rev 1053)
@@ -152,8 +152,10 @@
*/
protected function _filterDataAfterLoad(array $data, $new = false)
{
- foreach ($data as $name => $value) {
- $data[$name] = $this->getOnLoad($value, $new, $name, $data);
+ if ($this->getMeta(self::LOAD_TRANSFORMER)) {
+ foreach ($data as $name => $value) {
+ $data[$name] = $this->getOnLoad($value, $new, $name, $data);
+ }
}
return $data;
Modified: branches/receptioncodes/library/classes/MUtil/Model/TableModel.php
===================================================================
--- branches/receptioncodes/library/classes/MUtil/Model/TableModel.php 2012-11-30 14:45:28 UTC (rev 1052)
+++ branches/receptioncodes/library/classes/MUtil/Model/TableModel.php 2012-12-06 11:50:35 UTC (rev 1053)
@@ -119,6 +119,10 @@
{
// $this->_saveTableData returns the new row values, including any automatic changes.
// add $newValues to throw nothing away.
- return $this->_saveTableData($this->_table, $newValues, $filter, parent::SAVE_MODE_ALL) + $newValues;
+ $updatedValues = $this->_saveTableData($this->_table, $newValues, $filter, parent::SAVE_MODE_ALL) + $newValues;
+
+ // Handle possible onLoad
+ $updatedValues = $this->processAfterLoad($updatedValues);
+ return $updatedValues;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|