|
From: <gem...@li...> - 2011-11-28 18:24:41
|
Revision: 301
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=301&view=rev
Author: matijsdejong
Date: 2011-11-28 18:24:32 +0000 (Mon, 28 Nov 2011)
Log Message:
-----------
#44 Reception codes can be stopped.
Reception codes got their own objects in the margin. Processing changes has become more simple: just cascade to respondentTrack and token and let them decide to change anything.
Modified Paths:
--------------
trunk/library/classes/Gems/Default/ReceptionAction.php
trunk/library/classes/Gems/Default/RespondentAction.php
trunk/library/classes/Gems/Tracker/RespondentTrack.php
trunk/library/classes/Gems/Tracker/Token.php
trunk/library/classes/Gems/Tracker.php
trunk/library/classes/Gems/User/Organization.php
trunk/library/classes/Gems/User/User.php
trunk/library/classes/Gems/Util/Translated.php
trunk/library/classes/Gems/Util.php
trunk/library/configs/db/patches.sql
trunk/library/configs/db/tables/gems__reception_codes.10.sql
trunk/library/languages/default-en.mo
trunk/library/languages/default-en.po
trunk/library/languages/default-nl.mo
trunk/library/languages/default-nl.po
trunk/library/snippets/DeleteInSourceTrackSnippet.php
trunk/library/snippets/DeleteSingleSurveyInSourceTokenSnippet.php
trunk/library/snippets/DeleteTrackTokenSnippet.php
Added Paths:
-----------
trunk/library/classes/Gems/Registry/CachedArrayTargetAbstract.php
trunk/library/classes/Gems/Util/ReceptionCode.php
trunk/library/classes/Gems/Util/ReceptionCodeLibrary.php
Modified: trunk/library/classes/Gems/Default/ReceptionAction.php
===================================================================
--- trunk/library/classes/Gems/Default/ReceptionAction.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Default/ReceptionAction.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -71,9 +71,10 @@
*/
public function createModel($detailed, $action)
{
- $yesNo = $this->util->getTranslated()->getYesNo();
+ $rcLib = $this->util->getReceptionCodeLibrary();
+ $yesNo = $this->util->getTranslated()->getYesNo();
- $model = new MUtil_Model_TableModel('gems__reception_codes');
+ $model = new MUtil_Model_TableModel('gems__reception_codes');
$model->copyKeys(); // The user can edit the keys.
$model->set('grc_id_reception_code', 'label', $this->_('Code'), 'size', '10');
@@ -85,11 +86,11 @@
'elementClass', 'CheckBox',
'description', $this->_('This reception code is a success code.'));
$model->set('grc_active', 'label', $this->_('Active'),
- 'multiOptions', $yesNo ,
+ 'multiOptions', $yesNo,
'elementClass', 'CheckBox',
'description', $this->_('Only active codes can be selected.'));
$model->set('grc_for_respondents', 'label', $this->_('For respondents'),
- 'multiOptions', $yesNo ,
+ 'multiOptions', $yesNo,
'elementClass', 'CheckBox',
'description', $this->_('This reception code can be assigned to a respondent.'));
$model->set('grc_for_tracks', 'label', $this->_('For tracks'),
@@ -97,15 +98,13 @@
'elementClass', 'CheckBox',
'description', $this->_('This reception code can be assigned to a track.'));
$model->set('grc_for_surveys', 'label', $this->_('For surveys'),
- 'multiOptions', $yesNo ,
- 'elementClass', 'CheckBox',
+ 'multiOptions', $rcLib->getSurveyApplicationValues(),
'description', $this->_('This reception code can be assigned to a survey.'));
$model->set('grc_redo_survey', 'label', $this->_('Redo survey'),
- 'multiOptions', $this->util->getTranslated()->getRedoCodes(),
- 'elementClass', 'Select',
+ 'multiOptions', $rcLib->getRedoValues(),
'description', $this->_('Redo a survey on this reception code.'));
$model->set('grc_overwrite_answers', 'label', $this->_('Overwrite ansers'),
- 'multiOptions', $yesNo ,
+ 'multiOptions', $yesNo,
'elementClass', 'CheckBox',
'description', $this->_('Remove the consent from already answered surveys.'));
Modified: trunk/library/classes/Gems/Default/RespondentAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -227,8 +227,7 @@
// Log
$this->openedRespondent($data['gr2o_patient_nr'], $data['gr2o_id_organization'], $data['grs_id_user']);
- $sql = 'SELECT grc_id_reception_code, grc_description FROM gems__reception_codes WHERE grc_active = 1 AND grc_for_respondents = 1 ORDER BY grc_description';
- $options = $this->db->fetchPairs($sql);
+ $options = $this->util->getReceptionCodeLibrary()->getRespondentDeletionCodes();
$bridge = new MUtil_Model_FormBridge($model, $this->createForm());
$bridge->addSelect('gr2o_reception_code',
@@ -245,53 +244,39 @@
if ($request->isPost()) {
$data = $_POST + $data;
if ($form->isValid($data )) {
- // Is really removed
- if ($data['gr2o_reception_code'] != GemsEscort::RECEPTION_OK) {
- // Perform actual save
- $where = 'gr2o_id_user = ? AND gr2o_id_organization = ?';
- $where = $this->db->quoteInto($where, $data['gr2o_id_user'], null, 1);
- $where = $this->db->quoteInto($where, $data['gr2o_id_organization'], null, 1);
- $this->db->update('gems__respondent2org', array(
- 'gr2o_reception_code' => $data['gr2o_reception_code'],
- 'gr2o_changed' => new Zend_Db_Expr('CURRENT_TIMESTAMP'),
- 'gr2o_changed_by' => $this->session->user_id),
- $where);
+ $code = $this->util->getReceptionCode($data['gr2o_reception_code']);
- // Check for redo or overwrite answer in reception code.
- $sql = 'SELECT grc_overwrite_answers
- FROM gems__reception_codes
- WHERE grc_overwrite_answers = 1 AND grc_id_reception_code = ? LIMIT 1';
- if ($this->db->fetchOne($sql, $data['gr2o_reception_code'])) {
- // Update consent for tokens
- $consentCode = $this->util->getConsentRejected();
+ // Is the respondent really removed
+ if (! $code->isSuccess()) {
+ $userId = $this->loader->getCurrentUser()->getUserId();
- $tracker = $this->loader->getTracker();
- $tokenSelect = $tracker->getTokenSelect(true);
- $tokenSelect
- ->andReceptionCodes()
- ->andRespondentOrganizations()
- ->andConsents()
- ->forRespondent($data['gr2o_id_user'], $data['gr2o_id_organization']);
+ // Cascade to tracks
+ // the responsiblilty to handle it correctly is on the sub objects now.
+ $tracks = $this->loader->getTracker()->getRespondentTracks($data['gr2o_id_user'], $data['gr2o_id_organization']);
+ foreach ($tracks as $track) {
+ $track->setReceptionCode($code, null, $userId);
+ }
- // Update reception code for tokens
- $tokens = $tokenSelect->fetchAll();
+ // Perform actual save, but not simple stop codes.
+ if ($code->isForRespondents()) {
+ $values['gr2o_reception_code'] = $data['gr2o_reception_code'];
+ $values['gr2o_changed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
+ $values['gr2o_changed_by'] = $userId;
- // When a TRACK is removed, all tokens are automatically revoked
- foreach ($tokens as $tokenData) {
- $token = $tracker->getToken($tokenData);
- if ($token->hasSuccesCode() && $token->inSource()) {
+ $where = 'gr2o_id_user = ? AND gr2o_id_organization = ?';
+ $where = $this->db->quoteInto($where, $data['gr2o_id_user'], null, 1);
+ $where = $this->db->quoteInto($where, $data['gr2o_id_organization'], null, 1);
- $token->getSurvey()->updateConsent($token, $consentCode);
+ $this->db->update('gems__respondent2org', $values, $where);
- // TODO: Decide what to do: now we only update the consent codes, not
- // the token and respondentTrack consent codes
- // $token->setReceptionCode($data['gr2t_reception_code'], null, $this->session->user_id);
- }
- }
+ $this->addMessage($this->_('Respondent deleted.'));
+ $this->_reroute(array('action' => 'index'), true);
+ } else {
+ // Just a stop code
+ $this->addMessage($this->_('Respondent tracks stopped.'));
+ $this->_reroute(array('action' => 'show'));
}
- $this->addMessage($this->_('Respondent deleted.'));
- $this->_reroute(array('action' => 'index'), true);
} else {
$this->addMessage($this->_('Choose a reception code to delete.'));
}
Added: trunk/library/classes/Gems/Registry/CachedArrayTargetAbstract.php
===================================================================
--- trunk/library/classes/Gems/Registry/CachedArrayTargetAbstract.php (rev 0)
+++ trunk/library/classes/Gems/Registry/CachedArrayTargetAbstract.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -0,0 +1,175 @@
+<?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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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 Gems
+ * @subpackage Registry
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Add's automatic caching to an registry target object.
+ *
+ * @package Gems
+ * @subpackage Registry
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+abstract class Gems_Registry_CachedArrayTargetAbstract extends Gems_Registry_TargetAbstract
+{
+ /**
+ * Variable to add tags to the cache for cleanup.
+ *
+ * @var array
+ */
+ protected $_cacheTags = array();
+
+ /**
+ * The current data.
+ *
+ * @var array
+ */
+ protected $_data;
+
+ /**
+ * The id for this data
+ *
+ * @var mixed
+ */
+ protected $_id;
+
+ /**
+ *
+ * @var Zend_Cache_Core
+ */
+ protected $cache;
+
+ /**
+ * Creates the object.
+ *
+ * @param mixed $id Whatever identifies this object.
+ */
+ public function __construct($id)
+ {
+ $this->_id = $id;
+ }
+
+ /**
+ * isset() safe array access helper function.
+ *
+ * @param string $name
+ * @return mixed
+ */
+ protected function _get($name)
+ {
+ if (isset($this->_data[$name])) {
+ return $this->_data[$name];
+ }
+ }
+
+ /**
+ * Get the cacheId for the organization
+ *
+ * @return string
+ */
+ private function _getCacheId() {
+ return GEMS_PROJECT_NAME . '__' . get_class($this) . '__' . $this->_id;
+ }
+
+ /**
+ * Changes a value and signals the cache.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return Gems_Registry_CachedArrayTargetAbstract (continuation pattern)
+ */
+ protected function _set($name, $value)
+ {
+ $this->_data[$name] = $value;
+
+ // Do not reload / save here:
+ // 1: other changes might follow,
+ // 2: it might not be used,
+ // 3: e.g. database saves may change other data.
+ $this->invalidateCache();
+
+ return $this;
+ }
+
+ /**
+ * Should be called after answering the request to allow the Target
+ * to check if all required registry values have been set correctly.
+ *
+ * @return boolean False if required are missing.
+ */
+ public function checkRegistryRequestsAnswers()
+ {
+ if ($this->cache) {
+ $cacheId = $this->_getCacheId();
+ $this->_data = $this->cache->load($cacheId);
+ } else {
+ $cacheId = false;
+ }
+
+ if (! $this->_data) {
+ $this->_data = $this->loadData($this->_id);
+
+ if ($cacheId) {
+ $this->cache->save($this->_data, $cacheId, $this->_cacheTags);
+ }
+ }
+ // MUtil_Echo::track($this->_data);
+
+ return is_array($this->_data) && parent::checkRegistryRequestsAnswers();
+ }
+
+ /**
+ * Empty the cache of the organization
+ *
+ * @return Gems_User_Organization (continutation pattern)
+ */
+ public function invalidateCache() {
+ if ($this->cache) {
+ $cacheId = $this->_getCacheId();
+ $this->cache->remove($cacheId);
+ }
+ return $this;
+ }
+
+ /**
+ * Load the data when the cache is empty.
+ *
+ * @param mixed $id
+ * @return array The array of data values
+ */
+ abstract protected function loadData($id);
+}
Modified: trunk/library/classes/Gems/Tracker/RespondentTrack.php
===================================================================
--- trunk/library/classes/Gems/Tracker/RespondentTrack.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Tracker/RespondentTrack.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -100,6 +100,12 @@
/**
*
+ * @var Gems_Util
+ */
+ protected $util;
+
+ /**
+ *
* @param mixed $respTracksData Track Id or array containing reps2track record
*/
public function __construct($respTracksData)
@@ -113,6 +119,40 @@
}
/**
+ * Check this respondent track for the number of tokens completed / to do
+ *
+ * @param int $userId Id of the user who takes the action (for logging)
+ * @return int 1 if the track was changed by this code
+ */
+ public function _checkTrackCount($userId)
+ {
+ $sqlCount = 'SELECT COUNT(*) AS count, COALESCE(SUM(CASE WHEN gto_completion_time IS NULL THEN 0 ELSE 1 END), 0) AS completed
+ FROM gems__tokens
+ JOIN gems__reception_codes ON gto_reception_code = grc_id_reception_code AND grc_success = 1
+ WHERE gto_id_respondent_track = ?';
+
+ if ($counts = $this->db->fetchRow($sqlCount, $this->_respTrackId)) {
+ $values['gr2t_count'] = intval($counts['count']);
+ $values['gr2t_completed'] = intval($counts['completed']);
+
+ if ($values['gr2t_count'] == $values['gr2t_completed']) {
+ $tokenSelect = $this->tracker->getTokenSelect(array('MAX(gto_completion_time)'));
+ $tokenSelect->andReceptionCodes(array())
+ ->forRespondentTrack($this->_respTrackId)
+ ->onlySucces();
+
+ $values['gr2t_end_date'] = $tokenSelect->fetchOne();
+ } else {
+ $values['gr2t_end_date'] = null;
+ }
+
+ return $this->_updateTrack($values, $userId);
+ }
+
+ return 0;
+ }
+
+ /**
* Makes sure the fieldData is in $this->_fieldData
*
* @param boolean $reload Optional parameter to force reload.
@@ -129,7 +169,7 @@
$fieldData[$fieldMap[$key]] = $value;
}
}
-
+
$this->_fieldData = $fieldData;
}
}
@@ -137,19 +177,23 @@
/**
* Makes sure the receptioncode data is part of the $this->_respTrackData
*
- * @param boolean $reload Optional parameter to force reload.
+ * @param boolean $reload Optional parameter to force reload or array with new values.
*/
private function _ensureReceptionCode($reload = false)
{
if ($reload || (! isset($this->_respTrackData['grc_success']))) {
- $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ?";
- $code = $this->_respTrackData['gr2t_reception_code'];
+ if (is_array($reload)) {
+ $this->_respTrackData = $reload + $this->_respTrackData;
+ } else {
+ $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ?";
+ $code = $this->_respTrackData['gr2t_reception_code'];
- if ($row = $this->db->fetchRow($sql, $code)) {
- $this->_respTrackData = $row + $this->_respTrackData;
- } else {
- $trackId = $this->_respTrackId;
- throw new Gems_Exception("Reception code $code is missing for track $trackId.");
+ if ($row = $this->db->fetchRow($sql, $code)) {
+ $this->_respTrackData = $row + $this->_respTrackData;
+ } else {
+ $trackId = $this->_respTrackId;
+ throw new Gems_Exception("Reception code $code is missing for track $trackId.");
+ }
}
}
}
@@ -292,31 +336,12 @@
*/
public function checkTrackTokens($userId, Gems_Tracker_Token $fromToken = null)
{
- $sqlCount = 'SELECT COUNT(*) AS count, COALESCE(SUM(CASE WHEN gto_completion_time IS NULL THEN 0 ELSE 1 END), 0) AS completed
- FROM gems__tokens
- JOIN gems__reception_codes ON gto_reception_code = grc_id_reception_code AND grc_success = 1
- WHERE gto_id_respondent_track = ?';
+ // Update token completion count.
+ $this->_checkTrackCount($userId);
- if ($counts = $this->db->fetchRow($sqlCount, $this->_respTrackId)) {
- $values['gr2t_count'] = intval($counts['count']);
- $values['gr2t_completed'] = intval($counts['completed']);
-
- if ($values['gr2t_count'] == $values['gr2t_completed']) {
- $tokenSelect = $this->tracker->getTokenSelect(array('MAX(gto_completion_time)'));
- $tokenSelect->andReceptionCodes(array())
- ->forRespondentTrack($this->_respTrackId)
- ->onlySucces();
-
- $values['gr2t_end_date'] = $tokenSelect->fetchOne();
- } else {
- $values['gr2t_end_date'] = null;
- }
-
- $this->_updateTrack($values, $userId);
- }
-
$engine = $this->getTrackEngine();
+ // Check for validFrom and validUntil dates that have changed.
if ($fromToken) {
return $engine->checkTokensFrom($this, $fromToken, $userId);
} elseif ($this->_checkStart) {
@@ -619,7 +644,7 @@
$this->_respTrackData = $this->db->fetchRow($sql, $this->_respTrackId);
}
-
+
$this->_ensureFieldData(true);
return $this;
@@ -629,30 +654,57 @@
* Set the reception code for this respondent track and make sure the
* necessary cascade to the tokens and thus the source takes place.
*
- * @param string $code The new reception code
+ * @param string $code The new (non-success) reception code or a Gems_Util_ReceptionCode object
* @param string $comment Comment for tokens. False values leave value unchanged
* @param int $userId The current user
* @return int 1 if the token has changed, 0 otherwise
*/
public function setReceptionCode($code, $comment, $userId)
{
- $values['gr2t_reception_code'] = $code;
+ // Make sure it is a Gems_Util_ReceptionCode object
+ if (! $code instanceof Gems_Util_ReceptionCode) {
+ $code = $this->util->getReceptionCode($code);
+ }
+ $changed = 0;
- $changed = $this->_updateTrack($values, $userId);
+ // Apply this code both only when it is a track code.
+ // Patient level codes are just cascaded to the tokens.
+ //
+ // The exception is of course when the exiting values must
+ // be overwritten, e.g. when cooperation is retracted.
+ if ($code->isForTracks() || $code->isOverwriter()) {
+ $values['gr2t_reception_code'] = $code->getCode();
- if ($changed) {
- // Reload reception code values
- $this->_ensureReceptionCode(true);
+ $changed = $this->_updateTrack($values, $userId);
- // Cascade to tokens
- if (! $this->hasSuccesCode()) {
- foreach ($this->getTokens() as $token) {
- if ($token->hasSuccesCode()) {
- $token->setReceptionCode($code, $comment, $userId);
- }
+ if ($changed) {
+ // Reload reception code values
+ $this->_ensureReceptionCode($code->getAllData());
+ }
+ }
+
+ // Stopcodes have a different logic.
+ if ($code->isStopCode()) {
+ // Cascade stop to tokens
+ foreach ($this->getTokens() as $token) {
+ if ($token->hasSuccesCode() && (! $token->isCompleted())) {
+ $changed += $token->setReceptionCode($code, $comment, $userId);
}
}
+ $changed = max($changed, 1);
+
+ // Update token count / completion
+ $this->_checkTrackCount($userId);
+
+ } elseif (! $code->isSuccess()) {
+ // Cascade code to tokens
+ foreach ($this->getTokens() as $token) {
+ if ($token->hasSuccesCode()) {
+ $token->setReceptionCode($code, $comment, $userId);
+ }
+ }
}
+
return $changed;
}
}
Modified: trunk/library/classes/Gems/Tracker/Token.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Token.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Tracker/Token.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -147,19 +147,23 @@
/**
* Makes sure the receptioncode data is part of the $this->_gemsData
*
- * @param boolean $reload Optional parameter to force reload.
+ * @param boolean $reload Optional parameter to force reload or an array with the new values.
*/
private function _ensureReceptionCode($reload = false)
{
if ($reload || (! isset($this->_gemsData['grc_success']))) {
- $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ?";
- $code = $this->_gemsData['gto_reception_code'];
+ if (is_array($reload)) {
+ $this->_gemsData = $reload + $this->_gemsData;
+ } else {
+ $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ?";
+ $code = $this->_gemsData['gto_reception_code'];
- if ($row = $this->db->fetchRow($sql, $code)) {
- $this->_gemsData = $row + $this->_gemsData;
- } else {
- $token = $this->_tokenId;
- throw new Gems_Exception("Reception code $code is missing for token $token.");
+ if ($row = $this->db->fetchRow($sql, $code)) {
+ $this->_gemsData = $row + $this->_gemsData;
+ } else {
+ $token = $this->_tokenId;
+ throw new Gems_Exception("Reception code $code is missing for token $token.");
+ }
}
}
}
@@ -973,6 +977,7 @@
/**
*
+ * @deprecated Use the ReceptionCode->hadRedoCode
* @return boolean
*/
public function hasRedoCode()
@@ -987,6 +992,7 @@
/**
* True if the reception code is a redo survey copy.
*
+ * @deprecated Use the ReceptionCode->hasRedoCopyCode
* @return boolean
*/
public function hasRedoCopyCode()
@@ -995,7 +1001,7 @@
$this->_ensureReceptionCode();
}
- return Gems_Util_Translated::REDO_COPY == $this->_gemsData['grc_redo_survey'];
+ return Gems_Util_ReceptionCodeLibrary::REDO_COPY == $this->_gemsData['grc_redo_survey'];
}
/**
@@ -1101,25 +1107,31 @@
* Set the reception code for this token and make sure the necessary
* cascade to the source takes place.
*
- * @param string $code The new reception code
+ * @param string $code The new (non-success) reception code or a Gems_Util_ReceptionCode object
* @param string $comment Comment False values leave value unchanged
* @param int $userId The current user
* @return int 1 if the token has changed, 0 otherwise
*/
public function setReceptionCode($code, $comment, $userId)
{
- $values['gto_reception_code'] = $code;
+ // Make sure it is a Gems_Util_ReceptionCode object
+ if (! $code instanceof Gems_Util_ReceptionCode) {
+ $code = $this->util->getReceptionCode($code);
+ }
+
+ $values['gto_reception_code'] = $code->getCode();
if ($comment) {
$values['gto_comment'] = $comment;
}
+ MUtil_Echo::track($values);
$changed = $this->_updateToken($values, $userId);
if ($changed) {
// Reload reception code values
- $this->_ensureReceptionCode(true);
+ $this->_ensureReceptionCode($code->getAllData());
- if (! $this->hasSuccesCode()) {
+ if ($code->isOverwriter() || (! $code->isSuccess())) {
$survey = $this->getSurvey();
// Update the consent code in the source
Modified: trunk/library/classes/Gems/Tracker.php
===================================================================
--- trunk/library/classes/Gems/Tracker.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Tracker.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -331,6 +331,27 @@
/**
*
+ * @param int $userId
+ * @param int $organizationId
+ * @return array of Gems_Tracker_RespondentTrack
+ */
+ public function getRespondentTracks($userId, $organizationId)
+ {
+ $sql = "SELECT *
+ FROM gems__respondent2track INNER JOIN gems__reception_codes ON gr2t_reception_code = grc_id_reception_code
+ WHERE gr2t_id_user = ? AND gr2t_id_organization = ?";
+ $rows = $this->db->fetchAll($sql, array($userId, $organizationId));
+ $tracks = array();
+
+ foreach ($rows as $row) {
+ $tracks[$row['gr2t_id_respondent_track']] = $this->getRespondentTrack($row);
+ }
+
+ return $tracks;
+ }
+
+ /**
+ *
* @param mixed $respTrackData Track id or array containing trackdata
* @return Gems_Tracker_RespondentTrack
*/
Modified: trunk/library/classes/Gems/User/Organization.php
===================================================================
--- trunk/library/classes/Gems/User/Organization.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/User/Organization.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -46,9 +46,16 @@
* @license New BSD License
* @since Class available since version 1.5
*/
-class Gems_User_Organization extends Gems_Registry_TargetAbstract
+class Gems_User_Organization extends Gems_Registry_CachedArrayTargetAbstract
{
/**
+ * Variable to add tags to the cache for cleanup.
+ *
+ * @var array
+ */
+ protected $_cacheTags = array('organization');
+
+ /**
* The default organization data for 'no organization'.
*
* @var array
@@ -56,16 +63,6 @@
protected $_noOrganization = array(
'gor_id_organization' => 1,
'gor_name' => 'NO ORGANIZATION',
- 'gor_code' => null,
- 'gor_location' => null,
- 'gor_url' => null,
- 'gor_task' => null,
- 'gor_accessible_by' => null,
- 'gor_contact_name' => null,
- 'gor_contact_email' => null,
- 'gor_welcome' => null,
- 'gor_signature' => null,
- 'gor_style' => null,
'gor_iso_lang' => 'en',
'gor_has_respondents' => 0,
'gor_add_respondents' => 0,
@@ -75,39 +72,11 @@
/**
*
- * @var array
- */
- protected $_organizationData;
-
- /**
- *
- * @var int
- */
- protected $_organizationId;
-
- /**
- *
- * @var Zend_Cache_Core
- */
- protected $cache;
-
- /**
- *
* @var Zend_Db_Adapter_Abstract
*/
protected $db;
/**
- * Creates the organization object.
- *
- * @param int $organizationId
- */
- public function __construct($organizationId)
- {
- $this->_organizationId = $organizationId;
- }
-
- /**
* Returns a callable if a method is called as a variable
* or the value from the organizationData if it exists
*
@@ -116,26 +85,14 @@
*/
public function __get($name)
{
- if (method_exists($this, $name)) {
- // Return a callable
- return array($this, $name);
- } elseif (isset($this->_organizationData[$name])) {
- return $this->_organizationData[$name];
+ if (isset($this->_data[$name])) {
+ return $this->_data[$name];
}
- throw new Gems_Exception_Coding("Unknown method '$name' requested as callable.");
+ return parent::__get($name);
}
/**
- * Get the cacheId for the organization
- *
- * @return string
- */
- private function _getCacheId() {
- return GEMS_PROJECT_NAME . '__' . __CLASS__ . '__' . $this->_organizationId;
- }
-
- /**
* Set menu parameters from the organization
*
* @param Gems_Menu_ParameterSource $source
@@ -153,7 +110,7 @@
*/
public function canCreateRespondents()
{
- return (boolean) $this->_organizationData['gor_add_respondents'];
+ return (boolean) $this->_get('gor_add_respondents');
}
/**
@@ -163,62 +120,17 @@
*/
public function canHaveRespondents()
{
- return (boolean) $this->_organizationData['gor_has_respondents'] || $this->_organizationData['gor_add_respondents'];
+ return (boolean) $this->_get('gor_has_respondents') || $this->_get('gor_add_respondents');
}
/**
- * Should be called after answering the request to allow the Target
- * to check if all required registry values have been set correctly.
- *
- * @return boolean False if required are missing.
- */
- public function checkRegistryRequestsAnswers()
- {
- if ($this->cache) {
- $cacheId = $this->_getCacheId();
- $this->_organizationData = $this->cache->load($cacheId);
- } else {
- $cacheId = false;
- }
-
- if (! $this->_organizationData) {
- $sql = "SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1";
- $this->_organizationData = $this->db->fetchRow($sql, $this->_organizationId);
-
- if (! $this->_organizationData) {
- $this->_organizationData = $this->_noOrganization;
- } else {
- $dbOrgId = $this->db->quote($this->_organizationId, Zend_Db::INT_TYPE);
- $sql = "SELECT gor_id_organization, gor_name
- FROM gems__organizations
- WHERE gor_active = 1 AND
- (
- gor_id_organization = $dbOrgId OR
- gor_accessible_by LIKE '%:$dbOrgId:%'
- )
- ORDER BY gor_name";
- $this->_organizationData['can_access'] = $this->db->fetchPairs($sql);
-
- // MUtil_Echo::track($sql, $this->_organizationData['can_access']);
- }
-
- if ($cacheId) {
- $this->cache->save($this->_organizationData, $cacheId);
- }
- }
- // MUtil_Echo::track($this->_organizationData);
-
- return is_array($this->_organizationData) && parent::checkRegistryRequestsAnswers();
- }
-
- /**
* Get the organizations this organizations can access.
*
* @return array Of type orgId => orgName
*/
public function getAllowedOrganizations()
{
- return $this->_organizationData['can_access'];
+ return $this->_get('can_access');
}
/**
@@ -228,7 +140,7 @@
*/
public function getCode()
{
- return $this->_organizationData['gor_code'];
+ return $this->_get('gor_code');
}
/**
@@ -238,7 +150,7 @@
*/
public function getId()
{
- return $this->_organizationData['gor_id_organization'];
+ return $this->_get('gor_id_organization');
}
/**
@@ -248,7 +160,7 @@
*/
public function getName()
{
- return $this->_organizationData['gor_name'];
+ return $this->_get('gor_name');
}
/**
@@ -258,7 +170,7 @@
*/
public function getSignature()
{
- return $this->_organizationData['gor_signature'];
+ return $this->_get('gor_signature');
}
/**
@@ -268,30 +180,49 @@
*/
public function getStyle()
{
- return $this->_organizationData['gor_style'];
+ return $this->_get('gor_style');
}
/**
- * Get the welcome message for the organization.
+ * Load the data when the cache is empty.
*
- * @return string
+ * @param mixed $id
+ * @return array The array of data values
*/
- public function getWelcome()
+ protected function loadData($id)
{
- return $this->_organizationData['gor_welcome'];
+ $sql = "SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1";
+ $data = $this->db->fetchRow($sql, $id);
+
+ if ($data) {
+ $dbOrgId = $this->db->quote($id, Zend_Db::INT_TYPE);
+ $sql = "SELECT gor_id_organization, gor_name
+ FROM gems__organizations
+ WHERE gor_active = 1 AND
+ (
+ gor_id_organization = $dbOrgId OR
+ gor_accessible_by LIKE '%:$dbOrgId:%'
+ )
+ ORDER BY gor_name";
+ $data['can_access'] = $this->db->fetchPairs($sql);
+ natsort($data['can_access']);
+
+ // MUtil_Echo::track($sql, $data['can_access']);
+ } else {
+ $data = $this->_noOrganization;
+ }
+
+ return $data;
}
/**
- * Empty the cache of the organization
+ * Get the welcome message for the organization.
*
- * @return Gems_User_Organization (continutation pattern)
+ * @return string
*/
- public function invalidateCache() {
- if ($this->cache) {
- $cacheId = $this->_getCacheId();
- $this->cache->remove($cacheId);
- }
- return $this;
+ public function getWelcome()
+ {
+ return $this->_get('gor_welcome');
}
/**
@@ -304,17 +235,17 @@
*/
public function setHasRespondents($userId)
{
- if (0 == $this->_organizationData['gor_has_respondents']) {
- $this->_organizationData['gor_has_respondents'] = 1;
-
+ if (! $this->_get('gor_has_respondents')) {
$values['gor_has_respondents'] = 1;
$values['gor_changed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
$values['gor_changed_by'] = $userId;
- $where = $this->db->quoteInto('gor_id_organization = ?', $this->_organizationId);
+ $where = $this->db->quoteInto('gor_id_organization = ?', $this->_id);
$this->db->update('gems__organizations', $values, $where);
- $this->invalidateCache();
+
+ // Invalidate cache / change value
+ $this->_set('gor_has_respondents', 1);
}
return $this;
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/User/User.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -648,10 +648,10 @@
// Privilege overrules organizational settings
if ($this->hasPrivilege('pr.organization-switch')) {
$orgs = $this->db->fetchPairs("SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active = 1 ORDER BY gor_name");
+ natsort($orgs);
} else {
$orgs = $this->getBaseOrganization()->getAllowedOrganizations();
}
- natsort($orgs);
// MUtil_Echo::track($orgs);
$this->_setVar('__allowedOrgs', $orgs);
Added: trunk/library/classes/Gems/Util/ReceptionCode.php
===================================================================
--- trunk/library/classes/Gems/Util/ReceptionCode.php (rev 0)
+++ trunk/library/classes/Gems/Util/ReceptionCode.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -0,0 +1,175 @@
+<?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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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 Gems
+ * @subpackage Ytil
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Utility function for the user of reception codes.
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Util_ReceptionCode extends Gems_Registry_CachedArrayTargetAbstract
+{
+ /**
+ * Variable to add tags to the cache for cleanup.
+ *
+ * @var array
+ */
+ protected $_cacheTags = array('reception_code');
+
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ * Returns the complete record.
+ *
+ * @return array
+ */
+ public function getAllData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * The reception code.
+ *
+ * @return string
+ */
+ public function getCode()
+ {
+ return $this->_id;
+ }
+
+ /**
+ *
+ * @return boolean
+ */
+ public function hasRedoCode()
+ {
+ return (boolean) $this->_get('grc_redo_survey');
+ }
+
+ /**
+ * True if the reception code is a redo survey copy.
+ *
+ * @return boolean
+ */
+ public function hasRedoCopyCode()
+ {
+ return Gems_Util_ReceptionCodeLibrary::REDO_COPY == $this->_get('grc_redo_survey');
+ }
+
+ /**
+ * Is this code for respondent use?
+ *
+ * @return boolean
+ */
+ public function isForRespondents()
+ {
+ return (boolean) $this->_get('grc_for_respondents');
+ }
+
+ /**
+ * Is this code for track use?
+ *
+ * @return boolean
+ */
+ public function isForTracks()
+ {
+ return (boolean) $this->_get('grc_for_tracks');
+ }
+
+ /**
+ * Is this code for survey use?
+ *
+ * @return boolean
+ */
+ public function isForSurveys()
+ {
+ return $this->_get('grc_for_surveys') > Gems_Util_ReceptionCodeLibrary::APPLY_NOT;
+ }
+
+ /**
+ * Does this code overwrite set values?
+ *
+ * @return boolean
+ */
+ public function isOverwriter()
+ {
+ return (boolean) $this->_get('grc_overwrite_answers');
+ }
+
+ /**
+ * Is this code a survey stop code.
+ *
+ * Then do not apply it to the track or respondent, but do apply it to the tokens.
+ *
+ * @return boolean
+ */
+ public function isStopCode()
+ {
+ // MUtil_Echo::track($this->_data);
+ return $this->_get('grc_for_surveys') === Gems_Util_ReceptionCodeLibrary::APPLY_STOP;
+ }
+
+ /**
+ * Is this code a success code.
+ *
+ * @return boolean
+ */
+ public function isSuccess()
+ {
+ return (boolean) $this->_get('grc_success');
+ }
+
+ /**
+ * Load the data when the cache is empty.
+ *
+ * @param mixed $id
+ * @return array The array of data values
+ */
+ protected function loadData($id)
+ {
+ $sql = "SELECT * FROM gems__reception_codes WHERE grc_id_reception_code = ? LIMIT 1";
+ return $this->db->fetchRow($sql, $id);
+ }
+}
Added: trunk/library/classes/Gems/Util/ReceptionCodeLibrary.php
===================================================================
--- trunk/library/classes/Gems/Util/ReceptionCodeLibrary.php (rev 0)
+++ trunk/library/classes/Gems/Util/ReceptionCodeLibrary.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -0,0 +1,170 @@
+<?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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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 Gems
+ * @subpackage Util
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Library functions and constants for working with reception codes.
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Util_ReceptionCodeLibrary extends Gems_Registry_TargetAbstract
+{
+ const APPLY_NOT = 0;
+ const APPLY_DO = 1;
+ const APPLY_STOP = 2;
+
+ const REDO_NONE = 0;
+ const REDO_ONLY = 1;
+ const REDO_COPY = 2;
+
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ *
+ * @var Zend_Translate
+ */
+ protected $translate;
+
+ /**
+ *
+ * @return Zend_Db_Select for a fetchPairs
+ */
+ protected function _getDeletionCodeSelect()
+ {
+ $select = $this->db->select();
+ $select->from('gems__reception_codes', array('grc_id_reception_code', 'grc_description'))
+ ->where('grc_active = 1')
+ ->order('grc_description');
+
+ return $select;
+ }
+
+ /**
+ * Return the field values for the redo code.
+ *
+ * <ul><li>0: do not redo</li>
+ * <li>1: redo but do not copy answers</li>
+ * <li>2: redo and copy answers</li></ul>
+ *
+ * @staticvar array $data
+ * @return array
+ */
+ public function getRedoValues()
+ {
+ static $data;
+
+ if (! $data) {
+ $data = array(
+ self::REDO_NONE => $this->translate->_('No'),
+ self::REDO_ONLY => $this->translate->_('Yes (forget answers)'),
+ self::REDO_COPY => $this->translate->_('Yes (keep answers)'));
+ }
+
+ return $data;
+ }
+
+ /**
+ * Return the field values for surveys.
+ *
+ * <ul><li>0: do not use</li>
+ * <li>1: use (and cascade)</li>
+ * <li>2: use for open rounds only</li></ul>
+ *
+ * @staticvar array $data
+ * @return array
+ */
+ public function getSurveyApplicationValues()
+ {
+ static $data;
+
+ if (! $data) {
+ $data = array(
+ self::APPLY_NOT => $this->translate->_('No'),
+ self::APPLY_DO => $this->translate->_('Yes (individual surveys only)'),
+ self::APPLY_STOP => $this->translate->_('Stop (per respondent or track only)'));
+ }
+
+ return $data;
+ }
+
+ /**
+ * Returns the respondent deletion reception code list.
+ *
+ * @return array a value => label array.
+ */
+ public function getRespondentDeletionCodes()
+ {
+ $select = $this->_getDeletionCodeSelect();
+ $select->where('(grc_for_respondents = 1 OR grc_for_surveys = ?)', self::APPLY_STOP);
+
+ return $this->db->fetchPairs($select);
+ }
+
+ /**
+ * Returns the single survey deletion reception code list.
+ *
+ * @return array a value => label array.
+ */
+ public function getSingleSurveyDeletionCodes()
+ {
+ $select = $this->_getDeletionCodeSelect();
+ $select->where('(grc_for_surveys = ? OR grc_for_tracks = 1)', self::APPLY_DO)
+ ->where('grc_redo_survey = ?', self::REDO_NONE);
+
+ return $this->db->fetchPairs($select);
+ }
+
+ /**
+ * Returns the track deletion reception code list.
+ *
+ * @return array a value => label array.
+ */
+ public function getTrackDeletionCodes()
+ {
+ $select = $this->_getDeletionCodeSelect();
+ $select->where('(grc_for_tracks = 1 OR grc_for_surveys = ?)', self::APPLY_STOP);
+
+ return $this->db->fetchPairs($select);
+ }
+}
Modified: trunk/library/classes/Gems/Util/Translated.php
===================================================================
--- trunk/library/classes/Gems/Util/Translated.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Util/Translated.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -1,4 +1,5 @@
<?php
+
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
@@ -42,10 +43,6 @@
*/
class Gems_Util_Translated extends Gems_Registry_TargetAbstract
{
- const REDO_NONE = 0;
- const REDO_ONLY = 1;
- const REDO_COPY = 2;
-
protected $phpDateFormatString = 'd-m-Y';
/**
@@ -211,27 +208,6 @@
return array('M' => $this->_('Mr.'), 'F' => $this->_('Mrs.'), 'U' => $this->_('Mr./Mrs.'));
}
- /**
- * Return the field values for the redo code.
- *
- * <ul><li>0: do not redo</li>
- * <li>1: redo but do not copy answers</li>
- * <li>2: redo and copy answers</li></ul>
- *
- * @staticvar array $data
- * @return array
- */
- public function getRedoCodes()
- {
- static $data;
-
- if (! $data) {
- $data = array(self::REDO_NONE => $this->_('No'), self::REDO_ONLY => $this->_('Yes (forget answers)'), self::REDO_COPY => $this->_('Yes (keep answers)'));
- }
-
- return $data;
- }
-
public function getYesNo()
{
static $data;
Modified: trunk/library/classes/Gems/Util.php
===================================================================
--- trunk/library/classes/Gems/Util.php 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/classes/Gems/Util.php 2011-11-28 18:24:32 UTC (rev 301)
@@ -79,6 +79,12 @@
/**
*
+ * @var Gems_Util_ReceptionCodeLibrary
+ */
+ protected $receptionCodeLibrary;
+
+ /**
+ *
* @var Gems_Util_RequestCache
*/
protected $requestCache;
@@ -188,7 +194,34 @@
}
/**
+ * Returns a single reception code object.
*
+ * @param string $code
+ * @return Gems_Util_ReceptionCode
+ */
+ public function getReceptionCode($code)
+ {
+ static $codes = array();
+
+ if (! isset($codes[$code])) {
+ $codes[$code] = $this->_loadClass('receptionCode', true, array($code));
+ }
+
+ return $codes[$code];
+ }
+
+ /**
+ * Returns a
+ *
+ * @return Gems_Util_ReceptionCodeLibrary
+ */
+ public function getReceptionCodeLibrary()
+ {
+ return $this->_getClass('receptionCodeLibrary');
+ }
+
+ /**
+ *
* @param string $sourceAction The action to get the cache from if not the current one.
* @param boolean $readonly Optional, tell the cache not to store any new values
* @return Gems_Util_RequestCache
@@ -215,15 +248,15 @@
{
return $this->_getClass('translated');
}
-
+
/**
* Checks if a given IP is allowed according to a set
* of IP addresses / ranges.
- *
+ *
* Multiple addresses/ranges are separated by a colon,
* an individual range takes the form of
* 10.0.0.0-10.0.0.255 (subnet masks are not supported)
- *
+ *
* @param string $ip
* @param string $ipRanges
* @return bool
@@ -233,23 +266,23 @@
if (!strlen($ipRanges)) {
return true;
}
-
+
$ipLong = ip2long($ip);
-
+
$ranges = explode('|', $ipRanges);
-
+
foreach ($ranges as $range) {
if (($sep = strpos($range, '-')) !== false) {
$min = ip2long(substr($range, 0, $sep));
$max = ip2long(substr($range, $sep + 1));
-
+
$validate = new Zend_Validate_Between(
array(
'min' => $min,
'max' => $max
)
);
-
+
if ($min <= $ipLong && $ipLong <= $max) {
return true;
}
@@ -259,7 +292,7 @@
}
}
}
-
+
return false;
}
}
Modified: trunk/library/configs/db/patches.sql
===================================================================
--- trunk/library/configs/db/patches.sql 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/configs/db/patches.sql 2011-11-28 18:24:32 UTC (rev 301)
@@ -344,3 +344,10 @@
-- PATCH: Base URL / installation URL to facilitate org switching
ALTER TABLE gems__organizations ADD `gor_url_base` VARCHAR(1270) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null AFTER `gor_url`;
+
+-- PATCH: New fundamental reception code 'STOP'
+INSERT INTO gems__reception_codes (grc_id_reception_code, grc_description, grc_success,
+ grc_for_surveys, grc_redo_survey, grc_for_tracks, grc_for_respondents, grc_overwrite_answers, grc_active,
+ grc_changed, grc_changed_by, grc_created, grc_created_by)
+ VALUES
+ ('stop', 'Stop surveys', 0, 2, 0, 0, 0, 0, 1, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1);
Modified: trunk/library/configs/db/tables/gems__reception_codes.10.sql
===================================================================
--- trunk/library/configs/db/tables/gems__reception_codes.10.sql 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/configs/db/tables/gems__reception_codes.10.sql 2011-11-28 18:24:32 UTC (rev 301)
@@ -5,7 +5,7 @@
grc_success boolean not null default 0,
- grc_for_surveys boolean not null default 0,
+ grc_for_surveys tinyint not null default 0,
grc_redo_survey tinyint not null default 0,
grc_for_tracks boolean not null default 0,
grc_for_respondents boolean not null default 0,
@@ -25,9 +25,9 @@
CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
INSERT INTO gems__reception_codes (grc_id_reception_code, grc_description, grc_success,
- grc_for_surveys, grc_redo_survey, grc_for_tracks, grc_for_respondents, grc_active,
+ grc_for_surveys, grc_redo_survey, grc_for_tracks, grc_for_respondents, grc_overwrite_answers, grc_active,
grc_changed, grc_changed_by, grc_created, grc_created_by)
VALUES
- ('OK', '', 1, 1, 0, 1, 1, 1, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1),
- ('skip', 'Skipped by calculation', 0, 1, 0, 0, 0, 0, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1);
-
+ ('OK', '', 1, 1, 0, 1, 1, 0, 1, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1),
+ ('skip', 'Skipped by calculation', 0, 1, 0, 0, 0, 1, 0, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1),
+ ('stop', 'Stop surveys', 0, 2, 0, 0, 0, 0, 1, CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP, 1);
Modified: trunk/library/languages/default-en.mo
===================================================================
(Binary files differ)
Modified: trunk/library/languages/default-en.po
===================================================================
--- trunk/library/languages/default-en.po 2011-11-28 15:20:01 UTC (rev 300)
+++ trunk/library/languages/default-en.po 2011-11-28 18:24:32 UTC (rev 301)
@@ -2,7 +2,7 @@
msgstr ""
"Project-Id-Version: Pulse EN\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-11-28 12:25+0100\n"
+"POT-Creation-Date: 2011-11-28 19:14+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Matijs de Jong <mj...@ma...>\n"
"Language-Team: Erasmus MGZ <mat...@ma...>\n"
@@ -409,7 +409,7 @@
msgid " The error message is: %s"
msgstr " The error message is: %s"
-#: classes/Gems/Tracker.php:732
+#: classes/Gems/Tracker.php:753
msgid "Checks performed"
msgstr "Checks performed"
@@ -1023,7 +1023,7 @@
msgstr "%s records found."
#: classes/Gems/Default/ExportAction.php:172
-#: classes/Gems/Default/IndexAction.php:179
+#: classes/Gems/Default/IndexAction.php:192
#: classes/Gems/Default/MailJobAction.php:119
msgid "Organization"
msgstr "Organization"
@@ -1056,88 +1056,88 @@
msgid "Administrative groups"
msgstr "Administrative groups"
-#: classes/Gems/Default/IndexAction.php:91
+#: classes/Gems/Default/IndexAction.php:97
msgid "Enter your token..."
msgstr "Enter your token..."
-#: classes/Gems/Default/IndexAction.php:132
+#: classes/Gems/Default/IndexAction.php:140
#, php-format
msgid "Login to %s application"
msgstr "Login to %s application"
-#: classes/Gems/Default/IndexAction.php:136
+#: classes/Gems/Default/IndexAction.php:144
msgid "Login"
msgstr "Login"
-#: classes/Gems/Default/IndexAction.php:153
+#: classes/Gems/Default/IndexAction.php:166
msgid "Back to login"
msgstr "Back to login"
-#: classes/Gems/Default/IndexAction.php:201
+#: classes/Gems/Default/IndexAction.php:214
msgid "Password"
msgstr "Password"
-#: classes/Gems/Default/IndexAction.php:216
+#: classes/Gems/Default/IndexAction.php:229
#, php-format
msgid "Reset password for %s application"
msgstr "Reset password for %s application"
-#: classes/Gems/Default/IndexAction.php:220
+#: classes/Gems/Default/IndexAction.php:233
msgid "Reset password"
msgstr "Reset password"
-#: classes/Gems/Default/IndexAction.php:266
+#: classes/Gems/Default/IndexAction.php:279
msgid "Username"
msgstr "Username"
-#: classes/Gems/Default/IndexAction.php:306
+#: classes/Gems/Default/IndexAction.php:333
msgid "Your password must be changed."
msgstr "Your password must be changed."
-#: classes/Gems/Default/IndexAction.php:318
+#: classes/Gems/Default/IndexAction.php:345
#, php-format
msgid "Login successful, welcome %s."
msgstr "Login successful, welcome %s."
-#: classes/Gems/Default/IndexAction.php:358
+#: classes/Gems/Default/IndexAction.php:385
#, php-format
msgid "Good bye: %s."
msgstr "Good bye: %s."
-#: classes/Gems/Default/IndexAction.php:383
+#: classes/Gems/Default/IndexAction.php:410
msgid "Reset accepted, enter your new password."
msgstr "Reset accepted, enter your new password."
-#: classes/Gems/Default/IndexAction.php:387
+#: classes/Gems/Default/IndexAction.php:414
msgid "This key timed out or does not belong to this user."
msgstr "This key timed out or does not belong to this user."
-#: classes/Gems/Default/IndexAction.php:404
+#: classes/Gems/Default/IndexAction.php:431
msgid "Password reset requested"
msgstr "Password reset requested"
-#: classes/Gems/Defau...
[truncated message content] |