|
From: <gem...@li...> - 2012-04-05 15:50:42
|
Revision: 599
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=599&view=rev
Author: matijsdejong
Date: 2012-04-05 15:50:36 +0000 (Thu, 05 Apr 2012)
Log Message:
-----------
New survey return mechanism that allows more flexible return mechanism
Database patches now sorted on date changed, plus more cache cleanup for database objects
Modified Paths:
--------------
trunk/library/classes/Gems/Default/AskAction.php
trunk/library/classes/Gems/Default/DatabaseAction.php
trunk/library/classes/Gems/Default/RespondentAction.php
trunk/library/classes/Gems/Default/TrackActionAbstract.php
trunk/library/classes/Gems/User/User.php
Modified: trunk/library/classes/Gems/Default/AskAction.php
===================================================================
--- trunk/library/classes/Gems/Default/AskAction.php 2012-04-05 14:29:54 UTC (rev 598)
+++ trunk/library/classes/Gems/Default/AskAction.php 2012-04-05 15:50:36 UTC (rev 599)
@@ -272,46 +272,25 @@
public function returnAction()
{
- if (isset($this->session->user_id) && $this->session->user_id) {
+ $user = $this->loader->getCurrentUser();
+
+ if ($user->isActive()) {
$tracker = $this->loader->getTracker();
$token = $tracker->getToken($tracker->filterToken($this->_getParam(MUtil_Model::REQUEST_ID)));
// Check for completed tokens
- $this->loader->getTracker()->processCompletedTokens($token->getRespondentId(), $this->session->user_id);
+ $this->loader->getTracker()->processCompletedTokens($token->getRespondentId(), $user->getUserId());
- if (isset($this->session->return_controller) && $this->session->return_controller) {
- $return = $this->session->return_controller;
- } else {
- $return = 'respondent';
+ $parameters = $user->getSurveyReturn();
+ if (! $parameters) {
+ // Default
+ $request = $this->getRequest();
+ $parameters[$request->getControllerKey()] = 'respondent';
+ $parameters[$request->getActionKey()] = 'show';
+ $parameters[MUtil_Model::REQUEST_ID] = $token->getPatientNumber();
}
- $parameters['controller'] = $return;
- $parameters['action'] = 'show';
- $parameters[MUtil_Model::REQUEST_ID] = $token->getPatientNumber();
- switch ($return) {
- case 'track':
- $parameters['action'] = 'show-track';
- $parameters[Gems_Model::RESPONDENT_TRACK] = $token->getRespondentTrackId();
- break;
-
- case 'survey':
- $parameters[MUtil_Model::REQUEST_ID] = $token->getTokenId();
- break;
-
- case 'ask':
- $this->_forward('forward');
- return;
-
- default:
- // Allow open specification of return
- if (strpos($return, '/') !== false) {
- $parameters = MUtil_Ra::pairs(explode('/', $return));
- // MUtil_Echo::track($parameters);
- } else {
- $parameters['controller'] = 'respondent';
- }
- }
- $this->_reroute($parameters, true);
+ $this->_reroute($parameters, true);
} else {
$this->_forward('forward');
}
Modified: trunk/library/classes/Gems/Default/DatabaseAction.php
===================================================================
--- trunk/library/classes/Gems/Default/DatabaseAction.php 2012-04-05 14:29:54 UTC (rev 598)
+++ trunk/library/classes/Gems/Default/DatabaseAction.php 2012-04-05 15:50:36 UTC (rev 599)
@@ -61,6 +61,22 @@
}
/**
+ * Make sure the cache is cleaned.
+ *
+ * As a lot of cache depends on the database, it is best to clean the cache
+ * now since import tables might have changed.
+ *
+ * @return void
+ */
+ private function _cleanCache()
+ {
+ if ($this->cache instanceof Zend_Cache_Core) {
+ $this->cache->clean();
+ $this->addMessage($this->_('Cache cleaned'));
+ }
+ }
+
+ /**
* Adds elements from the model to the bridge that creates the form.
*
* Overrule this function to add different elements to the browse table, without
@@ -181,6 +197,7 @@
try {
$stmt = $this->db->query($sql);
$this->addMessage(sprintf($this->_('%1$s %2$s dropped'), $data['name'], $this->_(strtolower($data['type']))));
+ $this->_cleanCache();
$model->save(array('exists' => false), $model->getFilter());
@@ -266,13 +283,14 @@
$patcher = new Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths());
$changed = $patcher->uploadPatches($this->loader->getVersions()->getBuild());
$tableSql = sprintf(
- 'SELECT gpa_level AS `%s`, gpa_location AS `%s`, COUNT(*) AS `%s`, COUNT(*) - SUM(gpa_executed) AS `%s`, SUM(gpa_executed) AS `%s`, SUM(gpa_completed) AS `%s` FROM gems__patches GROUP BY gpa_level, gpa_location ORDER BY gpa_level DESC, gpa_location',
+ 'SELECT gpa_level AS `%s`, gpa_location AS `%s`, COUNT(*) AS `%s`, COUNT(*) - SUM(gpa_executed) AS `%s`, SUM(gpa_executed) AS `%s`, SUM(gpa_completed) AS `%s`, MAX(gpa_changed) AS `%s` FROM gems__patches GROUP BY gpa_level, gpa_location ORDER BY gpa_level DESC, gpa_location',
$this->_('Level'),
$this->_('Subtype'),
$this->_('Patches'),
$this->_('To be executed'),
$this->_('Executed'),
- $this->_('Finished'));
+ $this->_('Finished'),
+ $this->_('Changed on'));
if ($changed == -1) {
$this->addMessage($this->_('Create the patch table!'));
@@ -306,18 +324,11 @@
$form->getElement('db_level')->setValue($data['db_level']);
$this->addMessage(sprintf($this->_('%d patch(es) executed.'), $changed));
-
- //As a lot of cache depends on the database, it is best to clean the cache now
- //since import tables might have changed
- $cache = $this->escort->cache;
- if ($cache instanceof Zend_Cache_Core) {
- $cache->clean();
- $this->addMessage($this->_('Cache cleaned'));
- }
+ $this->_cleanCache();
}
$tableSql = sprintf(
- 'SELECT gpa_id_patch AS `%s`, gpa_level AS `%s`, gpa_location AS `%s`, gpa_name AS `%s`, gpa_sql AS `%s`, gpa_executed AS `%s`, gpa_completed AS `%s`, gpa_result as `%s` FROM gems__patches WHERE gpa_level = ? ORDER BY gpa_level, gpa_location, gpa_name, gpa_order',
+ 'SELECT gpa_id_patch AS `%s`, gpa_level AS `%s`, gpa_location AS `%s`, gpa_name AS `%s`, gpa_sql AS `%s`, gpa_executed AS `%s`, gpa_completed AS `%s`, gpa_result AS `%s`, gpa_changed AS `%s` FROM gems__patches WHERE gpa_level = ? ORDER BY gpa_level, gpa_changed DESC, gpa_location, gpa_name, gpa_order',
$this->_('Patch'),
$this->_('Level'),
$this->_('Subtype'),
@@ -325,7 +336,8 @@
$this->_('Query'),
$this->_('Executed'),
$this->_('Finished'),
- $this->_('Result'));
+ $this->_('Result'),
+ $this->_('Changed on'));
$tableSql = $this->db->quoteInto($tableSql, $form->getValue('level'));
}
@@ -439,6 +451,7 @@
$results = $model->runScript($data);
$this->addMessage($results);
+ $this->_cleanCache();
$this->_reroute(array('action' => 'show'));
}
}
@@ -461,10 +474,12 @@
$results[] = sprintf($this->_('Finished %s creation script for object %d of %d'), $this->_(strtolower($data['type'])), $i, $oCount) . '<br/>';
$i++;
}
+
} else {
$results[] = $this->_('All objects exist. Nothing was executed.');
}
$this->addMessage($results);
+ $this->_cleanCache();
$this->_reroute(array('action' => 'index'), true);
}
Modified: trunk/library/classes/Gems/Default/RespondentAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentAction.php 2012-04-05 14:29:54 UTC (rev 598)
+++ trunk/library/classes/Gems/Default/RespondentAction.php 2012-04-05 15:50:36 UTC (rev 599)
@@ -355,7 +355,8 @@
{
parent::init();
- $this->session->return_controller = $this->getRequest()->getControllerName();
+ // Tell the system where to return to after a survey has been taken
+ $this->loader->getCurrentUser()->setSurveyReturn($this->getRequest());
}
protected function openedRespondent($patientId, $orgId = null, $userId = null)
Modified: trunk/library/classes/Gems/Default/TrackActionAbstract.php
===================================================================
--- trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-04-05 14:29:54 UTC (rev 598)
+++ trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-04-05 15:50:36 UTC (rev 599)
@@ -365,7 +365,8 @@
{
parent::init();
- $this->session->return_controller = $this->getRequest()->getControllerName();
+ // Tell the system where to return to after a survey has been taken
+ $this->loader->getCurrentUser()->setSurveyReturn($this->getRequest());
}
public function initFilter()
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2012-04-05 14:29:54 UTC (rev 598)
+++ trunk/library/classes/Gems/User/User.php 2012-04-05 15:50:36 UTC (rev 599)
@@ -846,6 +846,16 @@
}
/**
+ * get the parameters where the survey should return to
+ *
+ * @return array
+ */
+ public function getSurveyReturn()
+ {
+ return $this->_getVar('surveyReturn', array());
+ }
+
+ /**
* Returns the user id, that identifies this user within this installation.
*
* One user id might be connected to multiple logins for multiple organizations.
@@ -1317,6 +1327,25 @@
}
/**
+ * Set the parameters where the survey should return to
+ *
+ * @param mixed $return Zend_Controller_Request_Abstract, array of something that can be turned into one.
+ * @return Gems_User_User
+ */
+ public function setSurveyReturn($return)
+ {
+ if ($return instanceof Zend_Controller_Request_Abstract) {
+ $return = $return->getParams();
+ } elseif (! is_array($return)) {
+ $return = MUtil_Ra::to($return);
+ }
+
+ $this->_setVar('surveyReturn', $return);
+
+ return $this;
+ }
+
+ /**
* Unsets this user as the current user.
*
* This means that the data about this user will no longer be stored in a session.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|