|
From: <gem...@li...> - 2011-11-17 10:59:37
|
Revision: 227
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=227&view=rev
Author: matijsdejong
Date: 2011-11-17 10:59:27 +0000 (Thu, 17 Nov 2011)
Log Message:
-----------
Preparation for #41 onLoad & getFormatted functionality:
- onSave() function enters the value first, isNew next, then name and context,
- SelectModelPaginator allows (future) interception of onLoad calls.
Modified Paths:
--------------
trunk/library/classes/Gems/Default/StaffAction.php
trunk/library/classes/Gems/Model/RespondentModel.php
trunk/library/classes/Gems/Model.php
trunk/library/classes/Gems/Project/ProjectSettings.php
trunk/library/classes/GemsEscort.php
trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php
trunk/library/classes/MUtil/Model/ModelAbstract.php
trunk/library/classes/MUtil/Model/Save/ArraySaver.php
trunk/library/snippets/EditTrackTokenSnippet.php
Added Paths:
-----------
trunk/library/classes/MUtil/Model/SelectModelPaginator.php
Modified: trunk/library/classes/Gems/Default/StaffAction.php
===================================================================
--- trunk/library/classes/Gems/Default/StaffAction.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/Gems/Default/StaffAction.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -98,7 +98,7 @@
case Gems_User_UserLoader::USER_STAFF:
Gems_Model::addUserPassword($model);
$passwordField = 'gup_password';
- $model->setOnSave($passwordField, array($this->project, 'getValueHashForModel'));
+ $model->setOnSave($passwordField, array($this->project, 'getValueHash'));
break;
case Gems_User_UserLoader::USER_OLD_STAFF:
@@ -268,12 +268,13 @@
/**
* Return an old style (< 1.5) hashed version of the input value.
*
- * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
* @param string $value The value to hash.
* @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility
+ * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
+ * @param array $context Optional, the other values being saved
* @return string The salted hash as a 32-character hexadecimal number.
*/
- public function getOldPasswordHash($name, $value, $new)
+ public function getOldPasswordHash($value, $isNew = false, $name = null, array $context = array())
{
return md5($value);
}
Modified: trunk/library/classes/Gems/Model/RespondentModel.php
===================================================================
--- trunk/library/classes/Gems/Model/RespondentModel.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/Gems/Model/RespondentModel.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -133,12 +133,13 @@
/**
* Return a hashed version of the input value.
*
- * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
- * @param string $value The value to hash.
- * @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility
+ * @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 string The salted hash as a 32-character hexadecimal number.
*/
- public function formatSSN($name, $value, $new = false)
+ public function formatSSN($value, $isNew = false, $name = null, array $context = array())
{
if ($value) {
return $this->project->getValueHash($value);
Modified: trunk/library/classes/Gems/Model.php
===================================================================
--- trunk/library/classes/Gems/Model.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/Gems/Model.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -120,12 +120,15 @@
/**
* Create a Gems project wide unique user id
*
- * @param string $name
- * @param mixed $value
- * @param boolean $isNew
+ * @see Gems_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 int
*/
- public function createGemsUserId($name, $value, $isNew)
+ public function createGemsUserId($value, $isNew = false, $name = null, array $context = array())
{
if ($isNew || (null === $value)) {
$creationTime = new Zend_Db_Expr('CURRENT_TIMESTAMP');
Modified: trunk/library/classes/Gems/Project/ProjectSettings.php
===================================================================
--- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -224,17 +224,4 @@
return md5($salted, false);
}
-
- /**
- * Returns a salted hash on the
- *
- * @param string $name Fieldname
- * @param string $value The value to hash
- * @param string $isNew True when new
- * @return string The salted hash as a 32-character hexadecimal number.
- */
- public function getValueHashForModel($name, $value, $isNew = false)
- {
- return $this->getValueHash($value);
- }
}
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/GemsEscort.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -1207,12 +1207,13 @@
*
* @deprecated Since 1.5
*
- * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
* @param string $value The value to hash.
* @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility
+ * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
+ * @param array $context Optional, the other values being saved
* @return string The salted hash as a 32-character hexadecimal number.
*/
- public function passwordHash($name, $value, $new)
+ public function passwordHash($value, $isNew = false, $name = null, array $context = array())
{
return $this->project->getValueHash($value);
}
Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -596,14 +596,26 @@
throw new MUtil_Model_ModelException("Cannot create UniqueValue validator as no table was defined for field $name.");
}
- public function formatSaveDate($name, $value, $new = false)
+ /**
+ * A ModelAbstract->setOnSave() function that returns the input
+ * date as a valid date.
+ *
+ * @see Gems_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 Zend_Date
+ */
+ public function formatSaveDate($value, $isNew = false, $name = null)
{
if ($name && (! ((null === $value) || ($value instanceof Zend_Db_Expr)))) {
if ($saveFormat = $this->get($name, 'storageFormat')) {
if ($value instanceof Zend_Date) {
return $value->toString($saveFormat);
-
+
} else {
$displayFormat = $this->get($name, 'dateFormat');
@@ -737,9 +749,10 @@
*/
public function loadPaginator($filter = true, $sort = true)
{
- $select = $this->_createSelect($filter, $sort);
+ $select = $this->_createSelect($filter, $sort);
+ $adapter = new MUtil_Model_SelectModelPaginator($select, $this);
- return Zend_Paginator::factory($select);
+ return new Zend_Paginator($adapter);
}
// abstract public function save(array $newValues);
Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -143,7 +143,7 @@
}
if ($this->isSaveable($name, $value, $new)) {
- $filteredData[$name] = $this->getOnSave($name, $value, $new);
+ $filteredData[$name] = $this->getOnSave($value, $new, $name, $data);
}
}
@@ -579,12 +579,22 @@
return $this->_model_name;
}
- public function getOnSave($name, $value, $new = false)
+ /**
+ * Checks for and executes any actions to perform on a value before
+ * saving the value
+ *
+ * @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 mixed The value to save
+ */
+ public function getOnSave($value, $new, $name, array $context = array())
{
if ($call = $this->get($name, self::SAVE_TRANSFORMER)) {
if (is_callable($call)) {
- $value = call_user_func($call, $name, $value, $new);
+ $value = call_user_func($call, $value, $new, $name, $context);
} else {
$value = $call;
}
@@ -1107,6 +1117,13 @@
return $this;
}
+ /**
+ * Sets a name to automatically determined/changed of value during save.
+ *
+ * @param string $name
+ * @param mixed $callableOrConstant A constant or a function of this type: callable($value, $isNew = false, $name = null, array $context = array())
+ * @return MUtil_Model_ModelAbstract (continuation pattern)
+ */
public function setOnSave($name, $callableOrConstant)
{
$this->set($name, self::SAVE_TRANSFORMER, $callableOrConstant);
Modified: trunk/library/classes/MUtil/Model/Save/ArraySaver.php
===================================================================
--- trunk/library/classes/MUtil/Model/Save/ArraySaver.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/classes/MUtil/Model/Save/ArraySaver.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -75,7 +75,19 @@
return $class;
}
- public function saveValue($name, $value, $isNew)
+ /**
+ * A ModelAbstract->setOnSave() function that concatenates the
+ * value if it is an array.
+ *
+ * @see Gems_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 Zend_Date
+ */
+ public function saveValue($value, $isNew = false, $name = null, array $context = array())
{
if (is_array($value)) {
$value = implode($this->seperatorChar, $value);
Added: trunk/library/classes/MUtil/Model/SelectModelPaginator.php
===================================================================
--- trunk/library/classes/MUtil/Model/SelectModelPaginator.php (rev 0)
+++ trunk/library/classes/MUtil/Model/SelectModelPaginator.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Model
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * This class wraps around a select as a paginator, while allowing model->onload
+ * functions to apply.
+ *
+ * @see MUtil_Model_DatabaseModelAbstract
+ *
+ * @package MUtil
+ * @subpackage Model
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class MUtil_Model_SelectModelPaginator implements Zend_Paginator_Adapter_Interface
+{
+ /**
+ *
+ * @var MUtil_Model_DatabaseModelAbstract
+ */
+ protected $_model;
+
+ /**
+ *
+ * @var Zend_Paginator_Adapter_DbSelect
+ */
+ protected $_selectAdapter;
+
+ /**
+ *
+ * @param Zend_Db_Select $select
+ * @param MUtil_Model_ModelAbstract $model
+ */
+ public function __construct(Zend_Db_Select $select, MUtil_Model_DatabaseModelAbstract $model)
+ {
+ $this->_selectAdapter = new Zend_Paginator_Adapter_DbSelect($select);
+ $this->_model = $model;
+ }
+
+ /**
+ * Returns the total number of rows in the result set.
+ *
+ * @return integer
+ */
+ public function count()
+ {
+ return $this->_selectAdapter->count();
+ }
+
+ /**
+ * Returns an array of items for a page.
+ *
+ * @param integer $offset Page offset
+ * @param integer $itemCountPerPage Number of items per page
+ * @return array
+ */
+ public function getItems($offset, $itemCountPerPage)
+ {
+ $items = $this->_selectAdapter->getItems($offset, $itemCountPerPage);
+
+ return $items;
+ }
+}
Modified: trunk/library/snippets/EditTrackTokenSnippet.php
===================================================================
--- trunk/library/snippets/EditTrackTokenSnippet.php 2011-11-17 08:45:52 UTC (rev 226)
+++ trunk/library/snippets/EditTrackTokenSnippet.php 2011-11-17 10:59:27 UTC (rev 227)
@@ -160,8 +160,8 @@
if ($this->formData[self::RECALCULATE_FIELD]) {
$model = $this->getModel();
// Refresh token with current form data
- $updateData['gto_valid_from'] = $model->getOnSave('gto_valid_from', $this->formData['gto_valid_from'], true);
- $updateData['gto_valid_until'] = $model->getOnSave('gto_valid_until', $this->formData['gto_valid_until'], true);
+ $updateData['gto_valid_from'] = $model->getOnSave($this->formData['gto_valid_from'], true, 'gto_valid_from');
+ $updateData['gto_valid_until'] = $model->getOnSave($this->formData['gto_valid_until'], true, 'gto_valid_until');
$updateData['gto_comment'] = $this->formData['gto_comment'];
$this->token->refresh($updateData);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|