|
From: <gem...@li...> - 2012-06-21 09:38:34
|
Revision: 774
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=774&view=rev
Author: mennodekker
Date: 2012-06-21 09:38:22 +0000 (Thu, 21 Jun 2012)
Log Message:
-----------
Moved RespondentExport to a separate class
-> solves menu jump and not allowed error when pr.respondet.export-html given
Modified Paths:
--------------
trunk/library/classes/Gems/Default/RespondentAction.php
trunk/library/classes/Gems/Default/RespondentExportAction.php
trunk/library/classes/Gems/Loader.php
Added Paths:
-----------
trunk/library/classes/Gems/Export/RespondentExport.php
Modified: trunk/library/classes/Gems/Default/RespondentAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentAction.php 2012-06-20 16:59:53 UTC (rev 773)
+++ trunk/library/classes/Gems/Default/RespondentAction.php 2012-06-21 09:38:22 UTC (rev 774)
@@ -52,12 +52,48 @@
'RespondentTokenTabsSnippet',
'RespondentTokenSnippet',
);
+
+ public $exportSnippets = array('RespondentDetailsSnippet');
public $filterStandard = array('grc_success' => 1);
public $sortKey = array('gr2o_opened' => SORT_DESC);
public $useTabbedForms = true;
+
+ /**
+ * Constructs the form
+ *
+ * @param Gems_Export_RespondentExport $export
+ * @return Gems_Form_TableForm
+ */
+ protected function _getExportForm($export)
+ {
+ $form = new Gems_Form_TableForm();
+ $form->setAttrib('target', '_blank');
+
+ $element = new Zend_Form_Element_Checkbox('group');
+ $element->setLabel($this->_('Group surveys'));
+ $element->setValue(1);
+ $form->addElement($element);
+
+ $element = new Zend_Form_Element_Select('format');
+ $element->setLabel($this->_('Output format'));
+ $outputFormats = array('html' => 'HTML');
+ if (!empty($export->_wkhtmltopdfLocation)) {
+ $outputFormats['pdf'] = 'PDF';
+ $element->setValue('pdf');
+ }
+ $element->setMultiOptions($outputFormats);
+ $form->addElement($element);
+
+ $element = new Zend_Form_Element_Submit('export');
+ $element->setLabel($this->_('Export'))
+ ->setAttrib('class', 'button');
+ $form->addElement($element);
+
+ return $form;
+ }
/**
* Adds columns from the model to the bridge that creates the browse table.
@@ -422,6 +458,38 @@
public function exportAction()
{
- $this->_reroute(array('controller' => 'respondent-export', 'action' => 'index'));
+ //First show the respondent snippet
+ $model = $this->getModel();
+ $data = $model->applyRequest($this->getRequest(), true)->loadFirst();
+
+ if (! isset($data['grs_id_user'])) {
+ $this->addMessage(sprintf($this->_('Unknown %s requested'), $this->getTopic()));
+ $this->_reroute(array('action' => 'index'));
+ }
+
+ $params['model'] = $model;
+ $params['baseUrl'] = array(MUtil_Model::REQUEST_ID => $this->_getParam(MUtil_Model::REQUEST_ID));
+ $params['buttons'] = $this->createMenuLinks();
+ $params['onclick'] = $this->findAllowedMenuItem('edit');
+ if ($params['onclick']) {
+ $params['onclick'] = $params['onclick']->toHRefAttribute($this->getRequest());
+ }
+ $params['respondentData'] = $data;
+ $this->addSnippets($this->exportSnippets, $params);
+
+ //Now show the export form
+ $export = $this->loader->getRespondentExport($this);
+ $form = $this->_getExportForm($export);
+ $this->html->h2($this->_('Export respondent'));
+ $div = $this->html->div(array('id' => 'mainform'));
+ $div[] = $form;
+
+ $request = $this->getRequest();
+
+ $form->populate($request->getParams());
+
+ if ($request->isPost()) {
+ $export->render((array) $this->getRequest()->getParam('id'), $this->getRequest()->getParam('group'), $this->getRequest()->getParam('format'));
+ }
}
}
Modified: trunk/library/classes/Gems/Default/RespondentExportAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentExportAction.php 2012-06-20 16:59:53 UTC (rev 773)
+++ trunk/library/classes/Gems/Default/RespondentExportAction.php 2012-06-21 09:38:22 UTC (rev 774)
@@ -44,32 +44,15 @@
*/
class Gems_Default_RespondentExportAction extends Gems_Controller_Action
{
- public $useHtmlView = true;
-
- protected $_wkhtmltopdfLocation = "";
-
- protected $_reportFooter = 'Export_ReportFooterSnippet';
- protected $_reportHeader = 'Export_ReportHeaderSnippet';
- protected $_respondentSnippet = 'Export_RespondentSnippet';
+ public $useHtmlView = true;
- protected $_groupedSurveySnippet = 'TrackAnswersModelSnippet';
- protected $_singleSurveySnippet = 'AnswerModelSnippet';
-
- public function init()
- {
- parent::init();
-
- if (isset($this->project->export) && isset($this->project->export['wkhtmltopdf'])) {
- $this->_wkhtmltopdfLocation = $this->project->export['wkhtmltopdf'];
- }
- }
-
/**
* Constructs the form
*
+ * @param Gems_Export_RespondentExport $export
* @return Gems_Form_TableForm
- */
- protected function _getForm()
+ */
+ protected function _getForm($export)
{
$form = new Gems_Form_TableForm();
$form->setAttrib('target', '_blank');
@@ -92,7 +75,7 @@
$element = new Zend_Form_Element_Select('format');
$element->setLabel($this->_('Output format'));
$outputFormats = array('html' => 'HTML');
- if (!empty($this->_wkhtmltopdfLocation)) {
+ if (!empty($export->_wkhtmltopdfLocation)) {
$outputFormats['pdf'] = 'PDF';
$element->setValue('pdf');
}
@@ -107,264 +90,11 @@
return $form;
}
- /**
- * Calls 'wkhtmltopdf' to convert HTML to PDF
- *
- * @param string $content The HTML source
- * @return string The converted PDF file
- * @throws Exception
- */
- protected function _convertToPdf($content)
- {
- $tempInputFilename = GEMS_ROOT_DIR . '/var/tmp/export-' . md5(time() . rand()) . '.html';
- $tempOutputFilename = GEMS_ROOT_DIR . '/var/tmp/export-' . md5(time() . rand()) . '.pdf';
-
- file_put_contents($tempInputFilename, $content);
-
- if (!file_exists($tempInputFilename)) {
- throw new Exception("Unable to create temporary file '{$tempInputFilename}'");
- }
-
- $lastLine = exec(escapeshellarg($this->_wkhtmltopdfLocation) . ' ' . escapeshellarg($tempInputFilename)
- . ' ' . escapeshellarg($tempOutputFilename), $outputLines, $return);
-
- if ($return > 0) {
- @unlink($tempInputFilename);
- @unlink($tempOutputFilename);
-
- throw new Exception(sprintf($this->_('Unable to run PDF conversion: "%s"'), $lastLine));
- }
-
- $pdfContents = file_get_contents($tempOutputFilename);
-
- @unlink($tempInputFilename);
- @unlink($tempOutputFilename);
-
- return $pdfContents;
- }
-
- /**
- * Returns true when this token should be displayed
- *
- * @param Gems_Tracker_Token $token
- * @return boolean
- */
- public function _displayToken($token)
- {
- if ($token->isCompleted()) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Determines if this particular token should be included
- * in the report
- *
- * @param Gems_Tracker_Token $token
- * @return boolean This dummy implementation always returns true
- */
- protected function _isTokenInFilter(Gems_Tracker_Token $token)
- {
- return true;
- }
-
- /**
- * Exports all the tokens of a single track, grouped by round
- *
- * @param Gems_Tracker_RespondentTrack $track
- */
- protected function _exportTrackTokens(Gems_Tracker_RespondentTrack $track)
- {
- $groupSurveys = $this->getRequest()->getParam('group');
- $token = $track->getFirstToken();
- $engine = $track->getTrackEngine();
- $surveys = array();
-
- $table = $this->html->table(array('class' => 'browser'));
- $table->th($this->_('Survey'))
- ->th($this->_('Round'))
- ->th($this->_('Token'))
- ->th($this->_('Status'));
- $this->html->br();
-
- while ($token) {
- //Should this token be in the list?
- if (!$this->_isTokenInFilter($token)) {
- $token = $token->getNextToken();
- continue;
- }
-
- $table->tr()->td($token->getSurveyName())
- ->td(($engine->getTrackType() == 'T' ? $token->getRoundDescription() : $this->_('Single Survey')))
- ->td(strtoupper($token->getTokenId()))
- ->td($token->getStatus());
-
- //Should we display the answers?
- if (!$this->_displayToken($token)) {
- $token = $token->getNextToken();
- continue;
- }
-
- if ($engine->getTrackType() == 'S' || !$groupSurveys) {
- $this->html->span()->b($token->getSurveyName() . ($token->getRoundDescription() ? ' (' . $token->getRoundDescription() . ')' : ''));
- $this->addSnippet($this->_singleSurveySnippet, 'token', $token, 'tokenId', $token->getTokenId(),
- 'showHeaders', false, 'showButtons', false, 'showSelected', false, 'showTakeButton', false);
-
- $this->html->br();
- } else {
- if (!isset($surveys[$token->getSurveyId()])) {
- $surveys[$token->getSurveyId()] = true;
-
- $this->html->span()->b($token->getSurveyName());
- $this->addSnippet($this->_groupedSurveySnippet, 'token', $token, 'tokenId', $token->getTokenId(),
- 'showHeaders', false, 'showButtons', false, 'showSelected', false, 'showTakeButton', false);
-
- $this->html->br();
- }
- }
-
- $token = $token->getNextToken();
- }
- }
-
- /**
- * Exports a single track
- *
- * @param Gems_Tracker_RespondentTrack $track
- */
- protected function _exportTrack(Gems_Tracker_RespondentTrack $track)
- {
- if ($track->getReceptionCode() != GemsEscort::RECEPTION_OK) {
- return;
- }
-
- $trackModel = $this->loader->getTracker()->getRespondentTrackModel();
- $trackModel->resetOrder();
- $trackModel->set('gtr_track_name', 'label', $this->_('Track'));
- $trackModel->set('gr2t_track_info', 'label', $this->_('Description'),
- 'description', $this->_('Enter the particulars concerning the assignment to this respondent.'));
- $trackModel->set('assigned_by', 'label', $this->_('Assigned by'));
- $trackModel->set('gr2t_start_date', 'label', $this->_('Start'),
- 'formatFunction', $this->util->getTranslated()->formatDate,
- 'default', MUtil_Date::format(new Zend_Date(), 'dd-MM-yyyy'));
- $trackModel->set('gr2t_reception_code');
- $trackModel->set('gr2t_comment', 'label', $this->_('Comment'));
- $trackModel->setFilter(array('gr2t_id_respondent_track' => $track->getRespondentTrackId()));
- $trackData = $trackModel->loadFirst();
-
- $this->html->h3($this->_('Track') . ' ' . $trackData['gtr_track_name']);
-
- $bridge = new MUtil_Model_VerticalTableBridge($trackModel, array('class' => 'browser'));
- $bridge->setRepeater(MUtil_Lazy::repeat(array($trackData)));
- $bridge->th($this->_('Track information'), array('colspan' => 2));
- $bridge->setColumnCount(1);
- foreach($trackModel->getItemsOrdered() as $name) {
- if ($label = $trackModel->get($name, 'label')) {
- $bridge->addItem($name, $label);
- }
- }
-
- $table = $bridge->getTable();
-
- foreach ($track->getFieldData() as $field => $value) {
- if (is_int($field)) {
- continue;
- }
-
- $table->tr()->th($field)->td($value);
- }
-
- $this->html[] = $table;
- $this->html->br();
-
- $this->_exportTrackTokens($track);
-
- $this->html->hr();
- }
-
- /**
- * Exports a single respondent
- *
- * @param string $respondentId
- */
- protected function _exportRespondent($respondentId)
- {
- $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);
-
- $tracker = $this->loader->getTracker();
- $tracks = $tracker->getRespondentTracks($respondentData['gr2o_id_user'], $respondentData['gr2o_id_organization']);
-
- foreach ($tracks as $trackId => $track) {
- $this->_exportTrack($track);
- }
- }
-
- /**
- * Renders the entire report (including layout)
- *
- * @param string[] $respondentId
- */
- protected function _render($respondents)
- {
- $this->html = new MUtil_Html_Sequence();
-
- $this->addSnippet($this->_reportHeader);
-
- $respondentCount = count($respondents);
- $respondentIdx = 0;
- foreach ($respondents as $respondentId) {
- $respondentIdx++;
- $this->_exportRespondent($respondentId);
-
- 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) {
- $this->escort->layoutSwitch();
- }
- $this->escort->postDispatch($this->getRequest());
-
- $this->_helper->layout()->disableLayout();
- $this->_helper->viewRenderer->setNoRender(true);
-
- $this->view->layout()->content = $this->html->render($this->view);
-
- $content = $this->view->layout->render();
-
- if ($this->getRequest()->getParam('format') == 'pdf') {
- $content = $this->_convertToPdf($content);
- $filename = 'respondent-export-' . strtolower($respondentId) . '.pdf';
-
- header('Content-Type: application/x-download');
- header('Content-Length: '.strlen($content));
- header('Content-Disposition: inline; filename="'.$filename.'"');
- header('Cache-Control: private, max-age=0, must-revalidate');
- header('Pragma: public');
- }
-
- echo $content;
-
- $this->escort->menu->setVisible(true);
- }
-
public function indexAction()
{
- $form = $this->_getForm();
+ $export = $this->loader->getRespondentExport($this);
+
+ $form = $this->_getForm($export);
$this->html->h2($this->_('Export respondent'));
$div = $this->html->div(array('id' => 'mainform'));
$div[] = $form;
@@ -377,7 +107,7 @@
$respondents = explode(',', $request->getParam('id'));
$respondents = array_map('trim', $respondents);
- $this->_render($respondents);
+ $export->render($respondents, $this->getRequest()->getParam('group'), $this->getRequest()->getParam('format'));
}
}
}
\ No newline at end of file
Added: trunk/library/classes/Gems/Export/RespondentExport.php
===================================================================
--- trunk/library/classes/Gems/Export/RespondentExport.php (rev 0)
+++ trunk/library/classes/Gems/Export/RespondentExport.php 2012-06-21 09:38:22 UTC (rev 774)
@@ -0,0 +1,342 @@
+<?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 Export
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * Handles export of all tracks/surveys for a respondent
+ *
+ * @package Gems
+ * @subpackage Export
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5.5
+ */
+class Gems_Export_RespondentExport extends Gems_Registry_TargetAbstract
+{
+ public $_wkhtmltopdfLocation = "";
+
+ protected $_reportFooter = 'Export_ReportFooterSnippet';
+ protected $_reportHeader = 'Export_ReportHeaderSnippet';
+ protected $_respondentSnippet = 'Export_RespondentSnippet';
+
+ protected $_groupedSurveySnippet = 'TrackAnswersModelSnippet';
+ protected $_singleSurveySnippet = 'AnswerModelSnippet';
+
+ public $escort;
+ public $project;
+ private $html;
+ public $loader;
+ /**
+ * @var Zend_Translate_Adapter
+ */
+ public $translate;
+
+ public $util;
+
+ public $view;
+
+ public function _($messageid, $locale = null)
+ {
+ return $this->translate->_($messageid, $locale);
+ }
+
+ public function afterRegistry()
+ {
+ parent::afterRegistry();
+
+ // Load the pdf class from the project settings if available
+ if (isset($this->project->export) && isset($this->project->export['wkhtmltopdf'])) {
+ $this->_wkhtmltopdfLocation = $this->project->export['wkhtmltopdf'];
+ }
+ }
+
+ /**
+ * Calls 'wkhtmltopdf' to convert HTML to PDF
+ *
+ * @param string $content The HTML source
+ * @return string The converted PDF file
+ * @throws Exception
+ */
+ protected function _convertToPdf($content)
+ {
+ $tempInputFilename = GEMS_ROOT_DIR . '/var/tmp/export-' . md5(time() . rand()) . '.html';
+ $tempOutputFilename = GEMS_ROOT_DIR . '/var/tmp/export-' . md5(time() . rand()) . '.pdf';
+
+ file_put_contents($tempInputFilename, $content);
+
+ if (!file_exists($tempInputFilename)) {
+ throw new Exception("Unable to create temporary file '{$tempInputFilename}'");
+ }
+
+ $lastLine = exec(escapeshellarg($this->_wkhtmltopdfLocation) . ' ' . escapeshellarg($tempInputFilename)
+ . ' ' . escapeshellarg($tempOutputFilename), $outputLines, $return);
+
+ if ($return > 0) {
+ @unlink($tempInputFilename);
+ @unlink($tempOutputFilename);
+
+ throw new Exception(sprintf($this->_('Unable to run PDF conversion: "%s"'), $lastLine));
+ }
+
+ $pdfContents = file_get_contents($tempOutputFilename);
+
+ @unlink($tempInputFilename);
+ @unlink($tempOutputFilename);
+
+ return $pdfContents;
+ }
+
+ /**
+ * Returns true when this token should be displayed
+ *
+ * @param Gems_Tracker_Token $token
+ * @return boolean
+ */
+ public function _displayToken($token)
+ {
+ if ($token->isCompleted()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines if this particular token should be included
+ * in the report
+ *
+ * @param Gems_Tracker_Token $token
+ * @return boolean This dummy implementation always returns true
+ */
+ protected function _isTokenInFilter(Gems_Tracker_Token $token)
+ {
+ return true;
+ }
+
+ /**
+ * Exports all the tokens of a single track, grouped by round
+ *
+ * @param Gems_Tracker_RespondentTrack $track
+ */
+ protected function _exportTrackTokens(Gems_Tracker_RespondentTrack $track)
+ {
+ $groupSurveys = $this->_group;
+ $token = $track->getFirstToken();
+ $engine = $track->getTrackEngine();
+ $surveys = array();
+
+ $table = $this->html->table(array('class' => 'browser'));
+ $table->th($this->_('Survey'))
+ ->th($this->_('Round'))
+ ->th($this->_('Token'))
+ ->th($this->_('Status'));
+ $this->html->br();
+
+ while ($token) {
+ //Should this token be in the list?
+ if (!$this->_isTokenInFilter($token)) {
+ $token = $token->getNextToken();
+ continue;
+ }
+
+ $table->tr()->td($token->getSurveyName())
+ ->td(($engine->getTrackType() == 'T' ? $token->getRoundDescription() : $this->_('Single Survey')))
+ ->td(strtoupper($token->getTokenId()))
+ ->td($token->getStatus());
+
+ //Should we display the answers?
+ if (!$this->_displayToken($token)) {
+ $token = $token->getNextToken();
+ continue;
+ }
+
+ if ($engine->getTrackType() == 'S' || !$groupSurveys) {
+ $this->html->span()->b($token->getSurveyName() . ($token->getRoundDescription() ? ' (' . $token->getRoundDescription() . ')' : ''));
+ $this->html->snippet($this->_singleSurveySnippet, 'token', $token, 'tokenId', $token->getTokenId(),
+ 'showHeaders', false, 'showButtons', false, 'showSelected', false, 'showTakeButton', false);
+
+ $this->html->br();
+ } else {
+ if (!isset($surveys[$token->getSurveyId()])) {
+ $surveys[$token->getSurveyId()] = true;
+
+ $this->html->span()->b($token->getSurveyName());
+ $this->html->snippet($this->_groupedSurveySnippet, 'token', $token, 'tokenId', $token->getTokenId(),
+ 'showHeaders', false, 'showButtons', false, 'showSelected', false, 'showTakeButton', false);
+
+ $this->html->br();
+ }
+ }
+
+ $token = $token->getNextToken();
+ }
+ }
+
+ /**
+ * Exports a single track
+ *
+ * @param Gems_Tracker_RespondentTrack $track
+ */
+ protected function _exportTrack(Gems_Tracker_RespondentTrack $track)
+ {
+ if ($track->getReceptionCode() != GemsEscort::RECEPTION_OK) {
+ return;
+ }
+
+ $trackModel = $this->loader->getTracker()->getRespondentTrackModel();
+ $trackModel->resetOrder();
+ $trackModel->set('gtr_track_name', 'label', $this->_('Track'));
+ $trackModel->set('gr2t_track_info', 'label', $this->_('Description'),
+ 'description', $this->_('Enter the particulars concerning the assignment to this respondent.'));
+ $trackModel->set('assigned_by', 'label', $this->_('Assigned by'));
+ $trackModel->set('gr2t_start_date', 'label', $this->_('Start'),
+ 'formatFunction', $this->util->getTranslated()->formatDate,
+ 'default', MUtil_Date::format(new Zend_Date(), 'dd-MM-yyyy'));
+ $trackModel->set('gr2t_reception_code');
+ $trackModel->set('gr2t_comment', 'label', $this->_('Comment'));
+ $trackModel->setFilter(array('gr2t_id_respondent_track' => $track->getRespondentTrackId()));
+ $trackData = $trackModel->loadFirst();
+
+ $this->html->h3($this->_('Track') . ' ' . $trackData['gtr_track_name']);
+
+ $bridge = new MUtil_Model_VerticalTableBridge($trackModel, array('class' => 'browser'));
+ $bridge->setRepeater(MUtil_Lazy::repeat(array($trackData)));
+ $bridge->th($this->_('Track information'), array('colspan' => 2));
+ $bridge->setColumnCount(1);
+ foreach($trackModel->getItemsOrdered() as $name) {
+ if ($label = $trackModel->get($name, 'label')) {
+ $bridge->addItem($name, $label);
+ }
+ }
+
+ $table = $bridge->getTable();
+
+ foreach ($track->getFieldData() as $field => $value) {
+ if (is_int($field)) {
+ continue;
+ }
+
+ $table->tr()->th($field)->td($value);
+ }
+
+ $this->html[] = $table;
+ $this->html->br();
+
+ $this->_exportTrackTokens($track);
+
+ $this->html->hr();
+ }
+
+ /**
+ * Exports a single respondent
+ *
+ * @param string $respondentId
+ */
+ protected function _exportRespondent($respondentId)
+ {
+ $respondentModel = $this->loader->getModels()->getRespondentModel(false);
+ $respondentModel->setFilter(array('gr2o_patient_nr' => $respondentId));
+ $respondentData = $respondentModel->loadFirst();
+
+ $this->html->snippet($this->_respondentSnippet,
+ 'model', $respondentModel,
+ 'data', $respondentData,
+ 'respondentId', $respondentId);
+
+ $tracker = $this->loader->getTracker();
+ $tracks = $tracker->getRespondentTracks($respondentData['gr2o_id_user'], $respondentData['gr2o_id_organization']);
+
+ foreach ($tracks as $trackId => $track) {
+ $this->_exportTrack($track);
+ }
+ }
+
+ /**
+ * Renders the entire report (including layout)
+ *
+ * @param array|string[] $respondentId
+ * @param boolean $group Group same surveys or not
+ * @param string $format html|pdf, the output format to use
+ */
+ public function render($respondents, $group = true, $format = 'html')
+ {
+ $this->_group = $group;
+ $this->_format = $format;
+ $this->html = new MUtil_Html_Sequence();
+
+ $this->html->snippet($this->_reportHeader);
+
+ $respondentCount = count($respondents);
+ $respondentIdx = 0;
+ foreach ($respondents as $respondentId) {
+ $respondentIdx++;
+ $this->_exportRespondent($respondentId);
+
+ if ($respondentIdx < $respondentCount) {
+ // Add some whitespace between patients
+ $this->html->div('', array('style' => 'height: 100px'));
+ }
+ }
+
+ $this->html->snippet($this->_reportFooter, 'respondents', $respondents);
+
+ $this->escort->menu->setVisible(false);
+ if ($this->escort instanceof Gems_Project_Layout_MultiLayoutInterface) {
+ $this->escort->layoutSwitch();
+ }
+ $this->escort->postDispatch(Zend_Controller_Front::getInstance()->getRequest());
+
+ Zend_Controller_Action_HelperBroker::getExistingHelper('layout')->disableLayout();
+ Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->setNoRender(true);
+
+ $this->view->layout()->content = $this->html->render($this->view);
+
+ $content = $this->view->layout->render();
+
+ if ($this->_format == 'pdf') {
+ $content = $this->_convertToPdf($content);
+ $filename = 'respondent-export-' . strtolower($respondentId) . '.pdf';
+
+ header('Content-Type: application/x-download');
+ header('Content-Length: '.strlen($content));
+ header('Content-Disposition: inline; filename="'.$filename.'"');
+ header('Cache-Control: private, max-age=0, must-revalidate');
+ header('Pragma: public');
+ }
+
+ echo $content;
+
+ $this->escort->menu->setVisible(true);
+ }
+
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Loader.php
===================================================================
--- trunk/library/classes/Gems/Loader.php 2012-06-20 16:59:53 UTC (rev 773)
+++ trunk/library/classes/Gems/Loader.php 2012-06-21 09:38:22 UTC (rev 774)
@@ -1,298 +1,317 @@
-<?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 Loader
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id$
- */
-
-/**
- *
- * @package Gems
- * @subpackage Loader
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.4
- */
-class Gems_Loader extends Gems_Loader_LoaderAbstract
-{
- /**
- *
- * @var Gems_Events
- */
- protected $events;
-
- /**
- *
- * @var Gems_Export
- */
- protected $export;
-
- /**
- *
- * @var Gems_Model
- */
- protected $models;
-
- /**
- *
- * @var Gems_Pdf
- */
- protected $pdf;
-
- /**
- *
- * @var Gems_Roles
- */
- protected $roles;
-
- /**
- *
- * @var Gems_Selector
- */
- protected $selector;
-
- /**
- *
- * @var Gems_Snippets_SnippetLoader
- */
- protected $snippetLoader;
-
- /**
- *
- * @var Gems_Tracker
- */
- protected $tracker;
-
- /**
- *
- * @var Gems_Upgrades
- */
- protected $upgrades;
-
- /**
- *
- * @var Gems_User_UserLoader
- */
- protected $userLoader;
-
- /**
- *
- * @var Gems_Util
- */
- protected $util;
-
- /**
- *
- * @var Gems_Versions
- */
- protected $versions;
-
- /**
- * Load project specific menu or general Gems menu otherwise
- *
- * @param GemsEscort $escort
- * @return Gems_Menu
- */
- public function createMenu(GemsEscort $escort)
- {
- return $this->_loadClass('Menu', true, func_get_args());
- }
-
- /**
- *
- * @return Gems_User_User
- */
- public function getCurrentUser()
- {
- $loader = $this->getUserLoader();
-
- return $loader->getCurrentUser();
- }
-
- /**
- *
- * @return gems_Events
- */
- public function getEvents()
- {
- return $this->_getClass('events');
- }
-
- /**
- *
- * @return Gems_Export
- */
- public function getExport()
- {
- return $this->_getClass('export');
- }
-
- /**
- *
- * @return Gems_Model
- */
- public function getModels()
- {
- return $this->_getClass('models', 'model');
- }
-
- /**
- * Returns an organization object, initiated from the database.
- *
- * @param int $organizationId Optional, uses current user when empty
- * @return Gems_User_Organization
- */
- public function getOrganization($organizationId = null)
- {
- $loader = $this->getUserLoader();
-
- return $loader->getOrganization($organizationId);
- }
-
- /**
- *
- * @return Gems_Pdf
- */
- public function getPdf()
- {
- return $this->_getClass('pdf');
- }
-
- /**
- *
- * @param GemsEscort $escort
- * @return Gems_Roles
- */
- public function getRoles(GemsEscort $escort)
- {
- return $this->_getClass('roles', null, array($escort));
- }
-
- /**
- *
- * @return Gems_Selector
- */
- public function getSelector()
- {
- return $this->_getClass('selector');
- }
-
- /**
- *
- * @return Gems_Snippets_SnippetLoader
- */
- public function getSnippetLoader($container)
- {
- $class = $this->_getClass('snippetLoader', 'Snippets_SnippetLoader');
-
- //now add the calling class as a container
- $class->addRegistryContainer($container);
- return $class;
- }
-
- /**
- *
- * @return Gems_Task_TaskAbstract
- */
- public function getTask($name) {
- return $this->_loadClass('Task_' . ucfirst($name), true);
- }
-
- /**
- *
- * @param type $id
- * @return Gems_Task_TaskRunnerBatch
- */
- public function getTaskRunnerBatch($id)
- {
- return $this->_loadClass('Task_TaskRunnerBatch', true, array($id));
- }
-
- /**
- *
- * @return Gems_Tracker_TrackerInterface
- */
- public function getTracker()
- {
- return $this->_getClass('tracker');
- }
-
- /**
- *
- * @return Gems_Upgrades
- */
- public function getUpgrades()
- {
- return $this->_getClass('upgrades');
- }
-
- /**
- *
- * @param string $login_name
- * @param int $organization
- * @return Gems_User_User
- */
- public function getUser($login_name, $organization)
- {
- $loader = $this->getUserLoader();
-
- return $loader->getUser($login_name, $organization);
- }
-
- /**
- *
- * @return Gems_User_UserLoader
- */
- public function getUserLoader()
- {
- return $this->_getClass('userLoader', 'User_UserLoader');
- }
-
- /**
- *
- * @return Gems_Util
- */
- public function getUtil()
- {
- return $this->_getClass('util');
- }
-
- /**
- *
- * @return Gems_Versions
- */
- public function getVersions()
- {
- return $this->_getClass('versions');
- }
+<?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 Loader
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ *
+ * @package Gems
+ * @subpackage Loader
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4
+ */
+class Gems_Loader extends Gems_Loader_LoaderAbstract
+{
+ /**
+ *
+ * @var Gems_Events
+ */
+ protected $events;
+
+ /**
+ *
+ * @var Gems_Export
+ */
+ protected $export;
+
+ /**
+ *
+ * @var Gems_Model
+ */
+ protected $models;
+
+ /**
+ *
+ * @var Gems_Pdf
+ */
+ protected $pdf;
+
+ /**
+ *
+ * @var Gems_Export_RespondentExport
+ */
+ protected $respondentexport;
+
+ /**
+ *
+ * @var Gems_Roles
+ */
+ protected $roles;
+
+ /**
+ *
+ * @var Gems_Selector
+ */
+ protected $selector;
+
+ /**
+ *
+ * @var Gems_Snippets_SnippetLoader
+ */
+ protected $snippetLoader;
+
+ /**
+ *
+ * @var Gems_Tracker
+ */
+ protected $tracker;
+
+ /**
+ *
+ * @var Gems_Upgrades
+ */
+ protected $upgrades;
+
+ /**
+ *
+ * @var Gems_User_UserLoader
+ */
+ protected $userLoader;
+
+ /**
+ *
+ * @var Gems_Util
+ */
+ protected $util;
+
+ /**
+ *
+ * @var Gems_Versions
+ */
+ protected $versions;
+
+ /**
+ * Load project specific menu or general Gems menu otherwise
+ *
+ * @param GemsEscort $escort
+ * @return Gems_Menu
+ */
+ public function createMenu(GemsEscort $escort)
+ {
+ return $this->_loadClass('Menu', true, func_get_args());
+ }
+
+ /**
+ *
+ * @return Gems_User_User
+ */
+ public function getCurrentUser()
+ {
+ $loader = $this->getUserLoader();
+
+ return $loader->getCurrentUser();
+ }
+
+ /**
+ *
+ * @return gems_Events
+ */
+ public function getEvents()
+ {
+ return $this->_getClass('events');
+ }
+
+ /**
+ *
+ * @return Gems_Export
+ */
+ public function getExport()
+ {
+ return $this->_getClass('export');
+ }
+
+ /**
+ *
+ * @return Gems_Model
+ */
+ public function getModels()
+ {
+ return $this->_getClass('models', 'model');
+ }
+
+ /**
+ * Returns an organization object, initiated from the database.
+ *
+ * @param int $organizationId Optional, uses current user when empty
+ * @return Gems_User_Organization
+ */
+ public function getOrganization($organizationId = null)
+ {
+ $loader = $this->getUserLoader();
+
+ return $loader->getOrganization($organizationId);
+ }
+
+ /**
+ *
+ * @return Gems_Pdf
+ */
+ public function getPdf()
+ {
+ return $this->_getClass('pdf');
+ }
+
+ /**
+ *
+ * @return Gems_Export_RespondentExport
+ */
+ public function getRespondentExport($container)
+ {
+ $this->addRegistryContainer($container, 'tmp_export');
+ $class = $this->_getClass('respondentexport', 'Export_RespondentExport');
+ $this->removeRegistryContainer('tmp_export');
+
+ return $class;
+ }
+
+ /**
+ *
+ * @param GemsEscort $escort
+ * @return Gems_Roles
+ */
+ public function getRoles(GemsEscort $escort)
+ {
+ return $this->_getClass('roles', null, array($escort));
+ }
+
+ /**
+ *
+ * @return Gems_Selector
+ */
+ public function getSelector()
+ {
+ return $this->_getClass('selector');
+ }
+
+ /**
+ *
+ * @return Gems_Snippets_SnippetLoader
+ */
+ public function getSnippetLoader($container)
+ {
+ $class = $this->_getClass('snippetLoader', 'Snippets_SnippetLoader');
+
+ //now add the calling class as a container
+ $class->addRegistryContainer($container);
+ return $class;
+ }
+
+ /**
+ *
+ * @return Gems_Task_TaskAbstract
+ */
+ public function getTask($name) {
+ return $this->_loadClass('Task_' . ucfirst($name), true);
+ }
+
+ /**
+ *
+ * @param type $id
+ * @return Gems_Task_TaskRunnerBatch
+ */
+ public function getTaskRunnerBatch($id)
+ {
+ return $this->_loadClass('Task_TaskRunnerBatch', true, array($id));
+ }
+
+ /**
+ *
+ * @return Gems_Tracker_TrackerInterface
+ */
+ public function getTracker()
+ {
+ return $this->_getClass('tracker');
+ }
+
+ /**
+ *
+ * @return Gems_Upgrades
+ */
+ public function getUpgrades()
+ {
+ return $this->_getClass('upgrades');
+ }
+
+ /**
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return Gems_User_User
+ */
+ public function getUser($login_name, $organization)
+ {
+ $loader = $this->getUserLoader();
+
+ return $loader->getUser($login_name, $organization);
+ }
+
+ /**
+ *
+ * @return Gems_User_UserLoader
+ */
+ public function getUserLoader()
+ {
+ return $this->_getClass('userLoader', 'User_UserLoader');
+ }
+
+ /**
+ *
+ * @return Gems_Util
+ */
+ public function getUtil()
+ {
+ return $this->_getClass('util');
+ }
+
+ /**
+ *
+ * @return Gems_Versions
+ */
+ public function getVersions()
+ {
+ return $this->_getClass('versions');
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|