From: <gem...@li...> - 2011-10-31 09:46:37
|
Revision: 155 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=155&view=rev Author: matijsdejong Date: 2011-10-31 09:46:30 +0000 (Mon, 31 Oct 2011) Log Message: ----------- Fix for ticket #32: fieldmap cache crashes with the language 'nl-informal'. AddTrackSnippet can now handle organization switches correctly. Made it easier to write your own AnswerModel. Small fixes for #31 Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php trunk/library/configs/db/patches.sql trunk/library/snippets/AddTracksSnippet.php trunk/library/snippets/AnswerModelSnippet.php trunk/library/snippets/TrackAnswersModelSnippet.php Added Paths: ----------- trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-10-31 09:46:30 UTC (rev 155) @@ -209,9 +209,9 @@ $adapter->setIdentity($userid); $adapter->setCredential(md5($_POST['password'], false)); $result = $auth->authenticate($adapter, $_POST['userlogin']); - MUtil_Echo::track('old autho'); + // MUtil_Echo::track('old autho'); } else { - MUtil_Echo::track('new autho'); + // MUtil_Echo::track('new autho'); } if (!$result->isValid()) { Added: trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php (rev 0) +++ trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2011-10-31 09:46:30 UTC (rev 155) @@ -0,0 +1,229 @@ +<?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 Tracker + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: AnswerModelSnippet.php 28 2011-09-16 06:24:15Z mennodekker $ + */ + +/** + * Displays answers to a survey. + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Tracker_Snippets_AnswerModelSnippetGeneric extends Gems_Snippets_ModelTableSnippetAbstract +{ + /** + * Set a fixed model sort. + * + * Leading _ means not overwritten by sources. + * + * @var array + */ + protected $_fixedSort = array('gto_round_order' => SORT_ASC); + + /** + * Shortfix to add class attribute + * + * @var string + */ + protected $class = 'browser'; + + /** + * + * @var string Format used for displaying dates. + */ + protected $dateFormat = Zend_Date::DATE_MEDIUM; + + /** + * Required + * + * @var Gems_Loader + */ + protected $loader; + + /** + * Required + * + * @var Zend_Locale + */ + protected $locale; + + /** + * Optional: $request or $tokenData must be set + * + * The display data of the token shown + * + * @var Gems_Tracker_Token + */ + protected $token; + + /** + * Required: id of the selected token to show + * + * @var string + */ + protected $tokenId; + + /** + * Adds columns from the model to the bridge that creates the browse table. + * + * Overrule this function to add different columns to the browse table, without + * having to recode the core table building code. + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @return void + */ + protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) + { + $br = MUtil_Html::create('br'); + $selectedClass = MUtil_Lazy::iff(MUtil_Lazy::comp($bridge->gto_id_token, '==', $this->tokenId), 'selectedColumn', null); + + $bridge->th($this->_('Status')); + $td = $bridge->tdh(MUtil_Lazy::first($bridge->grc_description, $this->_('OK'))); + $td->appendAttrib('class', $selectedClass); + + $bridge->th($this->_('Question')); + $td = $bridge->tdh( + $bridge->gto_round_description, + MUtil_Lazy::iif($bridge->gto_round_description, $br), + MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from) + ); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + + foreach($model->getItemsOrdered() as $name) { + if ($label = $model->get($name, 'label')) { + $bridge->thd($label, array('class' => $model->get($name, 'thClass'))); + $td = $bridge->td($bridge->$name); + + $td->appendAttrib('class', 'answer'); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + } + } + + $bridge->th($this->_('Token')); + $td = $bridge->tdh($bridge->gto_id_token->strtoupper()); + $td->appendAttrib('class', $selectedClass); + $td->appendAttrib('class', $bridge->row_class); + } + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + $model = $this->token->getSurveyAnswerModel($this->locale->getLanguage()); + + $model->set('gto_valid_from', 'dateFormat', $this->dateFormat); + $model->set('gto_completion_time', 'dateFormat', $this->dateFormat); + + return $model; + } + + + /** + * Create the snippets content + * + * This is a stub function either override getHtmlOutput() or override render() + * + * @param Zend_View_Abstract $view Just in case it is needed here + * @return MUtil_Html_HtmlInterface Something that can be rendered + */ + public function getHtmlOutput(Zend_View_Abstract $view) + { + $htmlDiv = MUtil_Html::create()->div(); + + if ($this->tokenId) { + if ($this->token->exists) { + $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); + + $htmlDiv->pInfo(sprintf( + $this->_('Answers for token %s, patient number %s: %s.'), + strtoupper($this->tokenId), + $this->token->getPatientNumber(), + $this->token->getRespondentName())) + ->appendAttrib('class', 'noprint'); + + $table = parent::getHtmlOutput($view); + $table->setPivot(true, 2, 1); + + $this->applyHtmlAttributes($table); + $htmlDiv[] = $table; + + } else { + $htmlDiv->ul(sprintf($this->_('Token %s not found.'), $this->tokenId), array('class' => 'errors')); + } + + } else { + $htmlDiv->ul($this->_('No token specified.'), array('class' => 'errors')); + } + + $buttonDiv = $htmlDiv->buttonDiv(); + $buttonDiv->actionLink(array(), $this->_('Close'), array('onclick' => 'window.close();')); + $buttonDiv->actionLink(array(), $this->_('Print'), array('onclick' => 'window.print();')); + return $htmlDiv; + } + + /** + * The place to check if the data set in the snippet is valid + * to generate the snippet. + * + * When invalid data should result in an error, you can throw it + * here but you can also perform the check in the + * checkRegistryRequestsAnswers() function from the + * {@see MUtil_Registry_TargetInterface}. + * + * @return boolean + */ + public function hasHtmlOutput() + { + if (! $this->tokenId) { + if (isset($this->token)) { + $this->tokenId = $this->token->getTokenId(); + } + } elseif (! $this->token) { + $this->token = $this->loader->getTracker()->getToken($this->tokenId); + } + + // Output always true, returns an error message as html when anything is wrong + return true; + } +} Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2011-10-31 09:46:30 UTC (rev 155) @@ -204,9 +204,10 @@ protected function _getMap() { - $cacheId = 'lsFieldMap'.$this->sourceSurveyId.$this->language; + $cacheId = 'lsFieldMap'.$this->sourceSurveyId.strtr($this->language, '-.', '__'); + $this->_fieldMap = $this->cache->load($cacheId); - if( ($this->_fieldMap = $this->cache->load($cacheId)) === false ) { + if (false === $this->_fieldMap) { $gTable = $this->_getGroupsTableName(); $qTable = $this->_getQuestionsTableName(); @@ -344,7 +345,6 @@ $this->cache->save($this->_fieldMap, $cacheId); } - return $this->_fieldMap; } Modified: trunk/library/configs/db/patches.sql =================================================================== --- trunk/library/configs/db/patches.sql 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/configs/db/patches.sql 2011-10-31 09:46:30 UTC (rev 155) @@ -228,4 +228,8 @@ ALTER TABLE `gems__staff` CHANGE `gsf_id_user` `gsf_id_user` BIGINT( 20 ) UNSIGNED NOT NULL; -ALTER TABLE `gems__staff` DROP INDEX `gsf_login`; \ No newline at end of file +ALTER TABLE `gems__staff` DROP INDEX `gsf_login`; + +ALTER TABLE `gems__staff` CHANGE `gsf_login` `gsf_login` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + CHANGE `gsf_password` `gsf_password` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + CHANGE `gsf_id_organization` `gsf_id_organization` BIGINT( 20 ) NULL DEFAULT NULL; Modified: trunk/library/snippets/AddTracksSnippet.php =================================================================== --- trunk/library/snippets/AddTracksSnippet.php 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/snippets/AddTracksSnippet.php 2011-10-31 09:46:30 UTC (rev 155) @@ -103,10 +103,11 @@ throw new exception('Invalid track type requested.'); } - $trackTypeTime = $trackType . '_time'; + $trackTypeCache = $trackType . '_' . $this->session->user_style; + $trackTypeTime = $trackType . '_time'; - if (isset($this->session->$trackType, $this->session->$trackTypeTime) && (time() < $this->session->$trackTypeTime)) { - $tracks = $this->session->$trackType; + if (isset($this->session->$trackTypeCache, $this->session->$trackTypeTime) && (time() < $this->session->$trackTypeTime)) { + $tracks = $this->session->$trackTypeCache; } else { $organization_id = $this->escort->getCurrentOrganization(); switch ($trackType) { @@ -153,8 +154,8 @@ } $tracks = $this->db->fetchPairs($sql); - $this->session->$trackType = $tracks; - $this->session->$trackTypeTime = time() + 600; + $this->session->$trackTypeCache = $tracks; + $this->session->$trackTypeTime = time() + 600; } $div = MUtil_Html::create()->div(array('class' => 'toolbox')); Modified: trunk/library/snippets/AnswerModelSnippet.php =================================================================== --- trunk/library/snippets/AnswerModelSnippet.php 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/snippets/AnswerModelSnippet.php 2011-10-31 09:46:30 UTC (rev 155) @@ -44,186 +44,5 @@ * @license New BSD License * @since Class available since version 1.4 */ -class AnswerModelSnippet extends Gems_Snippets_ModelTableSnippetAbstract -{ - /** - * Set a fixed model sort. - * - * Leading _ means not overwritten by sources. - * - * @var array - */ - protected $_fixedSort = array('gto_round_order' => SORT_ASC); - - /** - * Shortfix to add class attribute - * - * @var string - */ - protected $class = 'browser'; - - /** - * - * @var string Format used for displaying dates. - */ - protected $dateFormat = Zend_Date::DATE_MEDIUM; - - /** - * Required - * - * @var Gems_Loader - */ - protected $loader; - - /** - * Required - * - * @var Zend_Locale - */ - protected $locale; - - /** - * Optional: $request or $tokenData must be set - * - * The display data of the token shown - * - * @var Gems_Tracker_Token - */ - protected $token; - - /** - * Required: id of the selected token to show - * - * @var string - */ - protected $tokenId; - - /** - * Adds columns from the model to the bridge that creates the browse table. - * - * Overrule this function to add different columns to the browse table, without - * having to recode the core table building code. - * - * @param MUtil_Model_TableBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @return void - */ - protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) - { - $br = MUtil_Html::create('br'); - $selectedClass = MUtil_Lazy::iff(MUtil_Lazy::comp($bridge->gto_id_token, '==', $this->tokenId), 'selectedColumn', null); - - $bridge->th($this->_('Status')); - $td = $bridge->tdh(MUtil_Lazy::first($bridge->grc_description, $this->_('OK'))); - $td->appendAttrib('class', $selectedClass); - - $bridge->th($this->_('Question')); - $td = $bridge->tdh( - $bridge->gto_round_description, - MUtil_Lazy::iif($bridge->gto_round_description, $br), - MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from) - ); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - - foreach($model->getItemsOrdered() as $name) { - if ($label = $model->get($name, 'label')) { - $bridge->thd($label, array('class' => $model->get($name, 'thClass'))); - $td = $bridge->td($bridge->$name); - - $td->appendAttrib('class', 'answer'); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - } - } - - $bridge->th($this->_('Token')); - $td = $bridge->tdh($bridge->gto_id_token->strtoupper()); - $td->appendAttrib('class', $selectedClass); - $td->appendAttrib('class', $bridge->row_class); - } - - /** - * Creates the model - * - * @return MUtil_Model_ModelAbstract - */ - protected function createModel() - { - $model = $this->token->getSurveyAnswerModel($this->locale->getLanguage()); - - $model->set('gto_valid_from', 'dateFormat', $this->dateFormat); - $model->set('gto_completion_time', 'dateFormat', $this->dateFormat); - - return $model; - } - - - /** - * Create the snippets content - * - * This is a stub function either override getHtmlOutput() or override render() - * - * @param Zend_View_Abstract $view Just in case it is needed here - * @return MUtil_Html_HtmlInterface Something that can be rendered - */ - public function getHtmlOutput(Zend_View_Abstract $view) - { - $htmlDiv = MUtil_Html::create()->div(); - - if ($this->tokenId) { - if ($this->token->exists) { - $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); - - $htmlDiv->pInfo(sprintf( - $this->_('Answers for token %s, patient number %s: %s.'), - strtoupper($this->tokenId), - $this->token->getPatientNumber(), - $this->token->getRespondentName())) - ->appendAttrib('class', 'noprint'); - - $table = parent::getHtmlOutput($view); - $table->setPivot(true, 2, 1); - - $this->applyHtmlAttributes($table); - $htmlDiv[] = $table; - - } else { - $htmlDiv->ul(sprintf($this->_('Token %s not found.'), $this->tokenId), array('class' => 'errors')); - } - - } else { - $htmlDiv->ul($this->_('No token specified.'), array('class' => 'errors')); - } - - $buttonDiv = $htmlDiv->buttonDiv(); - $buttonDiv->actionLink(array(), $this->_('Close'), array('onclick' => 'window.close();')); - $buttonDiv->actionLink(array(), $this->_('Print'), array('onclick' => 'window.print();')); - return $htmlDiv; - } - - /** - * The place to check if the data set in the snippet is valid - * to generate the snippet. - * - * When invalid data should result in an error, you can throw it - * here but you can also perform the check in the - * checkRegistryRequestsAnswers() function from the - * {@see MUtil_Registry_TargetInterface}. - * - * @return boolean - */ - public function hasHtmlOutput() - { - if (! $this->tokenId) { - if (isset($this->token)) { - $this->tokenId = $this->token->getTokenId(); - } - } elseif (! $this->token) { - $this->token = $this->loader->getTracker()->getToken($this->tokenId); - } - - // Output always true, returns an error message as html when anything is wrong - return true; - } -} +class AnswerModelSnippet extends Gems_Tracker_Snippets_AnswerModelSnippetGeneric +{ } Modified: trunk/library/snippets/TrackAnswersModelSnippet.php =================================================================== --- trunk/library/snippets/TrackAnswersModelSnippet.php 2011-10-31 09:13:59 UTC (rev 154) +++ trunk/library/snippets/TrackAnswersModelSnippet.php 2011-10-31 09:46:30 UTC (rev 155) @@ -36,8 +36,6 @@ * @version $Id$ */ -include_once(dirname(__FILE__) . '/AnswerModelSnippet.php'); - /** * Class description of TrackAnswersModelSnippet * @@ -47,7 +45,7 @@ * @license New BSD License * @since Class available since version 1.4 */ -class TrackAnswersModelSnippet extends AnswerModelSnippet +class TrackAnswersModelSnippet extends Gems_Tracker_Snippets_AnswerModelSnippetGeneric { /** * Overrule to implement snippet specific filtering and sorting. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |