From: <gem...@li...> - 2012-06-15 11:42:31
|
Revision: 768 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=768&view=rev Author: mennodekker Date: 2012-06-15 11:42:19 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Moved some of the RespondentExportAction output to snippets so project can change it. Added getStatus to token to allow projects to have other status info than open, completed, future and missed Modified Paths: -------------- trunk/library/classes/Gems/Default/RespondentExportAction.php trunk/library/classes/Gems/Tracker/Token.php Added Paths: ----------- trunk/library/classes/Gems/Snippets/Export/ trunk/library/classes/Gems/Snippets/Export/ReportFooter.php trunk/library/classes/Gems/Snippets/Export/ReportHeader.php trunk/library/classes/Gems/Snippets/Export/RespondentSnippet.php Modified: trunk/library/classes/Gems/Default/RespondentExportAction.php =================================================================== --- trunk/library/classes/Gems/Default/RespondentExportAction.php 2012-06-15 10:30:24 UTC (rev 767) +++ trunk/library/classes/Gems/Default/RespondentExportAction.php 2012-06-15 11:42:19 UTC (rev 768) @@ -48,6 +48,10 @@ protected $_wkhtmltopdfLocation = ""; + protected $_reportFooter = 'Export_ReportFooter'; + protected $_reportHeader = 'Export_ReportHeader'; + protected $_respondentSnippet = 'Export_RespondentSnippet'; + protected $_groupedSurveySnippet = 'TrackAnswersModelSnippet'; protected $_singleSurveySnippet = 'AnswerModelSnippet'; @@ -161,7 +165,6 @@ $groupSurveys = $this->getRequest()->getParam('group'); $token = $track->getFirstToken(); $engine = $track->getTrackEngine(); - $today = new Zend_Date(); $surveys = array(); $table = $this->html->table(array('class' => 'browser')); @@ -172,33 +175,18 @@ $this->html->br(); while ($token) { + //Should this token be in the list? if (!$this->_isTokenInFilter($token)) { $token = $token->getNextToken(); continue; } - - $status = $this->_('Open'); - - if ($token->isCompleted()) { - $status = $this->_('Completed'); - } else { - $validFrom = $token->getValidFrom(); - $validUntil = $token->getValidUntil(); - - if (!empty($validUntil) && $validUntil->isEarlier($today)) { - $status = $this->_('Missed'); - } else if (!empty($validFrom) && $validFrom->isLater($today)) { - $status = $this->_('Future'); - } else if (empty($validFrom) && empty($validUntil)) { - $status = $this->_('Future'); - } - } - + $table->tr()->td($token->getSurveyName()) ->td(($engine->getTrackType() == 'T' ? $token->getRoundDescription() : $this->_('Single Survey'))) ->td(strtoupper($token->getTokenId())) - ->td($status); - + ->td($token->getStatus()); + + //Should we display the answers? if (!$token->isCompleted()) { $token = $token->getNextToken(); continue; @@ -291,26 +279,12 @@ $respondentModel = $this->loader->getModels()->getRespondentModel(false); $respondentModel->setFilter(array('gr2o_patient_nr' => $respondentId)); $respondentData = $respondentModel->loadFirst(); + + $this->addSnippet($this->_respondentSnippet, + 'model', $respondentModel, + 'data', $respondentData, + 'respondentId', $respondentId); - if (empty($respondentData)) { - $this->html->p()->b(sprintf($this->_('Unknown respondent %s'), $respondentId)); - return; - } - - $bridge = new MUtil_Model_VerticalTableBridge($respondentModel, array('class' => 'browser')); - $bridge->setRepeater(MUtil_Lazy::repeat(array($respondentData))); - $bridge->th($this->_('Respondent information'), array('colspan' => 4)); - $bridge->setColumnCount(2); - foreach($respondentModel->getItemsOrdered() as $name) { - if ($label = $respondentModel->get($name, 'label')) { - $bridge->addItem($name, $label); - } - } - - $this->html->h2($this->_('Respondent information') . ': ' . $respondentId); - $this->html[] = $bridge->getTable(); - $this->html->hr(); - $tracker = $this->loader->getTracker(); $tracks = $tracker->getRespondentTracks($respondentData['gr2o_id_user'], $respondentData['gr2o_id_organization']); @@ -327,25 +301,22 @@ protected function _render($respondents) { $this->html = new MUtil_Html_Sequence(); - $this->html->h1($this->_('Respondent report')); - - $table = $this->html->table(array('class' => 'browser')); - - $table->th($this->_('Report information'), array('colspan' => 2)); - $table->tr()->th($this->_('Generated by')) - ->td($this->loader->getCurrentUser()->getFullName()); - $table->tr()->th($this->_('Generated on')) - ->td(new Zend_Date()); - $table->tr()->th($this->_('Organization')) - ->td($this->loader->getCurrentUser()->getCurrentOrganization()->getName()); - - $this->html->br(); - + + $this->addSnippet($this->_reportHeader); + + $respondentCount = count($respondents); + $respondentIdx = 0; foreach ($respondents as $respondentId) { + $respondentIdx++; $this->_exportRespondent($respondentId); - - $this->html->div('', array('style' => 'height: 100px')); + + if ($respondentIdx < $respondentCount) { + // Add some whitespace between patients + $this->html->div('', array('style' => 'height: 100px')); + } } + + $this->addSnippet($this->_reportFooter, 'respondents', $respondents); $this->escort->menu->setVisible(false); if ($this->escort instanceof Gems_Project_Layout_MultiLayoutInterface) { Added: trunk/library/classes/Gems/Snippets/Export/ReportFooter.php =================================================================== --- trunk/library/classes/Gems/Snippets/Export/ReportFooter.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Export/ReportFooter.php 2012-06-15 11:42:19 UTC (rev 768) @@ -0,0 +1,60 @@ +<?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 Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Footer for html/pdf export of a respondent + * + * @package Gems + * @subpackage Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.5 + */ +class Gems_Snippets_Export_ReportFooter extends MUtil_Snippets_SnippetAbstract +{ + /** + * @var Gems_Loader + */ + public $loader; + + public function getHtmlOutput(Zend_View_Abstract $view) + { + $html = $this->getHtmlSequence(); + + $html->div($this->_('Report generation finished.'), array('class'=> 'centerAlign')); + $html->hr(); + + return $html; + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Snippets/Export/ReportHeader.php =================================================================== --- trunk/library/classes/Gems/Snippets/Export/ReportHeader.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Export/ReportHeader.php 2012-06-15 11:42:19 UTC (rev 768) @@ -0,0 +1,70 @@ +<?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 Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Header for html/pdf export of a respondent + * + * @package Gems + * @subpackage Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.5 + */ +class Gems_Snippets_Export_ReportHeader extends MUtil_Snippets_SnippetAbstract +{ + /** + * @var Gems_Loader + */ + public $loader; + + public function getHtmlOutput(Zend_View_Abstract $view) + { + $html = $this->getHtmlSequence(); + $html->h1($this->_('Respondent report')); + + $table = $html->table(array('class' => 'browser')); + + $table->th($this->_('Report information'), array('colspan' => 2)); + $table->tr()->th($this->_('Generated by')) + ->td($this->loader->getCurrentUser()->getFullName()); + $table->tr()->th($this->_('Generated on')) + ->td(new Zend_Date()); + $table->tr()->th($this->_('Organization')) + ->td($this->loader->getCurrentUser()->getCurrentOrganization()->getName()); + + $html->br(); + + return $html; + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Snippets/Export/RespondentSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Export/RespondentSnippet.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Export/RespondentSnippet.php 2012-06-15 11:42:19 UTC (rev 768) @@ -0,0 +1,96 @@ +<?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 Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Show info about the respondent during html/pdf export + * + * @package Gems + * @subpackage Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.5 + */ +class Gems_Snippets_Export_RespondentSnippet extends MUtil_Snippets_SnippetAbstract +{ + /** + * The data for the current respondentId + * + * @var array + */ + public $data; + + /** + * @var Gems_Model_RespondentModel + */ + public $model; + + /** + * The respondent we are looking at + * + * @var int + */ + public $respondentId; + + public function getHtmlOutput(Zend_View_Abstract $view) + { + parent::getHtmlOutput($view); + + $respondentModel = $this->model; + $respondentData = $this->data; + $respondentId = $this->respondentId; + + $html = $this->getHtmlSequence(); + if (empty($this->data)) { + $html->p()->b(sprintf($this->_('Unknown respondent %s'), $respondentId)); + return $html; + } + + $bridge = new MUtil_Model_VerticalTableBridge($respondentModel, array('class' => 'browser')); + $bridge->setRepeater(MUtil_Lazy::repeat(array($respondentData))); + $bridge->th($this->_('Respondent information'), array('colspan' => 4)); + $bridge->setColumnCount(2); + foreach($respondentModel->getItemsOrdered() as $name) { + if ($label = $respondentModel->get($name, 'label')) { + $bridge->addItem($name, $label); + } + } + + $html->h2($this->_('Respondent information') . ': ' . $respondentId); + $html[] = $bridge->getTable(); + $html->hr(); + + return $html; + } + +} \ No newline at end of file Modified: trunk/library/classes/Gems/Tracker/Token.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token.php 2012-06-15 10:30:24 UTC (rev 767) +++ trunk/library/classes/Gems/Tracker/Token.php 2012-06-15 11:42:19 UTC (rev 768) @@ -125,6 +125,12 @@ /** * + * @var Zend_Translate_Adapter + */ + public $translate; + + /** + * * @var Gems_Util */ protected $util; @@ -936,6 +942,34 @@ } /** + * Returns a string that tells if the token is open, completed or any other + * status you might like. This will not be interpreted by the tracker it is + * for display purposes only + */ + public function getStatus() + { + $today = new Zend_Date(); + $status = $this->translate->_('Open'); + + if ($this->isCompleted()) { + $status = $this->translate->_('Completed'); + } else { + $validFrom = $this->getValidFrom(); + $validUntil = $this->getValidUntil(); + + if (!empty($validUntil) && $validUntil->isEarlier($today)) { + $status = $this->translate->_('Missed'); + } else if (!empty($validFrom) && $validFrom->isLater($today)) { + $status = $this->translate->_('Future'); + } else if (empty($validFrom) && empty($validUntil)) { + $status = $this->translate->_('Future'); + } + } + + return $status; + } + + /** * * @return Gems_Tracker_Survey */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |