|
From: <gem...@li...> - 2011-10-28 12:37:03
|
Revision: 153
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=153&view=rev
Author: matijsdejong
Date: 2011-10-28 12:36:57 +0000 (Fri, 28 Oct 2011)
Log Message:
-----------
AddTrackSnippet can now handle organization switches correctly.
Made it easier to write your own AnswerModel.
Modified Paths:
--------------
branches/newUser/snippets/AddTracksSnippet.php
branches/newUser/snippets/AnswerModelSnippet.php
branches/newUser/snippets/TrackAnswersModelSnippet.php
Added Paths:
-----------
branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php
Added: branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php
===================================================================
--- branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php (rev 0)
+++ branches/newUser/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2011-10-28 12:36:57 UTC (rev 153)
@@ -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: branches/newUser/snippets/AddTracksSnippet.php
===================================================================
--- branches/newUser/snippets/AddTracksSnippet.php 2011-10-28 10:54:42 UTC (rev 152)
+++ branches/newUser/snippets/AddTracksSnippet.php 2011-10-28 12:36:57 UTC (rev 153)
@@ -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: branches/newUser/snippets/AnswerModelSnippet.php
===================================================================
--- branches/newUser/snippets/AnswerModelSnippet.php 2011-10-28 10:54:42 UTC (rev 152)
+++ branches/newUser/snippets/AnswerModelSnippet.php 2011-10-28 12:36:57 UTC (rev 153)
@@ -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: branches/newUser/snippets/TrackAnswersModelSnippet.php
===================================================================
--- branches/newUser/snippets/TrackAnswersModelSnippet.php 2011-10-28 10:54:42 UTC (rev 152)
+++ branches/newUser/snippets/TrackAnswersModelSnippet.php 2011-10-28 12:36:57 UTC (rev 153)
@@ -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.
|