From: <gem...@li...> - 2012-02-16 15:22:46
|
Revision: 497 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=497&view=rev Author: mennodekker Date: 2012-02-16 15:22:35 +0000 (Thu, 16 Feb 2012) Log Message: ----------- Action Helper for batches Modified Paths: -------------- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Controller/Action.php Added Paths: ----------- trunk/library/classes/Gems/Controller/Action/ trunk/library/classes/Gems/Controller/Action/Helper/ trunk/library/classes/Gems/Controller/Action/Helper/BatchRunner.php Added: trunk/library/classes/Gems/Controller/Action/Helper/BatchRunner.php =================================================================== --- trunk/library/classes/Gems/Controller/Action/Helper/BatchRunner.php (rev 0) +++ trunk/library/classes/Gems/Controller/Action/Helper/BatchRunner.php 2012-02-16 15:22:35 UTC (rev 497) @@ -0,0 +1,79 @@ +<?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. + * + * Short description of file + * + * @package Gems + * @subpackage + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Short description for BatchRunner + * + * Long description for class BatchRunner (if any)... + * + * @package Gems + * @subpackage Sample + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + * @deprecated Class deprecated since version 2.0 + */ +class Gems_Controller_Action_Helper_BatchRunner extends Zend_Controller_Action_Helper_Abstract +{ + /** + * + * @param MUtil_Batch_BatchAbstract $batch + * @param string $title + */ + public function direct(MUtil_Batch_BatchAbstract $batch, $title) + { + + if ($batch->run($this->getRequest())) { + exit; + } else { + $controller = $this->getActionController(); + $controller->html->h3($title); + + if ($batch->isFinished()) { + $controller->addMessage($batch->getMessages(true)); + $controller->html->pInfo($batch->getRestartButton($controller->_('Prepare recheck'), array('class' => 'actionlink'))); + } else { + if ($batch->count()) { + $controller->html->pInfo($batch->getStartButton(sprintf($controller->_('Start %s jobs'), $batch->count()))); + $controller->html->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%')); + } else { + $controller->html->pInfo($controller->_('Nothing to do.')); + } + } + } + } +} Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 14:34:19 UTC (rev 496) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 15:22:35 UTC (rev 497) @@ -273,26 +273,9 @@ $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheck' . $surveyId, $this->loader->getCurrentUser()->getUserId(), $where); - if ($batch->run($this->getRequest())) { - exit; - } else { - $this->html->h3( - sprintf($this->_('Checking survey results for the %s survey.'), - $this->db->fetchOne("SELECT gsu_survey_name FROM gems__surveys WHERE gsu_id_survey = ?", $surveyId))); - - if ($batch->isFinished()) { - $this->addMessage($batch->getMessages(true)); - $this->html->pInfo($batch->getRestartButton($this->_('Prepare recheck'), array('class' => 'actionlink'))); - } else { - if ($batch->count()) { - // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); - $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); - } else { - $this->html->pInfo($this->_('No tokens to check.')); - } - } - } + $title = sprintf($this->_('Checking survey results for the %s survey.'), + $this->db->fetchOne("SELECT gsu_survey_name FROM gems__surveys WHERE gsu_id_survey = ?", $surveyId)); + $this->_helper->BatchRunner($batch, $title); } /** @@ -302,24 +285,8 @@ { $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId()); - if ($batch->run($this->getRequest())) { - exit; - } else { - $this->html->h3($this->_('Checking survey results for all surveys.')); - - if ($batch->isFinished()) { - $this->addMessage($batch->getMessages(true)); - $this->html->pInfo($batch->getRestartButton($this->_('Prepare recheck'), array('class' => 'actionlink'))); - } else { - if ($batch->count()) { - // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); - $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); - } else { - $this->html->pInfo($this->_('No tokens to check.')); - } - } - } + $title = $this->_('Checking survey results for all surveys.'); + $this->_helper->BatchRunner($batch, $title); } /** Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-02-16 14:34:19 UTC (rev 496) +++ trunk/library/classes/GemsEscort.php 2012-02-16 15:22:35 UTC (rev 497) @@ -274,6 +274,10 @@ return $acl->getAcl(); } + protected function _initActionHelpers() { + Zend_Controller_Action_HelperBroker::addPrefix('Gems_Controller_Action_Helper'); + } + /** * Initialize the Project or Gems loader. * Modified: trunk/library/classes/MUtil/Controller/Action.php =================================================================== --- trunk/library/classes/MUtil/Controller/Action.php 2012-02-16 14:34:19 UTC (rev 496) +++ trunk/library/classes/MUtil/Controller/Action.php 2012-02-16 15:22:35 UTC (rev 497) @@ -64,7 +64,7 @@ * * @var MUtil_Html_Sequence $html The html object to add content to. */ - protected $html; + public $html; /** * The loader for snippets. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |