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. |
From: <gem...@li...> - 2012-02-20 12:06:37
|
Revision: 500 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=500&view=rev Author: mennodekker Date: 2012-02-20 12:06:25 +0000 (Mon, 20 Feb 2012) Log Message: ----------- Introducing the independent TaskRunnerBatch that can execute all kinds of tasks in a single batch and converted Gems_Tracker_Batch_ProcessTokensBatch to the TaskRunner Modified Paths: -------------- trunk/library/classes/Gems/Loader.php trunk/library/classes/Gems/Tracker.php trunk/library/classes/MUtil/Batch/BatchAbstract.php Added Paths: ----------- trunk/library/classes/Gems/Task/ trunk/library/classes/Gems/Task/CheckTokenCompletion.php trunk/library/classes/Gems/Task/CheckTrackTokens.php trunk/library/classes/Gems/Task/ProcessTokenCompletion.php trunk/library/classes/Gems/Task/TaskAbstract.php trunk/library/classes/Gems/Task/TaskInterface.php trunk/library/classes/Gems/Task/TaskRunnerBatch.php Modified: trunk/library/classes/Gems/Loader.php =================================================================== --- trunk/library/classes/Gems/Loader.php 2012-02-16 17:19:44 UTC (rev 499) +++ trunk/library/classes/Gems/Loader.php 2012-02-20 12:06:25 UTC (rev 500) @@ -203,6 +203,24 @@ /** * + * @return Gems_Task_TaskAbstract + */ + public function getTask($name) { + return $this->_getClass('task', 'Task_' . ucfirst($name)); + } + + /** + * + * @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() Added: trunk/library/classes/Gems/Task/CheckTokenCompletion.php =================================================================== --- trunk/library/classes/Gems/Task/CheckTokenCompletion.php (rev 0) +++ trunk/library/classes/Gems/Task/CheckTokenCompletion.php 2012-02-20 12:06:25 UTC (rev 500) @@ -0,0 +1,85 @@ +<?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 ProcessTokens + * + * Long description for class ProcessTokens (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_Task_CheckTokenCompletion extends Gems_Task_TaskAbstract +{ + /** + * @var Gems_Tracker + */ + public $tracker; + + public function execute($tokenData = null, $userId = null) + { + $this->tracker = $this->loader->getTracker(); + $this->_batch->addToCounter('checkedTokens'); + $token = $this->tracker->getToken($tokenData); + + if ($result = $token->checkTokenCompletion($userId)) { + if ($result & Gems_Tracker_Token::COMPLETION_DATACHANGE) { + $this->_batch->addToCounter('resultDataChanges'); + } + if ($result & Gems_Tracker_Token::COMPLETION_EVENTCHANGE) { + $this->_batch->addToCounter('surveyCompletionChanges'); + } + } + + if ($token->isCompleted()) { + $this->_batch->setTask('processTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId); + } + + if ($this->_batch->getCounter('surveyCompletionChanges')) { + $this->_batch->setMessage('surveyCompletionChanges', sprintf($this->translate->_('Answers changed by survey completion event for %d tokens.'), $this->_batch->getCounter('surveyCompletionChanges'))); + } + + if ($this->_batch->getCounter('resultDataChanges')) { + $this->_batch->setMessage('resultDataChanges', sprintf($this->translate->_('Results and timing changed for %d tokens.'), $this->_batch->getCounter('resultDataChanges'))); + } + + $this->_batch->setMessage('checkedTokens', sprintf($this->translate->_('Checked %d tokens.'), $this->_batch->getCounter('checkedTokens'))); + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Task/CheckTrackTokens.php =================================================================== --- trunk/library/classes/Gems/Task/CheckTrackTokens.php (rev 0) +++ trunk/library/classes/Gems/Task/CheckTrackTokens.php 2012-02-20 12:06:25 UTC (rev 500) @@ -0,0 +1,74 @@ +<?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 CheckTrackTokens + * + * Long description for class CheckTrackTokens (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_Task_CheckTrackTokens extends Gems_Task_TaskAbstract +{ + /** + * @var Gems_Tracker + */ + public $tracker; + + public function execute($respTrackData = null, $userId = null) + { + $this->tracker = $this->loader->getTracker(); + $respTrack = $this->tracker->getRespondentTrack($respTrackData); + $this->_batch->addToCounter('checkedRespondentTracks'); + + if ($result = $respTrack->checkTrackTokens($userId)) { + $this->_batch->addToCounter('tokenDateCauses'); + $this->_batch->addToCounter('tokenDateChanges', $result); + } + + if ($this->_batch->getCounter('tokenDateChanges')) { + $this->_batch->setMessage('tokenDateChanges', sprintf($this->translate->_('%2$d token date changes in %1$d tracks.'), $this->_batch->getCounter('tokenDateCauses'), $this->_batch->getCounter('tokenDateChanges'))); + } + + $this->_batch->setMessage('checkedRespondentTracks', sprintf($this->translate->_('Checked %d tracks.'), $this->_batch->getCounter('checkedRespondentTracks'))); + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Task/ProcessTokenCompletion.php =================================================================== --- trunk/library/classes/Gems/Task/ProcessTokenCompletion.php (rev 0) +++ trunk/library/classes/Gems/Task/ProcessTokenCompletion.php 2012-02-20 12:06:25 UTC (rev 500) @@ -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 ProcessTokenCompletion + * + * Long description for class ProcessTokenCompletion (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_Task_ProcessTokenCompletion extends Gems_Task_TaskAbstract +{ + /** + * @var Gems_Tracker + */ + public $tracker; + + + public function execute($tokenData = null, $userId = null) + { + $this->tracker = $this->loader->getTracker(); + $token = $this->tracker->getToken($tokenData); + + if ($token->isCompleted()) { + $respTrack = $token->getRespondentTrack(); + + if ($result = $respTrack->handleRoundCompletion($token, $userId)) { + $this->_batch->addToCounter('roundCompletionCauses'); + $this->_batch->addToCounter('roundCompletionChanges', $result); + } + + $trackId = $respTrack->getRespondentTrackId(); + $this->_batch->setTask('checkTrackTokens', 'chktrck-' . $trackId, $trackId, $userId); + } + + if ($this->_batch->getCounter('roundCompletionChanges')) { + $this->_batch->setMessage('roundCompletionChanges', sprintf($this->translate->_('%d token round completion events caused changed to %d tokens.'), $this->_batch->getCounter('roundCompletionCauses'), $this->_batch->getCounter('roundCompletionChanges'))); + } + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Task/TaskAbstract.php =================================================================== --- trunk/library/classes/Gems/Task/TaskAbstract.php (rev 0) +++ trunk/library/classes/Gems/Task/TaskAbstract.php 2012-02-20 12:06:25 UTC (rev 500) @@ -0,0 +1,76 @@ +<?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 TaskAbstract + * + * Long description for class TaskAbstract (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 + */ +abstract class Gems_Task_TaskAbstract extends MUtil_Registry_TargetAbstract implements Gems_Task_TaskInterface +{ + /** + * @var Gems_Task_TaskRunnerBatch + */ + protected $_batch; + + /** + * @var array + */ + protected $_params; + + /** + * @var Gems_Loader + */ + public $loader; + + /** + * @var Zend_Translate_Adapter + */ + public $translate; + + public function setBatch(Gems_Task_TaskRunnerBatch $batch) + { + $this->_batch = $batch; + } +} \ No newline at end of file Added: trunk/library/classes/Gems/Task/TaskInterface.php =================================================================== --- trunk/library/classes/Gems/Task/TaskInterface.php (rev 0) +++ trunk/library/classes/Gems/Task/TaskInterface.php 2012-02-20 12:06:25 UTC (rev 500) @@ -0,0 +1,55 @@ +<?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 TaskAbstract + * + * Long description for class TaskAbstract (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 + */ +interface Gems_Task_TaskInterface +{ + public function execute(); + + public function setBatch(Gems_Task_TaskRunnerBatch $batch); +} \ No newline at end of file Added: trunk/library/classes/Gems/Task/TaskRunnerBatch.php =================================================================== --- trunk/library/classes/Gems/Task/TaskRunnerBatch.php (rev 0) +++ trunk/library/classes/Gems/Task/TaskRunnerBatch.php 2012-02-20 12:06:25 UTC (rev 500) @@ -0,0 +1,137 @@ +<?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 TaskRunnerBatch + * + * Long description for class TaskRunnerBatch (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_Task_TaskRunnerBatch extends MUtil_Batch_BatchAbstract +{ + /** + * @var Gems_Loader + */ + public $loader; + + public $minimalStepDurationMs = 1000; + + public function __construct($id = null) + { + parent::__construct($id); + $this->loader = GemsEscort::getInstance()->loader; + } + + /** + * Add a message to the message stack. + * + * @param string $text A message to the user + * @return Gems_Task_TaskRunnerBatch + */ + public function addMessage($text) + { + parent::addMessage($text); + } + + /** + * Increment a named counter + * + * @param string $name + * @param integer $add + * @return integer + */ + public function addToCounter($name, $add = 1) + { + return parent::addToCounter($name, $add); + } + + /** + * Add a task to the stack, optionally adding as much parameters as needed + * + * @param string $task + * @return Gems_Task_TaskRunnerBatch + */ + public function addTask($task, $param1 = null) + { + $params = array_slice(func_get_args(), 1); + $this->addStep('runTask', $task, $params); + + return $this; + } + + public function runTask($task, $params) + { + $params = array_slice(func_get_args(), 1); + $taskClass = $this->loader->getTask($task); + $taskClass->setBatch($this); + call_user_func_array(array($taskClass, 'execute'), $params[0]); + } + + /** + * Add/set a message on the message stack with a specific id. + * + * @param scalar $id + * @param string $text A message to the user + * @return Gems_Task_TaskRunnerBatch + */ + public function setMessage($id, $text) + { + return parent::setMessage($id, $text); + } + + /** + * Add an execution step to the command stack. + * + * @param string $task + * @param mixed $id A unique id to prevent double adding of something to do + * @param mixed $param1 Scalar or array with scalars, as many parameters as needed allowed + * @return Gems_Task_TaskRunnerBatch + */ + public function setTask($task, $id, $param1 = null) + { + $params = array_slice(func_get_args(), 2); + $this->setStep('runTask', $id, $task, $params); + + return $this; + } +} \ No newline at end of file Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-02-16 17:19:44 UTC (rev 499) +++ trunk/library/classes/Gems/Tracker.php 2012-02-20 12:06:25 UTC (rev 500) @@ -128,6 +128,12 @@ /** * + * @var Gems_Loader + */ + protected $loader; + + /** + * * @var Zend_Translate */ protected $translate; @@ -841,6 +847,19 @@ { $where = implode(' ', $tokenSelect->getSelect()->getPart(Zend_Db_Select::WHERE)); + $batch = $this->loader->getTaskRunnerBatch($batch_id); + + if (! $batch->isLoaded()) { + $statement = $tokenSelect->getSelect()->query(); + //Process one row at a time to prevent out of memory errors for really big resultsets + while ($tokenData = $statement->fetch()) { + $tokenId = $tokenData['gto_id_token']; + $batch->setTask('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenId, $userId); + $batch->addToCounter('tokens'); + } + } + + /* $batch = $this->_loadClass('Batch_ProcessTokensBatch', true, array($batch_id)); if (! $batch->isLoaded()) { @@ -850,6 +869,7 @@ $batch->addToken($tokenData['gto_id_token'], $userId); } } + */ return $batch; } Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 17:19:44 UTC (rev 499) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-20 12:06:25 UTC (rev 500) @@ -81,6 +81,13 @@ private $_id; /** + * Holds the last message set by the batch job + * + * @var string + */ + private $_lastMessage = null; + + /** * Stack to keep existing id's. * * @var array @@ -246,6 +253,7 @@ protected function addMessage($text) { $this->_session->messages[] = $text; + $this->_lastMessage = $text; return $this; } @@ -313,6 +321,11 @@ return (string) $this->_functionPrefix; } + protected function getLastMessage() + { + return $this->_lastMessage; + } + /** * String of messages from the batch * @@ -560,7 +573,7 @@ // error_log('Cur: ' . microtime(true) . ' report is '. (microtime(true) > $reportRun ? 'true' : 'false')); if (microtime(true) > $reportRun) { // Communicate progress - $bar->update($this->getProgressPercentage(), end($this->_session->messages)); + $bar->update($this->getProgressPercentage(), $this->getLastMessage()); // INFO: When using PULL $bar->update() should exit the program, // but just let us make sure. @@ -619,6 +632,7 @@ protected function setMessage($id, $text) { $this->_session->messages[$id] = $text; + $this->_lastMessage = $text; return $this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-02-21 18:06:41
|
Revision: 506 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=506&view=rev Author: matijsdejong Date: 2012-02-21 18:06:31 +0000 (Tue, 21 Feb 2012) Log Message: ----------- Simplified finding menu items through controller / action SubMenuItems can be sorted in their display order Added functions for respondent login Added renderClosingTag to HtmlElement.php Modified Paths: -------------- trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Menu.php trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/RespondentUserDefinition.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserDefinitionAbstract.php trunk/library/classes/Gems/User/UserDefinitionInterface.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Html/HtmlElement.php Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-02-21 18:06:31 UTC (rev 506) @@ -189,7 +189,7 @@ $this->addMessage(sprintf($this->_('Automatic mails have been turned off since %s.'), $lock->getLockTime())); $request = $this->getRequest(); - if ($menuItem = $this->menu->findFirst(array($request->getControllerKey() => 'cron', $request->getActionKey() => 'cron-lock'))) { + if ($menuItem = $this->menu->findController('cron', 'cron-lock')) { $menuItem->set('label', $this->_('Turn Automatic Mail Jobs ON')); } } Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-02-21 18:06:31 UTC (rev 506) @@ -48,6 +48,10 @@ */ abstract class Gems_Menu_MenuAbstract { + /** + * + * @var GemsEscort + */ public $escort; protected $_subItems; @@ -597,4 +601,37 @@ } return $this; } + + /** + * Sorts the childeren on their order attribute (instead of the order the were added) + * + * @return Gems_Menu_MenuAbstract (continuation pattern) + */ + public function sortByOrder() + { + uasort($this->_subItems, array(__CLASS__, 'sortOrder')); + + return $this; + } + + /** + * uasort() function for sortByOrder() + * + * @see sortByOrder(); + * + * @param self $aItem + * @param self $bItem + * @return int + */ + public static function sortOrder($aItem, $bItem) + { + $a = $aItem->get('order'); + $b = $bItem->get('order'); + + if ($a == $b) { + return 0; + } + + return $a > $b ? 1 : -1; + } } Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Menu.php 2012-02-21 18:06:31 UTC (rev 506) @@ -417,6 +417,18 @@ } } + /** + * Find a menu item through specifying the controller and action + * + * @param string $controller + * @param string $action + * @return Gems_SubMenuItem + */ + public function findController($controller, $action = 'index') + { + return $this->findItem(array('controller' => $controller, 'action' => $action), false); + } + public function findFirst($request) { $find = $this->request2find($request); Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2012-02-21 18:06:31 UTC (rev 506) @@ -116,6 +116,19 @@ } /** + * Add the table and field to check for respondent login checks + * + * @return Gems_Model_RespondentModel (continuation pattern) + */ + public function addLoginCheck() + { + $this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul'); + $this->addColumn('CASE WHEN gul_id_user IS NULL THEN 0 ELSE 1 END', 'has_login'); + + return $this; + } + + /** * Apply hash function for array_walk_recursive in _checkFilterUsed() * * @see _checkFilterUsed() Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/Organization.php 2012-02-21 18:06:31 UTC (rev 506) @@ -77,6 +77,16 @@ protected $db; /** + * When true respondents of this organization may login + * + * @return boolean + */ + public function allowsRespondentLogin() + { + return (boolean) $this->_get('gor_respondent_group') && $this->canHaveRespondents(); + } + + /** * Set menu parameters from the organization * * @param Gems_Menu_ParameterSource $source @@ -106,10 +116,10 @@ { return (boolean) $this->_get('gor_has_respondents') || $this->_get('gor_add_respondents'); } - + /** * Returns the $key in organizationData when set otherwise the default value - * + * * @param string $key * @param mixed $default * @return mixed Modified: trunk/library/classes/Gems/User/RespondentUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-21 18:06:31 UTC (rev 506) @@ -91,4 +91,16 @@ return $select; } + + /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff() + { + return false; + } } \ No newline at end of file Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/User.php 2012-02-21 18:06:31 UTC (rev 506) @@ -107,6 +107,12 @@ protected $userLoader; /** + * + * @var Gems_Util + */ + protected $util; + + /** * Creates the class for this user. * * @param mixed $settings Array, Zend_Session_Namespace or ArrayObject for this user. @@ -448,6 +454,38 @@ } /** + * Returns a standard greeting for the current user. + * + * @return int + */ + public function getGreeting() + { + if (! $this->_getVar('user_greeting')) { + $greeting = array(); + $greetings = $this->util->getTranslated()->getGenderGreeting(); + + if (isset($greetings[$this->_getVar('user_gender')])) { + $greeting[] = $greetings[$this->_getVar('user_gender')]; + } + if ($this->_getVar('user_last_name')) { + if ($this->_getVar('user_surname_prefix')) { + $greeting[] = $this->_getVar('user_surname_prefix'); + } + $greeting[] = $this->_getVar('user_last_name'); + } else { + $name = $this->getLoginName(); + $name = substr($name, 0, 3) . str_repeat('*', strlen($name) - 2); + $greeting[] = $name; + } + + $this->_setVar('user_greeting', implode(' ', $greeting)); + } + + return $this->_getVar('user_greeting'); + } + + + /** * Returns the group number of the current user. * * @return int @@ -552,7 +590,7 @@ // Set menu OFF $menu->setVisible(false); - $menuItem = $menu->findFirst(array($request->getControllerKey() => 'option', $request->getActionKey() => 'change-password')); + $menuItem = $menu->findController('option', 'change-password'); // This may not yet be true, but is needed for the redirect. $menuItem->set('allowed', true); $menuItem->set('visible', true); @@ -563,6 +601,8 @@ if ($menuItem) { // Prevent redirecting to the current page. if (! ($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) { + echo $menuItem->get('label') . '<br/>'; + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoRoute($menuItem->toRouteUrl($request), null, true); } @@ -655,6 +695,16 @@ } /** + * Returns true when this user is a staff member. + * + * @return boolean + */ + public function isStaff() + { + return (boolean) $this->_getVar('user_staff'); + } + + /** * Allowes a refresh of the existing list of organizations * for this user. * Modified: trunk/library/classes/Gems/User/UserDefinitionAbstract.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2012-02-21 18:06:31 UTC (rev 506) @@ -100,6 +100,18 @@ } /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff() + { + return true; + } + + /** * Return true if the user has a password. * * @param Gems_User_User $user The user to check Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-02-21 18:06:31 UTC (rev 506) @@ -102,6 +102,15 @@ public function getUserData($login_name, $organization); /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff(); + + /** * Return true if the user has a password. * * @param Gems_User_User $user The user to check Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserLoader.php 2012-02-21 18:06:31 UTC (rev 506) @@ -232,6 +232,9 @@ if (! isset($values['user_active'])) { $values['user_active'] = true; } + if (! isset($values['user_staff'])) { + $values['user_staff'] = $definition->isStaff(); + } $values['__user_definition'] = $defName; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/GemsEscort.php 2012-02-21 18:06:31 UTC (rev 506) @@ -741,10 +741,10 @@ $p = $div->p(); if ($user->isActive()) { $p->append(sprintf($this->_('You are logged in as %s'), $user->getFullName())); - $item = $this->menu->findFirst(array($this->request->getControllerKey() => 'index', $this->request->getActionKey() => 'logoff')); + $item = $this->menu->findController('index', 'logoff'); $p->a($item->toHRefAttribute(), $this->_('Logoff'), array('class' => 'logout')); } else { - $item = $this->menu->findFirst(array($this->request->getControllerKey() => 'index', $this->request->getActionKey() => 'login')); + $item = $this->menu->findController('index', 'login'); $p->a($item->toHRefAttribute(), $this->_('You are not logged in'), array('class' => 'logout')); } $item->set('visible', false); @@ -947,7 +947,7 @@ $div = MUtil_Html::create()->div($args, array('id' => 'version')); $version = $this->loader->getVersions()->getVersion(); if (($this->menu instanceof Gems_Menu) && - ($item = $this->menu->findFirst(array('controller'=>'project-information', 'action'=>'changelog'))->toHRefAttribute())) { + ($item = $this->menu->findController('project-information', 'changelog')->toHRefAttribute())) { $link = MUtil_Html::create()->a($version, $item); } else { $link = $version; Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-21 18:06:31 UTC (rev 506) @@ -504,6 +504,19 @@ ); /** + * Some elements, e.g. iframe elements, must always be rendered with a closing + * tag because otherwise some poor browsers get confused. + * + * Overrules $renderWithoutContent: the element is always rendered when + * $renderClosingTag is true. + * + * @see $renderWithoutContent + * + * @var boolean The element is always rendered with a closing tag. + */ + public $renderClosingTag = false; + + /** * Most elements must be rendered even when empty, others should - according to the * xhtml specifications - only be rendered when the element contains some content. * @@ -1071,7 +1084,7 @@ $content = $this->renderContent($view); $has_content = (null !== $content); - if ($has_content || $this->renderWithoutContent) { + if ($has_content || $this->renderWithoutContent || $this->renderClosingTag) { $html = '<' . $this->tagName; @@ -1079,7 +1092,7 @@ $html .= $this->_htmlAttribs($this->_renderAttributes($view)); } - if ($has_content) { + if ($has_content || $this->renderClosingTag) { $html .= '>'; $html .= $content; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-02-23 15:40:41
|
Revision: 515 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=515&view=rev Author: matijsdejong Date: 2012-02-23 15:40:31 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Added SrcArrayAttribute Added documentation Modified Paths: -------------- trunk/library/classes/Gems/Html.php trunk/library/classes/MUtil/Html/AElement.php trunk/library/classes/MUtil/Html/AttributeAbstract.php trunk/library/classes/MUtil/Html/Creator.php trunk/library/classes/MUtil/Html/HrefArrayAttribute.php trunk/library/classes/MUtil/Html/HtmlElement.php trunk/library/classes/MUtil/Html.php Added Paths: ----------- trunk/library/classes/MUtil/Html/SrcArrayAttribute.php Modified: trunk/library/classes/Gems/Html.php =================================================================== --- trunk/library/classes/Gems/Html.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/Gems/Html.php 2012-02-23 15:40:31 UTC (rev 515) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. Modified: trunk/library/classes/MUtil/Html/AElement.php =================================================================== --- trunk/library/classes/MUtil/Html/AElement.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html/AElement.php 2012-02-23 15:40:31 UTC (rev 515) @@ -50,6 +50,15 @@ { public $renderWithoutContent = true; + /** + * An A element, shows the url as content when no other content is available. + * + * Any extra parameters are added as either content, attributes or handled + * as special types, if defined as such for this element. + * + * @param mixed $href We assume the first element contains the href, unless a later element is explicitly specified as such + * @param mixed $arg_array MUtil_Ra::args arguments + */ public function __construct($href, $arg_array = null) { $args = MUtil_Ra::args(func_get_args(), array('href' => 'MUtil_Html_HrefArrayAttribute')); @@ -81,6 +90,15 @@ return parent::_htmlAttribs($attribs); } + /** + * Static helper function to create an A element. + * + * Any extra parameters are added as either content, attributes or handled + * as special types, if defined as such for this element. + * + * @param mixed $href We assume the first element contains the href, unless a later element is explicitly specified as such + * @param mixed $arg_array MUtil_Ra::args arguments + */ public static function a($href, $arg_array = null) { $args = MUtil_Ra::args(func_get_args(), array('href' => 'MUtil_Html_HrefArrayAttribute')); Modified: trunk/library/classes/MUtil/Html/AttributeAbstract.php =================================================================== --- trunk/library/classes/MUtil/Html/AttributeAbstract.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html/AttributeAbstract.php 2012-02-23 15:40:31 UTC (rev 515) @@ -46,7 +46,6 @@ * @license New BSD License * @since Class available since version 1.0 */ - abstract class MUtil_Html_AttributeAbstract implements MUtil_Html_AttributeInterface { public $view; Modified: trunk/library/classes/MUtil/Html/Creator.php =================================================================== --- trunk/library/classes/MUtil/Html/Creator.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html/Creator.php 2012-02-23 15:40:31 UTC (rev 515) @@ -68,6 +68,7 @@ protected $_initialAttributeFunctions = array( 'href' => 'MUtil_Html_HrefArrayAttribute::hrefAttribute', 'onclick' => 'MUtil_Html_OnClickArrayAttribute::onclickAttribute', + 'src' => 'MUtil_Html_SrcArrayAttribute::srcAttribute', 'style' => 'MUtil_Html_StyleArrayAttribute::styleAttribute', ); Modified: trunk/library/classes/MUtil/Html/HrefArrayAttribute.php =================================================================== --- trunk/library/classes/MUtil/Html/HrefArrayAttribute.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html/HrefArrayAttribute.php 2012-02-23 15:40:31 UTC (rev 515) @@ -1,41 +1,53 @@ <?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. - */ - /** - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * 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 MUtil * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ +/** + * Href attribute, i.e the name is fixed. + * + * Behaves as parent class otherwise + * + * @see MUtil_Html_UrlArrayAttribute + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ class MUtil_Html_HrefArrayAttribute extends MUtil_Html_UrlArrayAttribute { public function __construct($args_array = null) @@ -48,4 +60,4 @@ { return new self($commands); } -} \ No newline at end of file +} Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-23 15:40:31 UTC (rev 515) @@ -569,6 +569,9 @@ /** * Make an element with the specified tag name. * + * Any extra parameters are added as either content, attributes or handled + * as special types, if defined as such for this element. + * * @param string $tagName * @param mixed $arg_array MUtil_Ra::args arguments */ Added: trunk/library/classes/MUtil/Html/SrcArrayAttribute.php =================================================================== --- trunk/library/classes/MUtil/Html/SrcArrayAttribute.php (rev 0) +++ trunk/library/classes/MUtil/Html/SrcArrayAttribute.php 2012-02-23 15:40:31 UTC (rev 515) @@ -0,0 +1,63 @@ +<?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 MUtil + * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: AttributeAbstract.php 514 2012-02-23 15:00:56Z matijsdejong $ + */ + +/** + * Src attribute, i.e the name is fixed. + * + * Behaves as parent class otherwise + * + * @see MUtil_Html_UrlArrayAttribute + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ +class MUtil_Html_SrcArrayAttribute extends MUtil_Html_UrlArrayAttribute +{ + public function __construct($args_array = null) + { + $args = func_get_args(); + parent::__construct('src', $args); + } + + public static function srcAttribute(array $commands = null) + { + return new self($commands); + } +} Modified: trunk/library/classes/MUtil/Html.php =================================================================== --- trunk/library/classes/MUtil/Html.php 2012-02-23 15:00:56 UTC (rev 514) +++ trunk/library/classes/MUtil/Html.php 2012-02-23 15:40:31 UTC (rev 515) @@ -154,6 +154,11 @@ return self::name2id($element->getName(), $element->getBelongsTo()); } + /** + * Helper function to access the core creator. + * + * @return MUtil_Html_Creator + */ public static function getCreator() { if (! self::$_creator) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-04-08 16:33:12
|
Revision: 611 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=611&view=rev Author: matijsdejong Date: 2012-04-08 16:33:06 +0000 (Sun, 08 Apr 2012) Log Message: ----------- Updated version numbers Modified Paths: -------------- trunk/library/classes/Gems/Versions.php trunk/library/classes/MUtil/Version.php Modified: trunk/library/classes/Gems/Versions.php =================================================================== --- trunk/library/classes/Gems/Versions.php 2012-04-08 16:30:28 UTC (rev 610) +++ trunk/library/classes/Gems/Versions.php 2012-04-08 16:33:06 UTC (rev 611) @@ -43,12 +43,12 @@ { public final function getBuild() { - return 46; + return 47; } public final function getGemsVersion() { - return '1.5.3'; + return '1.5.4'; } public function getProjectVersion() Modified: trunk/library/classes/MUtil/Version.php =================================================================== --- trunk/library/classes/MUtil/Version.php 2012-04-08 16:30:28 UTC (rev 610) +++ trunk/library/classes/MUtil/Version.php 2012-04-08 16:33:06 UTC (rev 611) @@ -33,8 +33,8 @@ class MUtil_Version { const MAJOR = 1; - const MINOR = 0; - const BUILD = 32; + const MINOR = 1; + const BUILD = 33; public static function get() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-06-14 14:33:49
|
Revision: 763 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=763&view=rev Author: matijsdejong Date: 2012-06-14 14:33:38 +0000 (Thu, 14 Jun 2012) Log Message: ----------- TargetInterface extented with afterRegistry() function ModelAbstract now extends from TargetAbstract Modified Paths: -------------- trunk/library/classes/Gems/Form.php trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php trunk/library/classes/Gems/Model/HiddenOrganizationModel.php trunk/library/classes/Gems/Model/OrganizationModel.php trunk/library/classes/Gems/Model/StaffModel.php trunk/library/classes/Gems/Model.php trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php trunk/library/classes/Gems/Tracker/Model/TrackModel.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php trunk/library/classes/MUtil/Model/ModelAbstract.php trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php trunk/library/classes/MUtil/Registry/Source.php trunk/library/classes/MUtil/Registry/TargetAbstract.php trunk/library/classes/MUtil/Registry/TargetInterface.php Modified: trunk/library/classes/Gems/Form.php =================================================================== --- trunk/library/classes/Gems/Form.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Form.php 2012-06-14 14:33:38 UTC (rev 763) @@ -101,6 +101,15 @@ $this->_scripts[] = $script; } + /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + public function getScripts() { return $this->_scripts; } Modified: trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -3,7 +3,7 @@ /** * 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 @@ -14,7 +14,7 @@ * * 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 @@ -36,8 +36,8 @@ */ /** - * LoaderAbstract is used for classes that chain from Gems_Loader. - * + * LoaderAbstract is used for classes that chain from Gems_Loader. + * * As these classes may need setting of values this subclass implements the * checkRegistryRequestsAnswers() easy access to resources. * @@ -48,6 +48,15 @@ class Gems_Loader_TargetLoaderAbstract extends Gems_Loader_LoaderAbstract implements MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + + /** * Allows the loader to set resources. * * @param string $name Name of resource to set Modified: trunk/library/classes/Gems/Model/HiddenOrganizationModel.php =================================================================== --- trunk/library/classes/Gems/Model/HiddenOrganizationModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/HiddenOrganizationModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,23 +45,9 @@ * @license New BSD License * @since Class available since version 1.0 */ -class Gems_Model_HiddenOrganizationModel extends Gems_Model_JoinModel implements MUtil_Registry_TargetInterface +class Gems_Model_HiddenOrganizationModel extends Gems_Model_JoinModel { /** - * Allows the loader to set resources. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - $this->$name = $resource; - - return true; - } - - /** * Stores the fields that can be used for sorting or filtering in the * sort / filter objects attached to this model. * @@ -94,36 +80,11 @@ return array(); } - /** - * Should be called after answering the request to allow the Target - * to check if all required registry values have been set correctly. - * - * @return boolean False if required values are missing. - */ - public function checkRegistryRequestsAnswers() - { - return true; - } - - /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - public function getCurrentOrganization() { return GemsEscort::getInstance()->getCurrentOrganization(); } - public function getKeyRef($forData, $href = array(), $organizationInKey = null) { $keys = $this->getKeys(); @@ -148,18 +109,4 @@ return $href; } - - /** - * Allows the loader to know the resources to set. - * - * Returns those object variables defined by the subclass but not at the level of this definition. - * - * Can be overruled. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } } Modified: trunk/library/classes/Gems/Model/OrganizationModel.php =================================================================== --- trunk/library/classes/Gems/Model/OrganizationModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/OrganizationModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,7 +45,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Model_OrganizationModel extends Gems_Model_ModelAbstract +class Gems_Model_OrganizationModel extends Gems_Model_JoinModel { /** * @var Gems_Loader Modified: trunk/library/classes/Gems/Model/StaffModel.php =================================================================== --- trunk/library/classes/Gems/Model/StaffModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/StaffModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -46,7 +46,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Model_StaffModel extends Gems_Model_ModelAbstract +class Gems_Model_StaffModel extends Gems_Model_JoinModel { public function __construct(Gems_Loader $loader) { Modified: trunk/library/classes/Gems/Model.php =================================================================== --- trunk/library/classes/Gems/Model.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model.php 2012-06-14 14:33:38 UTC (rev 763) @@ -96,30 +96,6 @@ protected $util; /** - * Create or loads the class. When only loading, this function returns a StaticCall object that - * can be invoked lazely. - * - * @see MUtil_Lazy_StaticCall - * @see MUtil_Registry_TargetInterface - * - * @param type $name - * @param type $create - * @param array $arguments - * @return Gems_Model_ModelAbstract - */ - protected function _loadClass($name, $create = false, array $arguments = array()) - { - $obj = parent::_loadClass($name, $create, $arguments); - - // If it as a Gems_Model_ModelAbstract, run the init method now - if ($obj instanceof Gems_Model_ModelAbstract) { - $obj->init(); - } - - return $obj; - } - - /** * Link the model to the user_logins table. * * @param Gems_Model_JoinModel $model Modified: trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -65,7 +65,7 @@ * @license New BSD License * @since Class available since version 1.4 */ -class Gems_Tracker_Model_StandardTokenModel extends Gems_Model_HiddenOrganizationModel implements MUtil_Registry_TargetInterface +class Gems_Tracker_Model_StandardTokenModel extends Gems_Model_HiddenOrganizationModel { /** * @@ -183,25 +183,6 @@ } /** - * Allows the source to set request. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - if (MUtil_Registry_Source::$verbose) { - MUtil_Echo::r('Resource set: ' . get_class($this) . '->' . __FUNCTION__ . - '("' . $name . '", ' . - (is_object($resource) ? get_class($resource) : gettype($resource)) . ')'); - } - $this->$name = $resource; - - return true; - } - - /** * Sets the labels, format functions, etc... * * @return Gems_Tracker_Model_StandardTokenModel @@ -248,29 +229,6 @@ return $this->translate && $this->util; } - /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - - /** - * Allows the loader to know the resources to set. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } - public function useRespondentTrackAsKey() { $this->setKeys($this->_getKeysFor('gems__respondent2org') + $this->_getKeysFor('gems__tracks')); Modified: trunk/library/classes/Gems/Tracker/Model/TrackModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,11 +45,11 @@ * @license New BSD License * @since Class available since version 1.4 */ -class Gems_Tracker_Model_TrackModel extends MUtil_Model_TableModel implements MUtil_Registry_TargetInterface +class Gems_Tracker_Model_TrackModel extends MUtil_Model_TableModel { /** * Holds the trackData in array with key trackId, for internal caching use only - * + * * @var array */ protected $_trackData = array(); @@ -84,25 +84,6 @@ } /** - * Allows the source to set request. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - if (MUtil_Registry_Source::$verbose) { - MUtil_Echo::r('Resource set: ' . get_class($this) . '->' . __FUNCTION__ . - '("' . $name . '", ' . - (is_object($resource) ? get_class($resource) : gettype($resource)) . ')'); - } - $this->$name = $resource; - - return true; - } - - /** * Sets the labels, format functions, etc... * * @param boolean $detailed True when shopwing detailed information @@ -143,29 +124,6 @@ } /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - - /** - * Allows the loader to know the resources to set. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } - - /** * Get the TrackCompletedEvent for the given trackId * * @param int $trackId Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -644,7 +644,7 @@ * A ModelAbstract->setOnSave() function that returns the input * date as a valid date. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -57,7 +57,7 @@ * @license New BSD License * @since Class available since version 1.0 */ -abstract class MUtil_Model_ModelAbstract +abstract class MUtil_Model_ModelAbstract extends MUtil_Registry_TargetAbstract { const ALIAS_OF = 'alias_of'; const AUTO_SAVE = 'auto_save'; @@ -788,6 +788,14 @@ return false; } + /** + * This is the place to put code to run after object initialization has finished and when all + * registry requests have been answered + */ + public function init() + { + } + public function is($name, $key, $value) { return $value == $this->_getKeyValue($name, $key); Modified: trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php =================================================================== --- trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php 2012-06-14 14:33:38 UTC (rev 763) @@ -131,7 +131,7 @@ * A ModelAbstract->setOnLoad() function that concatenates the * value if it is an array. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved @@ -157,7 +157,7 @@ * A ModelAbstract->setOnSave() function that concatenates the * value if it is an array. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved Modified: trunk/library/classes/MUtil/Registry/Source.php =================================================================== --- trunk/library/classes/MUtil/Registry/Source.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/Source.php 2012-06-14 14:33:38 UTC (rev 763) @@ -144,7 +144,13 @@ } // */ } } - return $target->checkRegistryRequestsAnswers(); + if ($target->checkRegistryRequestsAnswers()) { + $target->afterRegistry(); + + return true; + } else { + return false; + } } /** Modified: trunk/library/classes/MUtil/Registry/TargetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Registry/TargetAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/TargetAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -53,6 +53,15 @@ abstract class MUtil_Registry_TargetAbstract implements MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + + /** * Allows the loader to set resources. * * @param string $name Name of resource to set Modified: trunk/library/classes/MUtil/Registry/TargetInterface.php =================================================================== --- trunk/library/classes/MUtil/Registry/TargetInterface.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/TargetInterface.php 2012-06-14 14:33:38 UTC (rev 763) @@ -53,6 +53,14 @@ interface MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry(); + + /** * Allows the source to set request. * * @param string $name Name of resource to set This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-07-03 11:37:19
|
Revision: 809 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=809&view=rev Author: mennodekker Date: 2012-07-03 11:37:08 +0000 (Tue, 03 Jul 2012) Log Message: ----------- Path order is now correct for tab forms Modified Paths: -------------- trunk/library/classes/Gems/Controller/BrowseEditAction.php trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/Form.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/Form.php Modified: trunk/library/classes/Gems/Controller/BrowseEditAction.php =================================================================== --- trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-07-03 07:39:56 UTC (rev 808) +++ trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-07-03 11:37:08 UTC (rev 809) @@ -299,12 +299,6 @@ public function beforeFormDisplay ($form, $isNew) { if ($this->useTabbedForms || $form instanceof Gems_Form_TableForm) { - /* Not needed anymore @@TODO: Remove when proven, as there is a set tab - //Create the tabs tried in $form->render() but somehow that is never reached - if ($form instanceof Gems_TabForm) { - Gems_TabForm::htmlElementsToTabs($form); - }*/ - //If needed, add a row of link buttons to the bottom of the form if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) { $element = new MUtil_Form_Element_Html('formLinks'); Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-07-03 07:39:56 UTC (rev 808) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-07-03 11:37:08 UTC (rev 809) @@ -103,8 +103,8 @@ */ public function addDisplayGroup(array $elements, $name, $options = null) { - //Add the group as usual - parent::addDisplayGroup($elements, $name, $options); + //Add the group as usual, but skip decorator loading as we don't need that + parent::addDisplayGroup($elements, $name, (array) $options + array('disableLoadDefaultDecorators'=>true)); //Retrieve it and set decorators $group = $this->getDisplayGroup($name); Modified: trunk/library/classes/Gems/Form.php =================================================================== --- trunk/library/classes/Gems/Form.php 2012-07-03 07:39:56 UTC (rev 808) +++ trunk/library/classes/Gems/Form.php 2012-07-03 11:37:08 UTC (rev 809) @@ -90,6 +90,41 @@ $this->setDisableTranslator(true); } + protected function _activateJQueryView(Zend_View_Interface $view = null) + { + if ($this->_no_jquery) { + return; + } + + if (null === $view) { + $view = $this->getView(); + if (null === $view) { + return; + } + } + + parent::_activateJQueryView($view); + + if (false === $view->getPluginLoader('helper')->getPaths('Gems_JQuery_View_Helper')) { + $view->addHelperPath('Gems/JQuery/View/Helper', 'Gems_JQuery_View_Helper'); + } + } + + public function activateJQuery() + { + if ($this->_no_jquery) { + parent::activateJQuery(); + ZendX_JQuery::enableForm($this); + + $this->addPrefixPath('Gems_JQuery_Form_Decorator', 'Gems/JQuery/Form/Decorator/', Zend_Form::DECORATOR); + $this->addPrefixPath('Gems_JQuery_Form_Element', 'Gems/JQuery/Form/Element/', Zend_Form::ELEMENT); + + $this->_activateJQueryView(); + + $this->_no_jquery = false; + } + } + /** * Add a script to the head * Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2012-07-03 07:39:56 UTC (rev 808) +++ trunk/library/classes/Gems/TabForm.php 2012-07-03 11:37:08 UTC (rev 809) @@ -49,6 +49,42 @@ */ private $currentTab = null; + public function __construct($options = null) + { + parent::__construct($options); + + /** + * Make it a JQuery form + * + * NOTE: Do this for all subforms you add afterwards + */ + $this->activateJQuery(); + + /** + * You must set the form id so that you can add your tabPanes to the tabContainer + */ + if (is_null($this->getAttrib('id'))) $this->setAttrib('id', 'mainForm'); + + /** + * Now we add a hidden element to hold the selected tab + */ + $this->addElement(new Zend_Form_Element_Hidden('tab')); + + $jquery = $this->getView()->jQuery(); + /** + * This script handles saving the tab to our hidden input when a new tab is showed + */ + $js = sprintf('%1$s("#tabContainer").bind( "tabsshow", function(event, ui) { + var $tabs = %1$s("#tabContainer").tabs(); + var selected = $tabs.tabs("option", "selected"); // => 0 + %1$s("#%2$s input#tab").val(selected); + });', + ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), + $this->getAttrib('id') + ); + $jquery->addOnLoad($js); + } + /** * Add an element to the form, when a tab (subform) had been added, it will return * the subform instead of the form, keep this in mind when chaining methods @@ -183,144 +219,6 @@ } /** - * Create tabs from MUtil_Form_Element_Tab elements - * - * All elements following an element of type MUtil_Form_Element_Tab will be in tabs - * For these items a subform will be created of the type Gems_Form_TabSubForm - * - * @param Zend_Form $form The form containting the elements - */ - public static function htmlElementsToTabs($form) { - foreach ($form as $element) { - switch (get_class($element)) { - case 'MUtil_Form_Element_Tab': - //Start a new tab - if (isset($tab)) { - //First output the old data - $tabs[$tab->getName()] = $tab; - } - $name = $element->getName(); - $title = $element->getValue(); - if ($title instanceof MUtil_Html_Sequence) $title = $title->render($form->getView()); - $tab = new Gems_Form_TabSubForm(array('name' => $name, 'title' => strip_tags($title))); - $remove[] = $element->getName(); - break; - - case 'Zend_Form_Element_Hidden': - //zorg dat er geen display is voor hidden fields - $element->removeDecorator('htmlTag'); - $element->removeDecorator('Label'); - case 'Gems_Form_TabSubForm': - case 'Zend_Form_Element_Submit': - //Just leave this one out of the tabs - break; - - default: - if (isset($tab)) { - if ($element instanceof Zend_Form_DisplayGroup) { - $groupElements = $element->getElements(); - $groupName = $element->getName(); - $options = $element->getAttribs(); - $options['description'] = $element->getDescription(); - - $elements = array(); - foreach ($groupElements as $groupElement) { - $newElement = clone $groupElement; - $tab->addElement($newElement); - $elements[] = $newElement->getName(); - } - $removeGrp[] = $groupName; - foreach ($elements as $oldElement) { - $remove[] = $oldElement; - } - $tab->addDisplayGroup($elements, $groupName, $options); - } else { - $tab->addElement($element); - $remove[] = $element->getName(); - } - } else { - //Make sure error decorator is the last one! (not really needed inside the tabs, but just to make sure) - $error = $element->getDecorator('Errors'); - if ($error instanceof Zend_Form_Decorator_Errors) { - $element->removeDecorator('Errors'); - $element->addDecorator($error); - } - } - break; - } - } - //Get the final tab info - if (isset($tab)) { - $tabs[$tab->getName()] = $tab; - } - - //Cleanup the form, do this now, because otherwise the loop was reset when removing items - if (isset($remove)) { - foreach($remove as $name) { - $form->removeElement($name); - } - } - if (isset($removeGrp)) { - foreach($removeGrp as $name) { - $form->removeDisplayGroup($name); - } - } - - //Now add the tabs as displaygroups - if (isset($tabs) && is_array($tabs)) { - $form->addSubForms($tabs); - } else { - //Ok no tabs defined... maybe we should do something for display here... - } - - /** - * If the form is populated... and we have a tab set... select it - */ - $form->selectTab($form->getValue('tab')); - } - - /** - * Perfoms some actions needed to initialize the form - */ - public function init() - { - /** - * Make it a JQuery form - * - * NOTE: Do this for all subforms you add afterwards - */ - ZendX_JQuery::enableForm($this); - - $this->addPrefixPath('Gems_JQuery_Form_Decorator', 'Gems/JQuery/Form/Decorator', 'decorator') - ->addElementPrefixPath('Gems_JQuery_Form_Decorator', 'Gems/JQuery/Form/Decorator', 'decorator') - ->addDisplayGroupPrefixPath('Gems_JQuery_Form_Decorator', 'Gems/JQuery/Form/Decorator', 'decorator'); - - /** - * You must set the form id so that you can add your tabPanes to the tabContainer - */ - if (is_null($this->getAttrib('id'))) $this->setAttrib('id', 'mainForm'); - - /** - * Now we add a hidden element to hold the selected tab - */ - $this->addElement(new Zend_Form_Element_Hidden('tab')); - - $jquery = $this->getView()->jQuery(); - /** - * This script handles saving the tab to our hidden input when a new tab is showed - */ - $js = sprintf('%1$s("#tabContainer").bind( "tabsshow", function(event, ui) { - var $tabs = %1$s("#tabContainer").tabs(); - var selected = $tabs.tabs("option", "selected"); // => 0 - %1$s("#%2$s input#tab").val(selected); - });', - ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), - $this->getAttrib('id') - ); - $jquery->addOnLoad($js); - } - - /** * Load the default decorators * * @return void Modified: trunk/library/classes/MUtil/Form.php =================================================================== --- trunk/library/classes/MUtil/Form.php 2012-07-03 07:39:56 UTC (rev 808) +++ trunk/library/classes/MUtil/Form.php 2012-07-03 11:37:08 UTC (rev 809) @@ -92,7 +92,7 @@ Zend_Dojo::enableView($view); } - private function _activateJQueryView(Zend_View_Interface $view = null) + protected function _activateJQueryView(Zend_View_Interface $view = null) { if ($this->_no_jquery) { return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-07-05 14:01:44
|
Revision: 817 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=817&view=rev Author: matijsdejong Date: 2012-07-05 14:01:32 +0000 (Thu, 05 Jul 2012) Log Message: ----------- RoleAction dit not allow empty inheritance GemsEscort->_layoutCrumbs() now uses html objects Modified Paths: -------------- trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2012-07-05 12:33:00 UTC (rev 816) +++ trunk/library/classes/Gems/Default/RoleAction.php 2012-07-05 14:01:32 UTC (rev 817) @@ -84,7 +84,7 @@ $allPrivileges = $this->getUsedPrivileges(); $rolePrivileges = $this->escort->acl->getRolePrivileges(); - $inheritedPrivileges = $rolePrivileges[$data['grl_name']][MUtil_Acl::INHERITED][Zend_Acl::TYPE_ALLOW]; + $inheritedPrivileges = (array) $rolePrivileges[$data['grl_name']][MUtil_Acl::INHERITED][Zend_Acl::TYPE_ALLOW]; $privileges = array_diff_key($allPrivileges, array_flip($inheritedPrivileges)); $inheritedPrivileges = array_intersect_key($allPrivileges, array_flip($inheritedPrivileges)); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-07-05 12:33:00 UTC (rev 816) +++ trunk/library/classes/GemsEscort.php 2012-07-05 14:01:32 UTC (rev 817) @@ -588,11 +588,23 @@ // Must be called after _layoutNavigation() if ($this->menu && $this->menu->isVisible()) { - $div = MUtil_Html::create()->div($args + array('id' => 'crumbs')); - //$div->raw($this->view->navigation()->breadcrumbs()); - $div->raw($this->view->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render()); + $path = $this->menu->getActivePath($this->request); + $last = array_pop($path); - return $div; + // Only display when there is a path of more than one step + if ($path) { + $div = MUtil_Html::create()->div($args + array('id' => 'crumbs')); + $content = $div->seq(); + $content->setGlue(MUtil_Html::raw($this->_(' > '))); + + foreach ($path as $menuItem) { + $content->a($menuItem->toHRefAttribute($this->request), $menuItem->get('label')); + } + + $content->append($last->get('label')); + + return $div; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-07-19 16:56:09
|
Revision: 861 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=861&view=rev Author: matijsdejong Date: 2012-07-19 16:55:57 +0000 (Thu, 19 Jul 2012) Log Message: ----------- AutoFocus.php selectAll can be turned off TableForm uses AutoFocus.php Export can now search on respondent id's and on tracks Modified Paths: -------------- trunk/library/classes/Gems/Default/ExportAction.php trunk/library/classes/Gems/Export.php trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/MUtil/Form/Decorator/AutoFocus.php Modified: trunk/library/classes/Gems/Default/ExportAction.php =================================================================== --- trunk/library/classes/Gems/Default/ExportAction.php 2012-07-19 13:04:48 UTC (rev 860) +++ trunk/library/classes/Gems/Default/ExportAction.php 2012-07-19 16:55:57 UTC (rev 861) @@ -1,4 +1,5 @@ <?php + /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -40,11 +41,17 @@ * @subpackage Default * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License - * @since Class available since version 1.0 + * @since Class available since version 1.4 */ class Gems_Default_ExportAction extends Gems_Controller_Action { /** + * + * @var Zend_Db_Adapter_Abstract + */ + //public $db; + + /** * @var Gems_Export */ public $export; @@ -64,72 +71,42 @@ $this->export->controller = $this; } - public function getTopic($count = 1) - { - return $this->_('Data'); - } - public function getTopicTitle() + /** + * Convert the submitted form-data to a filter to be used for retrieving the data to export + * + * Now only handles the organization ID and consent codes, but can be extended to + * include track info or perform some checks + * + * @param array $data + * @return array + */ + protected function _getFilter($data) { - return $this->_('Export data'); - } + $filter = array(); + if (isset($data['ids'])) { + $idStrings = $data['ids']; - public function indexAction() - { - $this->initHtml(); - //Hacked around to get a self-refreshing form, quite hardcoded but fine for now - if ($form = $this->processForm()) { - if (!$this->getRequest()->isPost() || $form->getElement('export')->isChecked()) { - if ($form->getElement('export')->isChecked()) { - $data = $form->getValues(); - $this->handleExport($data); - } - $this->html->h3($this->getTopicTitle()); - $div = $this->html->div(array('id' => 'mainform')); - $div[] = $form; - } else { - Zend_Layout::resetMvcInstance(); - $this->html->raw($form->render($this->view)); + $idArray = preg_split('/[\s,;]+/', $idStrings, -1, PREG_SPLIT_NO_EMPTY); - //Now add all onload actions to make the form still work - $actions = $this->view->jQuery()->getOnLoadActions(); - $this->html->raw('<script type="text/javascript">'); - foreach ($actions as $action) { - $this->html->raw($action); - } - $this->html->raw('</script>'); + if ($idArray) { + // Make sure output is OK + // $idArray = array_map(array($this->db, 'quote'), $idArray); + + $filter['respondentid'] = $idArray; } } - } - /** - * Handle the form - * - * @param type $saveLabel - * @param type $data - * @return type - */ - public function processForm($saveLabel = null, $data = null) - { - $request = $this->getRequest(); - - if ($request->isPost()) { - $data = $request->getPost() + (array) $data; + if (isset($data['oid'])) { + $filter['organizationid'] = $data['oid']; } else { - //Set the defaults for the form here - $data = $this->export->getDefaults(); + //Invalid id so when nothing selected... we get nothing + //$filter['organizationid'] = '-1'; } + $filter['consentcode'] = array_diff((array) $this->util->getConsentTypes(), (array) $this->util->getConsentRejected()); - $form = $this->getForm($data); - - //Make the form 'autosubmit' so it can refresh - $form->setAttrib('id', 'autosubmit'); - $form->setAutoSubmit(MUtil_Html::attrib('href', array('action' => 'index', MUtil_Model::TEXT_FILTER => null, 'RouteReset' => true)), 'mainform'); - - if ($data) { - $form->populate($data); - } - return $form; + // Gems_Tracker::$verbose = true; + return $filter; } /** @@ -140,14 +117,28 @@ */ public function getForm(&$data) { - $surveys = $this->loader->getUtil()->getDbLookup()->getSurveysForExport(); - $organizations = $this->loader->getCurrentUser()->getAllowedOrganizations(); + $empty = $this->util->getTranslated()->getEmptyDropdownArray(); + $tracks = $empty + $this->util->getTrackData()->getSteppedTracks(); + $surveys = $this->util->getDbLookup()->getSurveysForExport(isset($data['tid']) ? $data['tid'] : null); + $organizations = $this->loader->getCurrentUser()->getRespondentOrganizations(); $types = $this->export->getExportClasses(); //Create the basic form $form = new Gems_Form_TableForm(); + $form->getDecorator('AutoFocus')->setSelectall(false); //Start adding elements + $element = new Zend_Form_Element_Textarea('ids'); + $element->setLabel($this->_('Respondent id\'s')) + ->setAttrib('cols', 60) + ->setAttrib('rows', 4); + $elements[] = $element; + + $element = new Zend_Form_Element_Select('tid'); + $element->setLabel($this->_('Tracks')) + ->setMultiOptions($tracks); + $elements[] = $element; + $element = new Zend_Form_Element_Select('sid'); $element->setLabel($this->_('Survey')) ->setMultiOptions($surveys); @@ -160,12 +151,11 @@ $survey = $this->loader->getTracker()->getSurvey(intval($data['sid'])); $filter = $this->_getFilter($data); $answers = $survey->getRawTokenAnswerRows($filter); - } else { - $answers = array(); + + $element = new MUtil_Form_Element_Exhibitor('records'); + $element->setValue(sprintf($this->_('%s records found.'), count($answers))); + $elements[] = $element; } - $element = new MUtil_Form_Element_Exhibitor('records'); - $element->setValue(sprintf($this->_('%s records found.'), count($answers))); - $elements[] = $element; $element = new Zend_Form_Element_MultiCheckbox('oid'); $element->setLabel($this->_('Organization')) @@ -213,6 +203,17 @@ return $form; } + public function getTopic($count = 1) + { + return $this->_('Data'); + } + + public function getTopicTitle() + { + return $this->_('Export data'); + } + + /** * Take care of exporting the data * @@ -244,25 +245,69 @@ } } + public function indexAction() + { + $this->initHtml(); + + //Hacked around to get a self-refreshing form, quite hardcoded but fine for now + if ($form = $this->processForm()) { + if (!$this->getRequest()->isPost() || $form->getElement('export')->isChecked()) { + if ($form->getElement('export')->isChecked()) { + $data = $form->getValues(); + $this->handleExport($data); + } + $this->html->h3($this->getTopicTitle()); + $div = $this->html->div(array('id' => 'mainform')); + $div[] = $form; + } else { + // We do not need to return the layout, just the form + $this->disableLayout(); + + // $this->html->append($form); + + $this->html->raw($form->render($this->view)); + + //Now add all onload actions to make the form still work + $actions = $this->view->jQuery()->getOnLoadActions(); + $script = $this->html->script(array('type' => "text/javascript")); + foreach ($actions as $action) { + $script->raw($action); + } + $this->html->raw($this->view->inlineScript()); + // MUtil_Echo::track(htmlentities($script->render($this->view))); + // MUtil_Echo::track(htmlentities($this->view->inlineScript())); + $this->html->raw(MUtil_Echo::out()); + } + } + } + /** - * Convert the submitted form-data to a filter to be used for retrieving the data to export + * Handle the form * - * Now only handles the organization ID and consent codes, but can be extended to - * include track info or perform some checks - * - * @param array $data - * @return array + * @param type $saveLabel + * @param type $data + * @return type */ - public function _getFilter($data) { - $filter = array(); - if (isset($data['oid'])) { - $filter['organizationid'] = $data['oid']; + public function processForm($saveLabel = null, $data = null) + { + $request = $this->getRequest(); + + if ($request->isPost()) { + $data = $request->getPost() + (array) $data; } else { - //Invalid id so when nothing selected... we get nothing - //$filter['organizationid'] = '-1'; + //Set the defaults for the form here + $data = $this->export->getDefaults(); } - $filter['consentcode'] = array_diff((array) $this->util->getConsentTypes(), (array) $this->util->getConsentRejected()); - return $filter; + $form = $this->getForm($data); + + //Make the form 'autosubmit' so it can refresh + $form->setAttrib('id', 'autosubmit'); + $form->setAutoSubmit(MUtil_Html::attrib('href', array('action' => 'index', MUtil_Model::TEXT_FILTER => null, 'RouteReset' => true)), 'mainform'); + + if ($data) { + $form->populate($data); + } + return $form; } } \ No newline at end of file Modified: trunk/library/classes/Gems/Export.php =================================================================== --- trunk/library/classes/Gems/Export.php 2012-07-19 13:04:48 UTC (rev 860) +++ trunk/library/classes/Gems/Export.php 2012-07-19 16:55:57 UTC (rev 861) @@ -1,4 +1,5 @@ <?php + /** * Copyright (c) 2011, Erasmus MC * All rights reserved. Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-07-19 13:04:48 UTC (rev 860) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-07-19 16:55:57 UTC (rev 861) @@ -229,7 +229,8 @@ $decorators = $this->getDecorators(); if (empty($decorators)) { - $this->addDecorator('FormElements') + $this->addDecorator('AutoFocus') + ->addDecorator('FormElements') ->addDecorator(array('table' => 'HtmlTag'), array('tag' => 'table', 'class'=>$class)) ->addDecorator(array('tab' => 'HtmlTag'), array('tag' => 'div', 'class' => 'displayGroup')) ->addDecorator('Form'); Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2012-07-19 13:04:48 UTC (rev 860) +++ trunk/library/classes/Gems/Util/DbLookup.php 2012-07-19 16:55:57 UTC (rev 861) @@ -349,9 +349,10 @@ * As this depends on the kind of source used it is in this method so projects can change to * adapt to their own sources. * + * @param int $trackId Optional track id * @return array */ - public function getSurveysForExport() + public function getSurveysForExport($trackId = null) { // Read some data from tables, initialize defaults... $select = $this->db->select(); @@ -360,7 +361,13 @@ $select->from('gems__surveys') ->join('gems__sources', 'gsu_id_source = gso_id_source') ->where('gso_active = 1') + ->where('gsu_id_survey IN (SELECT gto_id_survey FROM gems__tokens WHERE gto_completion_time IS NOT NULL)') ->order(array('gsu_active DESC', 'gsu_survey_name')); + + if ($trackId) { + $select->where('gsu_id_survey IN (SELECT gro_id_survey FROM gems__rounds WHERE gro_id_track = ?)', $trackId); + } + $result = $this->db->fetchAll($select); if ($result) { Modified: trunk/library/classes/MUtil/Form/Decorator/AutoFocus.php =================================================================== --- trunk/library/classes/MUtil/Form/Decorator/AutoFocus.php 2012-07-19 13:04:48 UTC (rev 860) +++ trunk/library/classes/MUtil/Form/Decorator/AutoFocus.php 2012-07-19 16:55:57 UTC (rev 861) @@ -46,6 +46,13 @@ */ class MUtil_Form_Decorator_AutoFocus extends Zend_Form_Decorator_Abstract { + /** + * When true the code attempts to select the text + * + * @var boolean + */ + protected $selectAll = true; + private function _getFocus($element) { // MUtil_Echo::r(get_class($element)); @@ -92,10 +99,44 @@ if (($view !== null) && ($focus !== null)) { // Use try {} around e.select as nog all elements have a select() function - $script = "e = document.getElementById('$focus'); if (e) {e.focus(); try { if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) {e.select();} } catch (ex) {}}"; + $script = "e = document.getElementById('$focus');"; + if ($this->selectAll) { + $script .= " + if (e) { + e.focus(); + try { + if (e.select) { + e.select(); + } + } catch (ex) {} + }"; + } else { + $script .= " + if (e) { + e.focus(); + if (e.setSelectionRange && e.value) { + var len = e.value.length * 2; + e.setSelectionRange(len, len); + } else { + e.value = e.value + } + }"; + } $view->inlineScript()->appendScript($script); } return $content; } + + /** + * Set the selectAll value + * + * @param type $value + * @return MUtil_Form_Decorator_AutoFocus (continuation pattern) + */ + public function setSelectAll($value = true) + { + $this->selectAll = $value; + return $this; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-07-24 08:57:30
|
Revision: 870 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=870&view=rev Author: mennodekker Date: 2012-07-24 08:57:06 +0000 (Tue, 24 Jul 2012) Log Message: ----------- Optimised tableform decorator fiddling to run only when rendering the form. Introduced MUtil_Form->setLazy(boolean) to make a form lazy, otherwise it will be rendered as is since most (if not all) forms are regular forms and Lazy just adds overhead to an object that is complicated enough by itself. Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/Form.php trunk/library/classes/MUtil/Html/InputRenderer.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-07-23 13:33:32 UTC (rev 869) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-07-24 08:57:06 UTC (rev 870) @@ -43,7 +43,8 @@ * @license New BSD License * @since Class available since version 1.4 */ -class Gems_Form_TableForm extends Gems_Form { +class Gems_Form_TableForm extends Gems_Form +{ /** * Whether or not form elements are members of an array * @var bool @@ -52,19 +53,105 @@ private $_alternate = null; - public function __construct($options = null) { - //Needed for alternating rows - $this->_alternate = new MUtil_Lazy_Alternate(array('odd','even')); - parent::__construct($options); + protected function _fixDecoratorDisplayGroup(&$element) + { + // Display group + $element->setDecorators(array('FormElements', + array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), + array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly' => true)), + 'Tooltip', + array('Description', array('tag' => 'label', 'class' => 'optional', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false)), + array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class' => 'label', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'openOnly' => true)), + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $element->getName() . ' ' . $element->getAttrib('class'))) + )); + + //Now add the right decorators to the elements + $groupElements = $element->getElements(); + foreach ($groupElements as $groupElement) { + $dec1 = $this->_getImportantDecorator($groupElement); + + $decorators = array(array('Description', array('class' => 'description')), + 'Errors', + 'Tooltip', + ); + + //If we want to see the individual fields labels, do so: + if ($element->getAttrib('showLabels') === true) { + if ($groupElement instanceof Zend_Form_Element_Checkbox) { + $decorators[] = array('Label', array('escape' => false, 'placement' => Zend_Form_Decorator_Label::APPEND)); + } else { + $decorators[] = array('Label', array('escape' => false)); + } + } + + //Apply final class and id to allow for custom styling + $decorators[] = array(array('labelCell' => 'HtmlTag'), array('tag' => 'div', 'class' => 'tab-displaygroup', 'id' => $groupElement->getName() . '_cont')); + + if (!is_null($dec1)) + array_unshift($decorators, $dec1); + $groupElement->setDecorators($decorators); + } } + protected function _fixDecoratorElement(&$element) + { + $dec1 = $this->_getImportantDecorator($element); + $decorators = array( + array('Description', array('class' => 'description')), + 'Errors', + array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), + array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly' => true)), + 'Tooltip', + array('Label', array('escape' => false)), + array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class' => 'label', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'openOnly' => true)), + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $element->getName())) + ); + if (!is_null($dec1)) { + array_unshift($decorators, $dec1); + } + $element->setDecorators($decorators); + } + + protected function _fixDecoratorHiddenSubmit(&$element) + { + //No label and tooltip + $decorators = array( + 'ViewHelper', + array('Description', array('class' => 'description')), + 'Errors', + array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), + array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly' => true)), + 'Tooltip', + array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class' => 'label', 'placement' => Zend_Form_Decorator_Abstract::PREPEND, 'openOnly' => true)), + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName(), 'style' => 'display:none;')) + ); + $element->setDecorators($decorators); + } + + protected function _fixDecoratorHtml(&$element) + { + // Display with colspan = 2 + $decorators = array( + 'ViewHelper', + array('Description', array('class' => 'description')), + 'Errors', + 'Tooltip', + array('Label', array('escape' => false)), + array(array('labelCell' => 'HtmlTag'), array('tag' => 'td', 'class' => 'label', 'colspan' => 2)), + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $element->getAttrib('class') . ' ' . $element->getName())) + ); + + $element->setDecorators($decorators); + } + /** * Get a ViewHelper or ZendX decorator to add in front of the decorator chain * * @param Zend_Form_Element $element * @return null|Zend_Form_Decorator_Abstract */ - private function _getImportantDecorator($element) { + private function _getImportantDecorator($element) + { $class = get_class($element); if (strpos($class, 'JQuery')) { @@ -104,111 +191,33 @@ public function addDisplayGroup(array $elements, $name, $options = null) { //Add the group as usual, but skip decorator loading as we don't need that - parent::addDisplayGroup($elements, $name, (array) $options + array('disableLoadDefaultDecorators'=>true)); - - //Retrieve it and set decorators - $group = $this->getDisplayGroup($name); - $group->setDecorators( array('FormElements', - array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), - array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - 'Tooltip', - array('Description', array('tag'=>'label', 'class'=>'optional', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'escape'=>false)), - array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), - array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) - )); - - //Now add the right decorators to the elements - $groupElements = $group->getElements(); - foreach ($groupElements as $element) { - $dec1 = $this->_getImportantDecorator($element); - - $decorators = array( array('Description', array('class'=>'description')), - 'Errors', - 'Tooltip', - ); - - //If we want to see the individual fields labels, do so: - if ($group->getAttrib('showLabels')===true) { - $decorators[] = array('Label', array('escape'=>false)); - } - - //Apply final class and id to allow for custom styling - $decorators[] = array(array('labelCell' => 'HtmlTag'), array('tag' => 'div', 'class'=>'tab-displaygroup', 'id'=>$element->getName().'_cont')); - - if (!is_null($dec1)) array_unshift($decorators, $dec1); - $element->setDecorators($decorators); - if ($element instanceof Zend_Form_Element_Checkbox) { - $decorator = $element->getDecorator('Label'); - if ($decorator) { - $decorator->setOption('placement', Zend_Form_Decorator_Label::APPEND); - } - } - } - return $this; + return parent::addDisplayGroup($elements, $name, (array) $options + array('disableLoadDefaultDecorators' => true)); } /** - * Add element to stack - * - * Takes care of setting the right decorators for table display - * - * @param string|Zend_Form_Element $element - * @param string $name - * @param array|Zend_Config $options - * @throws Zend_Form_Exception on invalid element - * @return Gems_Form_TableForm + * Fix the decorators so we get the table layout we want. Normally this is called + * only once when rendering the form. */ - public function addElement($element, $name = null, $options = null) + public function fixDecorators() { - parent::addElement($element, $name, $options); + //Needed for alternating rows + $this->_alternate = new MUtil_Lazy_Alternate(array('odd', 'even')); - if (null === $name) { - $name = $element->getName(); - } else { - $element = $this->getElement($name); - } + foreach ($this as $name => $element) { + if ($element instanceof MUtil_Form_Element_Html) { + $this->_fixDecoratorHtml($element); + + } elseif ($element instanceof Zend_Form_Element_Hidden || $element instanceof Zend_Form_Element_Submit) { + $this->_fixDecoratorHiddenSubmit($element); - $dec1 = $this->_getImportantDecorator($element); + } elseif ($element instanceof Zend_Form_Element) { + $this->_fixDecoratorElement($element); + + } elseif ($element instanceof Zend_Form_DisplayGroup) { + $this->_fixDecoratorDisplayGroup($element); - if ($element instanceof MUtil_Form_Element_Html) { - //Colspan 2 - $decorators = array( - array('Description', array('class'=>'description')), - 'Errors', - 'Tooltip', - array('Label', array('escape'=>false)), - array(array('labelCell' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'colspan'=>2)), - array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getAttrib('class') . ' ' . $element->getName())) - ); - } elseif ($element instanceof Zend_Form_Element_Hidden || - $element instanceof Zend_Form_Element_Submit) { - //No label and tooltip - $decorators = array( - array('Description', array('class'=>'description')), - 'Errors', - array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), - array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - 'Tooltip', - array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), - array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) - ); - } else { - $decorators = array( - array('Description', array('class'=>'description')), - 'Errors', - array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), - array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - 'Tooltip', - array('Label', array('escape'=>false)), - array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), - array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) - ); + } } - - if (!is_null($dec1)) array_unshift($decorators, $dec1); - $element->setDecorators($decorators); - - return $this; } /** @@ -230,30 +239,26 @@ $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('AutoFocus') - ->addDecorator('FormElements') - ->addDecorator(array('table' => 'HtmlTag'), array('tag' => 'table', 'class'=>$class)) - ->addDecorator(array('tab' => 'HtmlTag'), array('tag' => 'div', 'class' => 'displayGroup')) - ->addDecorator('Form'); + ->addDecorator('FormElements') + ->addDecorator(array('table' => 'HtmlTag'), array('tag' => 'table', 'class' => $class)) + ->addDecorator(array('tab' => 'HtmlTag'), array('tag' => 'div', 'class' => 'displayGroup')) + ->addDecorator('Form'); } return $this; } - public function setView(Zend_View_Interface $view = null) + /** + * Fix the decorators the first time we try to render the form + * + * @param Zend_View_Interface $view + * @return string + */ + public function render(Zend_View_Interface $view = null) { - //If we set the view, fix the alternating rows - if ($this->_view !== $view) { - foreach($this as $name => $element) { - $decorator = $element->getDecorator('row'); - if ($decorator) { - if ($element instanceof Zend_Form_Element_Hidden) { - $decorator->setOption('style', 'display:none;'); - } else { - $decorator->setOption('class', $this->_alternate . ' ' . $decorator->getOption('class')); - } - } - } + if (!$this->_getIsRendered()) { + $this->fixDecorators(); } - return parent::setView($view); + return parent::render($view); } } \ No newline at end of file Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2012-07-23 13:33:32 UTC (rev 869) +++ trunk/library/classes/Gems/TabForm.php 2012-07-24 08:57:06 UTC (rev 870) @@ -275,16 +275,16 @@ $this->selectTab($tab); } - $form = parent::setView($view); + parent::setView($view); - if ($view) { + if ($this->_view !== $view) { $this->activateJQuery(); if (false === $view->getPluginLoader('helper')->getPaths('Gems_JQuery_View_Helper')) { $view->addHelperPath('Gems/JQuery/View/Helper', 'Gems_JQuery_View_Helper'); } } - return $form; + return $this; } /** Modified: trunk/library/classes/MUtil/Form.php =================================================================== --- trunk/library/classes/MUtil/Form.php 2012-07-23 13:33:32 UTC (rev 869) +++ trunk/library/classes/MUtil/Form.php 2012-07-24 08:57:06 UTC (rev 870) @@ -56,6 +56,8 @@ protected $_no_dojo = true; protected $_no_jquery = true; + protected $_Lazy = false; + /** * Constructor * @@ -200,6 +202,16 @@ } /** + * Return true when the form is lazy + * + * @return boolean + */ + public function isLazy() + { + return $this->_Lazy; + } + + /** * Validate the form * * As it is better for translation utilities to set the labels etc. translated, @@ -361,6 +373,16 @@ } /** + * Is the form Lazy or can it be rendered normally? + * + * @param boolean $lazy + */ + public function setLazy($lazy = false) + { + $this->_Lazy = (bool) $lazy; + } + + /** * Set view object * * @param Zend_View_Interface $view Modified: trunk/library/classes/MUtil/Html/InputRenderer.php =================================================================== --- trunk/library/classes/MUtil/Html/InputRenderer.php 2012-07-23 13:33:32 UTC (rev 869) +++ trunk/library/classes/MUtil/Html/InputRenderer.php 2012-07-24 08:57:06 UTC (rev 870) @@ -357,8 +357,12 @@ public static function renderForm(Zend_View_Abstract $view, Zend_Form $form) { - return self::renderUntil($view, $form, - array('Zend_Form_Decorator_Form', 'Zend_Dojo_Form_Decorator_DijitForm')); + if ($form instanceof MUtil_Form && $form->isLazy()) { + return self::renderUntil($view, $form, + array('Zend_Form_Decorator_Form', 'Zend_Dojo_Form_Decorator_DijitForm')); + } else { + return self::renderComplete($view, $form); + } } public static function renderOnly(Zend_View_Abstract $view, $element, array $decorators) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-09-04 08:50:31
|
Revision: 920 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=920&view=rev Author: mennodekker Date: 2012-09-04 08:50:20 +0000 (Tue, 04 Sep 2012) Log Message: ----------- Cleaned up some paths we do not need in forms Simplified formbridge to be more efficient Removed unneeded render from tableform Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/Form.php trunk/library/classes/MUtil/Form.php trunk/library/classes/MUtil/Model/FormBridge.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-08-30 15:21:34 UTC (rev 919) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-09-04 08:50:20 UTC (rev 920) @@ -265,10 +265,12 @@ */ public function render(Zend_View_Interface $view = null) { - if (!$this->_getIsRendered()) { - $this->fixDecorators(); + if ($this->_getIsRendered()) { + return; } + $this->fixDecorators(); + return parent::render($view); } } \ No newline at end of file Modified: trunk/library/classes/Gems/Form.php =================================================================== --- trunk/library/classes/Gems/Form.php 2012-08-30 15:21:34 UTC (rev 919) +++ trunk/library/classes/Gems/Form.php 2012-09-04 08:50:20 UTC (rev 920) @@ -79,10 +79,8 @@ // $this->addPrefixPath(GEMS_PROJECT_NAME_UC . '_Form_Element', GEMS_PROJECT_NAME_UC . '/Form/Element/', Zend_Form::ELEMENT); parent::__construct($options); - $this->addPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator/', Zend_Form::DECORATOR); - $this->addPrefixPath('Gems_Form_Element', 'Gems/Form/Element/', Zend_Form::ELEMENT); + $this->addPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator', Zend_Form::DECORATOR); - $this->addElementPrefixPath(GEMS_PROJECT_NAME_UC . '_Validate', GEMS_PROJECT_NAME_UC . '/Validate/', Zend_Form_Element::VALIDATE); $this->addElementPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator/', Zend_Form_Element::DECORATOR); $this->addElementPrefixPath('Gems_Filter', 'Gems/Filter/', Zend_Form_Element::FILTER); $this->addElementPrefixPath('Gems_Validate', 'Gems/Validate/', Zend_Form_Element::VALIDATE); Modified: trunk/library/classes/MUtil/Form.php =================================================================== --- trunk/library/classes/MUtil/Form.php 2012-08-30 15:21:34 UTC (rev 919) +++ trunk/library/classes/MUtil/Form.php 2012-09-04 08:50:20 UTC (rev 920) @@ -130,7 +130,7 @@ if ($this->_no_jquery) { ZendX_JQuery::enableForm($this); - $this->addPrefixPath('MUtil_JQuery_Form_Decorator', 'MUtil/JQuery/Form/Decorator/', Zend_Form::DECORATOR); + //$this->addPrefixPath('MUtil_JQuery_Form_Decorator', 'MUtil/JQuery/Form/Decorator/', Zend_Form::DECORATOR); $this->addPrefixPath('MUtil_JQuery_Form_Element', 'MUtil/JQuery/Form/Element/', Zend_Form::ELEMENT); $this->_activateJQueryView(); Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2012-08-30 15:21:34 UTC (rev 919) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2012-09-04 08:50:20 UTC (rev 920) @@ -108,7 +108,7 @@ } /** - * Add the element to the for and apply any filters & validators + * Add the element to the form and apply any filters & validators * * @param string $name * @param Zend_Form_Element $element @@ -173,13 +173,7 @@ } if ($validators) { - foreach ($validators as $validator) { - if (is_array($validator)) { - call_user_func_array(array($element, 'addValidator'), $validator); - } else { - $element->addValidator($validator); - } - } + $element->addValidators($validators); } } @@ -244,32 +238,36 @@ if ($allowedOptions) { // Remove options already filled. Using simple array addition // might trigger a lot of lazy calculations that are not needed. + $allowedOptionsFlipped = array_flip($allowedOptions); - //First strip the options that are not allowed + // First strip the options that are not allowed if (MUtil_Model::$verbose) { - $strippedKeys = array_keys(array_diff_key($options, array_flip($allowedOptions))); + $strippedKeys = array_keys(array_diff_key($options, $allowedOptionsflipped)); if (!empty($strippedKeys)) { MUtil_Echo::r($strippedKeys, 'stripped from options for ' . $name); } } - $options = array_intersect_key($options, array_flip($allowedOptions)); + $options = array_intersect_key($options, $allowedOptionsFlipped); - foreach ($allowedOptions as $key => $option) { - if (array_key_exists($option, $options)) { - unset($allowedOptions[$key]); - } - } + // Now get all options from the model, and extract only the allowed ones + $modelOptions = $this->model->get($name); + $modelOptions = array_intersect_key($modelOptions, $allowedOptionsFlipped); - if ($allowedOptions) { - // MUtil_Echo::r($allowedOptions); - $result = $this->model->get($name, $allowedOptions); - return (array) $result + (array) $options; - } + // Merge them: first use supplied $options, and add missing values from model + return (array) $options + (array) $modelOptions; } return $options; } + /** + * Find $name in the $options array and unset it. If not found, return the $default value + * + * @param string $name + * @param array $options + * @param mixed $default + * @return mixed + */ private function _moveOption($name, array &$options, $default = null) { if (isset($options[$name])) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-09-12 15:50:04
|
Revision: 939 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=939&view=rev Author: matijsdejong Date: 2012-09-12 15:49:52 +0000 (Wed, 12 Sep 2012) Log Message: ----------- #566: Finished: surveys and rounds can change / adapt the display of the answer data Found and fixed multi organization bugs in Track and SingleSurvey screens Snippet 'names' arrays can now contain parameters as well LimeSurvey1m9FieldMap.php now includes knowledge of parent question in sub question Found and fixed bug in JoinModel workings Modified Paths: -------------- trunk/library/classes/Gems/Controller/BrowseEditAction.php trunk/library/classes/Gems/Default/TrackAction.php trunk/library/classes/Gems/Default/TrackActionAbstract.php trunk/library/classes/Gems/Default/TrackRoundsAction.php trunk/library/classes/Gems/Event/SurveyDisplayEventInterface.php trunk/library/classes/Gems/Events.php trunk/library/classes/Gems/Loader.php trunk/library/classes/Gems/Snippets/SnippetLoader.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php trunk/library/classes/Gems/Tracker/Survey.php trunk/library/classes/Gems/Tracker/Token.php trunk/library/classes/MUtil/Controller/Action.php trunk/library/classes/MUtil/Html.php trunk/library/classes/MUtil/Model/JoinModel.php trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php Added Paths: ----------- trunk/library/classes/Gems/Event/Survey/Display/ByValue.php trunk/library/classes/Gems/Event/Survey/Display/OnlyAnswered.php trunk/library/classes/Gems/Event/Survey/Display/Reverse.php trunk/library/classes/Gems/Event/SurveyAnswerFilterAbstract.php trunk/library/classes/Gems/Tracker/Snippets/AnswerNameFilterInterface.php Modified: trunk/library/classes/Gems/Controller/BrowseEditAction.php =================================================================== --- trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-09-12 15:49:52 UTC (rev 939) @@ -160,10 +160,9 @@ } // */ if ($this->tableSnippets) { + $snippets = $this->getSnippets($this->tableSnippets, $params); $sequence = new MUtil_Html_Sequence(); - foreach ((array) $this->tableSnippets as $snippetName) { - $snippet = $this->getSnippet($snippetName, $params); - + foreach ($snippets as $snippet) { if ($snippet->hasHtmlOutput()) { $sequence[] = $snippet; } Modified: trunk/library/classes/Gems/Default/TrackAction.php =================================================================== --- trunk/library/classes/Gems/Default/TrackAction.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Default/TrackAction.php 2012-09-12 15:49:52 UTC (rev 939) @@ -483,7 +483,7 @@ $this->_setParam(Gems_Model::RESPONDENT_TRACK, $data['gr2t_id_respondent_track']); - $this->html->h2(sprintf($this->_('%s track for respondent nr %s'), $data['gtr_track_name'], $this->_getParam(MUtil_Model::REQUEST_ID))); + $this->html->h2(sprintf($this->_('%s track for respondent nr %s'), $data['gtr_track_name'], $this->_getParam(MUtil_Model::REQUEST_ID1))); if (! $this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) { $table = parent::getShowTable(); @@ -515,7 +515,8 @@ $this->addSnippet('TrackUsageTextDetailsSnippet', 'trackData', $data); } - $baseUrl[MUtil_Model::REQUEST_ID] = $this->_getIdParam(); + $baseUrl[MUtil_Model::REQUEST_ID1] = $this->_getParam(MUtil_Model::REQUEST_ID1); + $baseUrl[MUtil_Model::REQUEST_ID2] = $this->_getParam(MUtil_Model::REQUEST_ID2); $baseUrl[Gems_Model::RESPONDENT_TRACK] = $this->_getParam(Gems_Model::RESPONDENT_TRACK); $this->addSnippet('TrackTokenOverviewSnippet', 'trackData', $data, 'baseUrl', $baseUrl); Modified: trunk/library/classes/Gems/Default/TrackActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-09-12 15:49:52 UTC (rev 939) @@ -70,11 +70,10 @@ $result[] = parent::_createTable(); if ($this->trackType) { - $id = $this->_getParam(MUtil_Model::REQUEST_ID); + $orgId = trim($this->db->quote($this->_getParam(MUtil_Model::REQUEST_ID2)), "'"); $model = $this->createTrackModel(false, 'index'); $request = $this->getRequest(); - $organisation_id = $this->escort->getCurrentOrganization(); $searchText = $this->_getParam($model->getTextFilter()); $model->applyPostRequest($request); @@ -93,19 +92,24 @@ $filter['gtr_track_type'] = $this->trackType; $filter['gtr_active'] = 1; $filter[] = '(gtr_date_until IS NULL OR gtr_date_until >= CURRENT_DATE) AND gtr_date_start <= CURRENT_DATE'; - $filter[] = "gtr_organizations LIKE '%|$organisation_id|%'"; + $filter[] = "gtr_organizations LIKE '%|$orgId|%'"; - $baseurl = array('action' => 'index', 'gr2o_patient_nr' => $id, MUtil_Model::TEXT_FILTER => $searchText); + $menuParams = array( + 'gr2o_patient_nr' => $this->_getParam(MUtil_Model::REQUEST_ID1), + 'gr2o_id_organization' => $orgId); + $baseUrl = $menuParams + array( + 'action' => 'index', + MUtil_Model::TEXT_FILTER => $searchText); $bridge = new MUtil_Model_TableBridge($model, array('class' => 'browser')); - $bridge->setBaseUrl($baseurl); + $bridge->setBaseUrl($baseUrl); $bridge->setOnEmpty($this->_('No tracks found')); $bridge->getOnEmpty()->class = 'centerAlign'; $bridge->setRepeater($model->loadRepeatable($filter, $this->availableSort)); // Add view button if ($menuItem = $this->findAllowedMenuItem('view')) { - $bridge->addItemLink($menuItem->toActionLinkLower($request, $bridge, array('gr2o_patient_nr' => $id))); + $bridge->addItemLink($menuItem->toActionLinkLower($request, $bridge, $menuParams)); } foreach($model->getItemsOrdered() as $name) { @@ -116,7 +120,7 @@ // Add create button if ($menuItem = $this->findAllowedMenuItem('create')) { - $bridge->addItemLink($menuItem->toActionLinkLower($request, $bridge, array('gr2o_patient_nr' => $id))); + $bridge->addItemLink($menuItem->toActionLinkLower($request, $bridge, $menuParams)); } $result[] = MUtil_Html::create()->h3($this->_('Available tracks')); @@ -141,7 +145,7 @@ $patientId = $this->_getParam(MUtil_Model::REQUEST_ID1); $orgId = $this->_getParam(MUtil_Model::REQUEST_ID2); - return array ($patientId, $orgId); + return array($patientId, $orgId); } abstract protected function addTrackUsage($respId, $orgId, $trackId, $baseUrl); @@ -298,7 +302,7 @@ } else { - $this->addMessage(sprintf($this->_('%s %s not found.'), $this->getTopic(1), $this->_getParam(MUtil_Model::REQUEST_ID))); + $this->addMessage(sprintf($this->_('%s %s not found.'), $this->getTopic(1), $this->_getParam(MUtil_Model::REQUEST_ID1))); } } @@ -322,10 +326,7 @@ $data = $this->getRequest()->getParams(); } - if (isset($data[MUtil_Model::REQUEST_ID])) { - $keys[] = MUtil_Model::REQUEST_ID; - - } elseif (isset($data[MUtil_Model::REQUEST_ID1])) { + if (isset($data[MUtil_Model::REQUEST_ID1])) { $i = 1; while (isset($data[MUtil_Model::REQUEST_ID . $i])) { $keys[] = MUtil_Model::REQUEST_ID . $i; Modified: trunk/library/classes/Gems/Default/TrackRoundsAction.php =================================================================== --- trunk/library/classes/Gems/Default/TrackRoundsAction.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Default/TrackRoundsAction.php 2012-09-12 15:49:52 UTC (rev 939) @@ -256,8 +256,9 @@ $menuSource->setRequestId($trackId); // Tell the menu we're using track id as request id $this->html->p($question); - foreach ($trackEngine->getRoundShowSnippetNames() as $snippet) { - $this->html->append($this->getSnippet($snippet, 'roundId', $roundId, 'trackEngine', $trackEngine, 'trackId', $trackId, 'showMenu', false, 'showTitle', false)); + $snippets = $this->getSnippets($trackEngine->getRoundShowSnippetNames(), 'roundId', $roundId, 'trackEngine', $trackEngine, 'trackId', $trackId, 'showMenu', false, 'showTitle', false); + foreach ($snippets as $snippet) { + $this->html->append($snippet); } $footer = $this->html->p($question, ' ', array('class' => 'centerAlign')); Added: trunk/library/classes/Gems/Event/Survey/Display/ByValue.php =================================================================== --- trunk/library/classes/Gems/Event/Survey/Display/ByValue.php (rev 0) +++ trunk/library/classes/Gems/Event/Survey/Display/ByValue.php 2012-09-12 15:49:52 UTC (rev 939) @@ -0,0 +1,123 @@ +<?php + +/** + * Copyright (c) 2012, 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 Events + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: OnlyAnswered.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Put the highest value first + * + * @package Gems + * @subpackage Events + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.6 + */ +class Gems_Event_Survey_Display_ByValue extends Gems_Event_SurveyAnswerFilterAbstract +{ + /** + * Contains the values of the current token + * + * @var array + */ + private $_values; + + /** + * This function is called in addBrowseTableColumns() to filter the names displayed + * by AnswerModelSnippetGeneric. + * + * @see Gems_Tracker_Snippets_AnswerModelSnippetGeneric + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @param array $currentNames The current names in use (allows chaining) + * @return array Of the names of labels that should be shown + */ + public function filterAnswers(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, array $currentNames) + { + $currentNames = array_combine($currentNames, $currentNames); + $newOrder = array(); + + foreach ($this->_values as $key => $value) { + if (isset($currentNames[$key])) { + if ($parent = $model->get($key, 'parent_question')) { + $count = 0; + foreach ($model->getCol('parent_question') as $name => $currentParent) { + if (isset($currentNames[$name]) && ($currentParent === $parent)) { + $count++; + } + } + // Last occurence of this parent question + if ($count < 2) { + unset($currentNames[$parent]); + } + $newOrder[] = $parent; + + // MUtil_Echo::track($key, $parent); + } + + unset($currentNames[$key]); + $newOrder[] = $key; + } + } + + // MUtil_Echo::track($this->_values, $newOrder + $currentNames); + + return $newOrder + $currentNames; + } + + /** + * Function that returns the snippets to use for this display. + * + * @param Gems_Tracker_Token $token The token to get the snippets for + * @return array of Snippet names or nothing + */ + public function getAnswerDisplaySnippets(Gems_Tracker_Token $token) + { + $this->_values = array_filter($token->getRawAnswers(), 'is_numeric'); + arsort($this->_values); + + return parent::getAnswerDisplaySnippets($token); + } + + /** + * A pretty name for use in dropdown selection boxes. + * + * @return string Name + */ + public function getEventName() + { + return $this->translate->_('Show the highest answer first.'); + } +} Added: trunk/library/classes/Gems/Event/Survey/Display/OnlyAnswered.php =================================================================== --- trunk/library/classes/Gems/Event/Survey/Display/OnlyAnswered.php (rev 0) +++ trunk/library/classes/Gems/Event/Survey/Display/OnlyAnswered.php 2012-09-12 15:49:52 UTC (rev 939) @@ -0,0 +1,118 @@ +<?php + +/** + * Copyright (c) 2012, 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 Events + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: OnlyAnswered.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Display only those questions that have an answer + * + * @package Gems + * @subpackage Events + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.6 + */ +class Gems_Event_Survey_Display_OnlyAnswered extends Gems_Event_SurveyAnswerFilterAbstract +{ + /** + * This function is called in addBrowseTableColumns() to filter the names displayed + * by AnswerModelSnippetGeneric. + * + * @see Gems_Tracker_Snippets_AnswerModelSnippetGeneric + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @param array $currentNames The current names in use (allows chaining) + * @return array Of the names of labels that should be shown + */ + public function filterAnswers(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, array $currentNames) + { + $repeater = $model->loadRepeatable(); + $table = $bridge->getTable(); + $table->setRepeater($repeater); + + if (! $repeater->__start()) { + return $currentNames; + } + + $keys = array(); + while ($row = $repeater->__next()) { + // Add the keys that contain values. + // We don't care about the values in the array. + $keys += array_filter($row->getArrayCopy()); + } + + $lastMain = null; + $names = array(); + foreach ($currentNames as $name) { + $exists = isset($keys[$name]); + + // Keep track of should a main question be displayed. + // The question or a sub question should be answered + if ($model->get($name, 'thClass') === 'question') { + if ($lastMain) { + unset($names[$lastMain]); + } + + if ($exists) { + $lastMain = null; // Has value, display + } else { + $exists = true; // Add to list for the moment + $lastMain = $name; // But keep track for possible removal + } + } elseif ($exists) { + $lastMain = null; // Must display last main question + } + + + if ($exists) { + $names[$name] = $name; + // MUtil_Echo::track($name, $model->get($name, 'thClass'), $model->get($name, 'label')); + } + } + + return $names; + } + + /** + * A pretty name for use in dropdown selection boxes. + * + * @return string Name + */ + public function getEventName() + { + return $this->translate->_('Display only the questions with an answer.'); + } +} Added: trunk/library/classes/Gems/Event/Survey/Display/Reverse.php =================================================================== --- trunk/library/classes/Gems/Event/Survey/Display/Reverse.php (rev 0) +++ trunk/library/classes/Gems/Event/Survey/Display/Reverse.php 2012-09-12 15:49:52 UTC (rev 939) @@ -0,0 +1,74 @@ +<?php + +/** + * Copyright (c) 2012, 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 Events + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: OnlyAnswered.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Put the last question first + * + * @package Gems + * @subpackage Events + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.6 + */ +class Gems_Event_Survey_Display_Reverse extends Gems_Event_SurveyAnswerFilterAbstract +{ + /** + * This function is called in addBrowseTableColumns() to filter the names displayed + * by AnswerModelSnippetGeneric. + * + * @see Gems_Tracker_Snippets_AnswerModelSnippetGeneric + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @param array $currentNames The current names in use (allows chaining) + * @return array Of the names of labels that should be shown + */ + public function filterAnswers(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, array $currentNames) + { + return array_reverse($currentNames); + } + + /** + * A pretty name for use in dropdown selection boxes. + * + * @return string Name + */ + public function getEventName() + { + return $this->translate->_('Reverse the question order.'); + } +} Added: trunk/library/classes/Gems/Event/SurveyAnswerFilterAbstract.php =================================================================== --- trunk/library/classes/Gems/Event/SurveyAnswerFilterAbstract.php (rev 0) +++ trunk/library/classes/Gems/Event/SurveyAnswerFilterAbstract.php 2012-09-12 15:49:52 UTC (rev 939) @@ -0,0 +1,74 @@ +<?php + +/** + * Copyright (c) 2012, 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 Events + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: OnlyAnswered.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Abstract class for defining filters on answer displays + * + * @package Gems + * @subpackage Events + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.6 + */ +abstract class Gems_Event_SurveyAnswerFilterAbstract extends Gems_Registry_TargetAbstract + implements Gems_Event_SurveyDisplayEventInterface, Gems_Tracker_Snippets_AnswerNameFilterInterface +{ + /** + * + * @var Zend_Translate + */ + protected $translate; + + // public function filterAnswers(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, array $currentNames); + + /** + * Function that returns the snippets to use for this display. + * + * @param Gems_Tracker_Token $token The token to get the snippets for + * @return array of Snippet names or nothing + */ + public function getAnswerDisplaySnippets(Gems_Tracker_Token $token) + { + $snippets = (array) $token->getTrackEngine()->getAnswerSnippetNames(); + + $snippets['answerFilter'] = $this; + + return $snippets; + } + + // public function getEventName() +} Modified: trunk/library/classes/Gems/Event/SurveyDisplayEventInterface.php =================================================================== --- trunk/library/classes/Gems/Event/SurveyDisplayEventInterface.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Event/SurveyDisplayEventInterface.php 2012-09-12 15:49:52 UTC (rev 939) @@ -51,8 +51,8 @@ /** * Function that returns the snippets to use for this display. * - * @param boolean $group Should answers be grouped - * @return array of Snippet names + * @param Gems_Tracker_Token $token The token to get the snippets for + * @return array of Snippet names or nothing */ - public function getSnippets($group); + public function getAnswerDisplaySnippets(Gems_Tracker_Token $token); } Modified: trunk/library/classes/Gems/Events.php =================================================================== --- trunk/library/classes/Gems/Events.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Events.php 2012-09-12 15:49:52 UTC (rev 939) @@ -280,9 +280,20 @@ return $this->_loadEvent($eventName, self::SURVEY_COMPLETION_EVENT); } + /** * * @param string $eventName + * @return Gems_Event_SurveyDisplayEventInterface + */ + public function loadSurveyDisplayEvent($eventName) + { + return $this->_loadEvent($eventName, self::SURVEY_DISPLAY_EVENT); + } + + /** + * + * @param string $eventName * @return Gems_Event_TrackCompletedEventInterface */ public function loadTrackCompletionEvent($eventName) Modified: trunk/library/classes/Gems/Loader.php =================================================================== --- trunk/library/classes/Gems/Loader.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Loader.php 2012-09-12 15:49:52 UTC (rev 939) @@ -227,7 +227,7 @@ } /** - * + * * @return Gems_Snippets_SnippetLoader */ public function getSnippetLoader($container) @@ -235,7 +235,7 @@ $class = $this->_getClass('snippetLoader', 'Snippets_SnippetLoader'); //now add the calling class as a container - $class->addRegistryContainer($container); + $class->getSource()->addRegistryContainer($container); return $class; } Modified: trunk/library/classes/Gems/Snippets/SnippetLoader.php =================================================================== --- trunk/library/classes/Gems/Snippets/SnippetLoader.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Snippets/SnippetLoader.php 2012-09-12 15:49:52 UTC (rev 939) @@ -2,7 +2,7 @@ /** * 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 @@ -13,7 +13,7 @@ * * 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 @@ -24,7 +24,7 @@ * 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. - * + * * Gems specific version of the snippet loader * * @package Gems @@ -47,120 +47,21 @@ * @license New BSD License * @since Class available since version 1.5.5 */ -class Gems_Snippets_SnippetLoader extends Gems_Loader_TargetLoaderAbstract implements MUtil_Snippets_SnippetLoaderInterface +class Gems_Snippets_SnippetLoader extends MUtil_Snippets_SnippetLoader { - protected $cascade = 'Snippets'; - - protected $loader; - /** - * @var MUtil_Snippets_SnippetLoader - */ - protected $backup; - - /** - * Initialize the snippetloader (Gems style) + * Sets the source of variables and the first directory for snippets * - * @param mixed $container A container acting as source for MUtil_Registry_Source - * @param array $dirs The directories where to look for requested classes + * @param mixed $source Something that is or can be made into MUtil_Registry_SourceInterface, otheriwse Zend_Registry is used. */ - public function __construct($container = null, $dirs = array()) { - parent::__construct($container, $dirs); - $this->backup = new MUtil_Snippets_SnippetLoader($this); - $this->addDirectory(GEMS_LIBRARY_DIR . '/classes/MUtil/Snippets/Standard'); - } - - - /** - * Add a directory to the front of the list of places where snippets are loaded from. - * - * @param string $dir - * @return MUtil_Snippets_SnippetLoader - */ - public function addDirectory($dir) + public function __construct($source = null) { - if (!array_key_exists('', $this->_dirs)) { - $this->_dirs[''] = array(); - } - array_unshift($this->_dirs[''], $dir); + global $GEMS_DIRS; - return $this->backup->addDirectory($dir); - } + parent::__construct($source); - /** - * Add parameter values to the source for snippets. - * - * @param mixed $container_or_pairs This function can be called with either a single container or a list of name/value pairs. - * @return MUtil_Snippets_SnippetLoader - */ - public function addSource($container_or_pairs) - { - return $this->backup->addSource($container_or_pairs); - } - - /** - * Returns the directories where snippets are loaded from. - * - * @param array $dirs - * @return array - */ - public function getDirectories() - { - return $this->backup->getDirectories(); - } - - /** - * Searches and loads a .php snippet file. - * - * @param string $filename The name of the snippet - * @param array $extraSourceParameters name/value pairs to add to the source for this snippet - * @return MUtil_Snippets_SnippetInterface The snippet - */ - public function getSnippet($filename, array $extraSourceParameters = null) - { - try { - $this->addRegistryContainer($extraSourceParameters, 'tmpContainer'); - $snippet = $this->_loadClass($filename, true); - $this->removeRegistryContainer('tmpContainer'); - } catch (Exception $exc) { - MUtil_Echo::track($exc->getMessage()); - throw $exc; - //Class loading failed, now defer - //$snippet = $this->backup->getSnippet($filename, $extraSourceParameters); + foreach ($GEMS_DIRS as $key => $path) { + $this->addDirectory($path . '/' . $key); } - - return $snippet; } - - /** - * Returns a source of values for snippets. - * - * @return MUtil_Registry_SourceInterface - */ - public function getSource() - { - return $this->backup->getSource(); - } - - /** - * Set the directories where snippets are loaded from. - * - * @param array $dirs - * @return MUtil_Snippets_SnippetLoader (continuation pattern) - */ - public function setDirectories(array $dirs) - { - return $this->backup->setDirectories($dirs); - } - - /** - * Sets the source of variables for snippets - * - * @param MUtil_Registry_SourceInterface $source - * @return MUtil_Snippets_SnippetLoader (continuation pattern) - */ - public function setSource(MUtil_Registry_SourceInterface $source) - { - return $this->backup->setSource($source); - } } \ No newline at end of file Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-09-12 15:49:52 UTC (rev 939) @@ -657,6 +657,24 @@ } /** + * Returns a snippet name that can be used to display the answers to the token or nothing. + * + * @param Gems_Tracker_Token $token + * @return array Of snippet names + */ + public function getRoundAnswerSnippets(Gems_Tracker_Token $token) + { + $this->_ensureRounds(); + $roundId = $token->getRoundId(); + + if (isset($this->_rounds[$roundId]['gro_display_event']) && $this->_rounds[$roundId]['gro_display_event']) { + $event = $this->events->loadSurveyDisplayEvent($this->_rounds[$roundId]['gro_display_event']); + + return $event->getAnswerDisplaySnippets($token); + } + } + + /** * Return the Round Changed event name for this round * * @param int $roundId Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2012-09-12 15:49:52 UTC (rev 939) @@ -188,6 +188,14 @@ public function getPreviousRoundId($roundId, $roundOrder = null); /** + * Returns a snippet name that can be used to display the answers to the token or nothing. + * + * @param Gems_Tracker_Token $token + * @return array Of snippet names + */ + public function getRoundAnswerSnippets(Gems_Tracker_Token $token); + + /** * Return the Round Changed event name for this round * * @param int $roundId Modified: trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2012-09-12 15:49:52 UTC (rev 939) @@ -56,6 +56,14 @@ protected $_fixedSort = array('grc_success' => SORT_DESC, 'gto_round_order' => SORT_ASC, 'gto_valid_from' => SORT_ASC); /** + * Empty or a Gems_Tracker_Snippets_AnswerNameFilterInterface object that is + * used to filter the answers that are displayed. + * + * @var Gems_Tracker_Snippets_AnswerNameFilterInterface + */ + protected $answerFilter; + + /** * Shortfix to add class attribute * * @var string @@ -83,7 +91,7 @@ protected $locale; /** - * Switch to put the display of the cancel and pritn buttons. + * Switch to put the display of the cancel and print buttons. * * @var boolean */ @@ -91,12 +99,12 @@ /** * Switch to enable/disable the 'take' button underneath each - * open token. + * open token. * * @var boolean */ protected $showTakeButton = true; - + /** * Switch to put the display of the headers on or off * @@ -159,8 +167,15 @@ $td->appendAttrib('class', $selectedClass); $td->appendAttrib('class', $bridge->row_class); - foreach($model->getItemsOrdered() as $name) { - if ($label = $model->get($name, 'label')) { + // Apply filter on the answers displayed + $answerNames = $model->getItemsOrdered(); + if ($this->answerFilter instanceof Gems_Tracker_Snippets_AnswerNameFilterInterface) { + $answerNames = $this->answerFilter->filterAnswers($bridge, $model, $answerNames); + } + + foreach($answerNames as $name) { + $label = $model->get($name, 'label'); + if (strlen($label)) { $bridge->thd($label, array('class' => $model->get($name, 'thClass'))); $td = $bridge->td($bridge->$name); Added: trunk/library/classes/Gems/Tracker/Snippets/AnswerNameFilterInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Snippets/AnswerNameFilterInterface.php (rev 0) +++ trunk/library/classes/Gems/Tracker/Snippets/AnswerNameFilterInterface.php 2012-09-12 15:49:52 UTC (rev 939) @@ -0,0 +1,61 @@ +<?php + +/** + * Copyright (c) 2012, 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) 2012 Erasmus MC + * @license New BSD License + * @version $id: AnswerNameFilterInterface.php 203 2012-01-01 12:51:32Z matijs $ + */ + +/** + * Defines filters for answer display + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.5 + */ +interface Gems_Tracker_Snippets_AnswerNameFilterInterface +{ + /** + * This function is called in addBrowseTableColumns() to filter the names displayed + * by AnswerModelSnippetGeneric. + * + * @see Gems_Tracker_Snippets_AnswerModelSnippetGeneric + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @param array $currentNames The current names in use (allows chaining) + * @return array Of the names of labels that should be shown + */ + public function filterAnswers(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model, array $currentNames); +} Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9FieldMap.php 2012-09-12 15:49:52 UTC (rev 939) @@ -599,6 +599,7 @@ public function applyToModel(MUtil_Model_ModelAbstract $model) { $map = $this->_getMap(); + $parent = null; foreach ($map as $name => $field) { @@ -621,8 +622,9 @@ // Juggle the labels for sub-questions etc.. if (isset($field['sq_question'])) { if (isset($tmpres['label'])) { - // Add non answered question for grouping - $model->set('_' . $name . '_', $tmpres); + // Add non answered question for grouping and make it the current parent + $parent = '_' . $name . '_'; + $model->set($parent, $tmpres); } if (isset($field['sq_question1'])) { $tmpres['label'] = MUtil_Html::raw(sprintf($this->translate->_('%s: %s'), $this->removeHtml($field['sq_question']), $this->removeHtml($field['sq_question1']))); @@ -639,6 +641,15 @@ if (isset($field['code']) && (! $model->has($field['code']))) { $name = $field['code']; } + + // Parent storage + if ('question' === $tmpres['thClass']) { + $parent = $name; + } elseif ($parent) { + // Add the name of the parent item + $tmpres['parent_question'] = $parent; + } + $model->set($name, $tmpres); $oldfld = $field; Modified: trunk/library/classes/Gems/Tracker/Survey.php =================================================================== --- trunk/library/classes/Gems/Tracker/Survey.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Survey.php 2012-09-12 15:49:52 UTC (rev 939) @@ -241,6 +241,21 @@ } /** + * Returns a snippet name that can be used to display the answers to the token or nothing. + * + * @param Gems_Tracker_Token $token + * @return array Of snippet names + */ + public function getAnswerSnippetNames(Gems_Tracker_Token $token) + { + if (isset($this->_gemsSurvey['gsu_display_event'])) { + $event = $this->events->loadSurveyDisplayEvent($this->_gemsSurvey['gsu_display_event']); + + return $event->getAnswerDisplaySnippets($token); + } + } + + /** * Returns a model for diaplying the answers to this survey in the requested language. * * @param string $language (ISO) language string Modified: trunk/library/classes/Gems/Tracker/Token.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/Gems/Tracker/Token.php 2012-09-12 15:49:52 UTC (rev 939) @@ -63,7 +63,14 @@ protected $_gemsData = array(); /** + * Helper var for preventing infinite loops * + * @var boolean + */ + protected $_loopCheck = false; + + /** + * * @var Gems_Tracker_Token */ private $_nextToken = null; @@ -555,6 +562,24 @@ public function getAnswerSnippetNames() { if ($this->exists) { + if (! $this->_loopCheck) { + // Events should not call $this->getAnswerSnippetNames() but + // $this->getTrackEngine()->getAnswerSnippetNames(). Just in + // case the code writer made a mistake we have a guard here. + $this->_loopCheck = true; + + $snippets = $this->getTrackEngine()->getRoundAnswerSnippets($this); + + if (! $snippets) { + $snippets = $this->getSurvey()->getAnswerSnippetNames($this); + } + + if ($snippets) { + $this->_loopCheck = false; + return $snippets; + } + } + return $this->getTrackEngine()->getAnswerSnippetNames(); } else { return 'TokenNotFoundSnippet'; @@ -1093,7 +1118,7 @@ $values['gto_return_url'] = $this->calculateReturnUrl(); // MUtil_Echo::track($values); - + $this->_updateToken($values, $userId); $this->handleBeforeAnswering(); Modified: trunk/library/classes/MUtil/Controller/Action.php =================================================================== --- trunk/library/classes/MUtil/Controller/Action.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/MUtil/Controller/Action.php 2012-09-12 15:49:52 UTC (rev 939) @@ -187,20 +187,13 @@ public function addSnippet($filename, $parameter_value_pairs = null) { $extraSource = MUtil_Ra::pairs(func_get_args(), 1); - $snippet = $this->getSnippet($filename, $extraSource); - - if ($snippet->hasHtmlOutput()) { - $this->html[] = $snippet; - return $snippet; - } elseif ($url = $snippet->getRedirectRoute()) { - $snippet->redirectRoute(); - } - - return false; + $results = $this->addSnippets($filename, $extraSource); + return $results ? reset($results) : false; } /** - * Searches and loads a .php snippet file. + * Searches and loads multiple .php snippet files and adds them to this->html using the filename as + * content key, unless that key already exists. * * @param array $filenames Names of snippets * @param MUtil_Ra::pairs $parameter_value_pairs name/value pairs ot add to the source for this snippet @@ -211,13 +204,17 @@ if ($filenames) { $extraSource = MUtil_Ra::pairs(func_get_args(), 1); - $results = array(); - foreach ((array) $filenames as $filename) { - $snippet = $this->getSnippet($filename, $extraSource); + $results = array(); + $snippets = $this->getSnippets($filenames, $extraSource); + foreach ($snippets as $filename => $snippet) { if ($snippet->hasHtmlOutput()) { - $this->html[] = $snippet; - $results[$filename] = $snippet; + if (isset($this->html[$filename])) { + $this->html[] = $snippet; + } else { + $this->html[$filename] = $snippet; + } + $results[$filename] = $snippet; } elseif ($snippet->getRedirectRoute()) { $snippet->redirectRoute(); @@ -288,19 +285,47 @@ */ public function getSnippet($filename, $parameter_value_pairs = null) { - if (! $this->html) { - $this->initHtml(); - } + $extraSource = MUtil_Ra::pairs(func_get_args(), 1); + $results = $this->getSnippets($filename, $extraSource); + return reset($results); + } + /** + * Searches and loads multiple .php snippet file. + * + * @param string $filenames Array of snippet names with optionally extra parameters included + * @param MUtil_Ra::pairs $parameter_value_pairs name/value pairs ot add to the source for this snippet + * @return array Of filename => MUtil_Snippets_SnippetInterface snippets + */ + public function getSnippets($filenames, $parameter_value_pairs = null) + { if (func_num_args() > 1) { $extraSourceParameters = MUtil_Ra::pairs(func_get_args(), 1); } else { $extraSourceParameters = array(); } - $loader = $this->getSnippetLoader(); + if (is_array($filenames)) { + list($filenames, $params) = MUtil_Ra::keySplit($filenames); - return $loader->getSnippet($filename, $extraSourceParameters); + if ($params) { + $extraSourceParameters = $params + $extraSourceParameters; + } + } else { + $filenames = array($filenames); + } + + $results = array(); + + if ($filenames) { + $loader = $this->getSnippetLoader(); + + foreach ($filenames as $filename) { + $results[$filename] = $loader->getSnippet($filename, $extraSourceParameters); + } + } + + return $results; } /** Modified: trunk/library/classes/MUtil/Html.php =================================================================== --- trunk/library/classes/MUtil/Html.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/MUtil/Html.php 2012-09-12 15:49:52 UTC (rev 939) @@ -305,6 +305,19 @@ $extraSourceParameters = array(); } + if (is_array($name)) { + list($names, $params) = MUtil_Ra::keySplit($name); + + if ($params) { + $extraSourceParameters = $params + $extraSourceParameters; + } + if (isset($names[0])) { + $name = $names[0]; + } else { + throw new MUtil_Html_HtmlException('Missing snippet name in call to create snippet.'); + } + } + $loader = self::getSnippetLoader(); $snippet = $loader->getSnippet($name, $extraSourceParameters); Modified: trunk/library/classes/MUtil/Model/JoinModel.php =================================================================== --- trunk/library/classes/MUtil/Model/JoinModel.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/MUtil/Model/JoinModel.php 2012-09-12 15:49:52 UTC (rev 939) @@ -266,28 +266,35 @@ // Gotta repeat this every time, as keys may be set later foreach ($this->_joinFields as $source => $target) { // Use is_string as $target and $target can be e.g. a Zend_Db_Expr() object - if (! (is_string($target) && isset($newValues[$target]) && $newValues[$target])) { - if (! (is_string($source) && isset($newValues[$source]) && $newValues[$source])) { - // MUtil_Echo::track('Missing: ' . $source . ' -> ' . $target); - continue; - } - $newValues[$target] = $newValues[$source]; + // as $source is an index keys it must be a string + if (is_string($target)) { + if (! (isset($newValues[$target]) && $newValues[$target])) { + if (! (isset($newValues[$source]) && $newValues[$source])) { + if (MUtil_Model::$verbose) { + MUtil_Echo::r('Missing: ' . $source . ' -> ' . $target, 'ERROR!'); + } + continue; + } + $newValues[$target] = $newValues[$source]; - } elseif (! (is_string($source) && isset($newValues[$source]) && $newValues[$source])) { - $newValues[$source] = $newValues[$target]; + } elseif (! (isset($newValues[$source]) && $newValues[$source])) { + $newValues[$source] = $newValues[$target]; - } elseif ((strlen($newValues[$target]) > 0) && (strlen($newValues[$source]) > 0) && $newValues[$target] != $newValues[$source]) { - // Join key values changed. - // - // Set the old values as the filter - $filter[$target] = $newValues[$target]; - $filter[$source] = $newValues[$source]; + } elseif ((strlen($newValues[$target]) > 0) && (strlen($newValues[$source]) > 0) && $newValues[$target] != $newValues[$source]) { + // Join key values changed. + // + // Set the old values as the filter + $filter[$target] = $newValues[$target]; + $filter[$source] = $newValues[$source]; - // Switch the target value to the value in the source field. - // - // JOIN FIELD ORDER IS IMPORTANT!!! - // The changed field must be stated first. - $newValues[$target] = $newValues[$source]; + // Switch the target value to the value in the source field. + // + // JOIN FIELD ORDER IS IMPORTANT!!! + // The changing field must be stated first in the join statement. + $newValues[$target] = $newValues[$source]; + } + } elseif ($target instanceof Zend_Db_Expr && (! (isset($newValues[$source]) && $newValues[$source]))) { + $newValues[$source] = $target; } } Modified: trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2012-09-11 14:00:57 UTC (rev 938) +++ trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2012-09-12 15:49:52 UTC (rev 939) @@ -184,12 +184,14 @@ $model->trackUsage(); $table = $this->getBrowseTable($model); - if ($this->browse) { - $paginator = $model->loadPaginator(); - $table->setRepeater($paginator); - $this->addPaginator($table, $paginator); - } else { - $table->setRepeater($model->loadRepeatable()); + if (! $table->getRepeater()) { + if ($this->browse) { + $paginator = $model->loadPaginator(); + $table->setRepeater($paginator); + $this->addPaginator($table, $paginator); + } else { + $table->setRepeater($model->loadRepeatable()); + } } return $table; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-10-25 15:05:36
|
Revision: 998 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=998&view=rev Author: matijsdejong Date: 2012-10-25 15:05:27 +0000 (Thu, 25 Oct 2012) Log Message: ----------- Code cleanup + documentation Extr unitility getRespondentId in DbLookup.php Modified Paths: -------------- trunk/library/classes/Gems/Menu.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2012-10-25 12:55:41 UTC (rev 997) +++ trunk/library/classes/Gems/Menu.php 2012-10-25 15:05:27 UTC (rev 998) @@ -278,7 +278,6 @@ { $orgId = $this->escort->getLoader()->getCurrentUser()->getCurrentOrganizationId(); - // $params = array(MUtil_Model::REQUEST_ID => 'gr2o_patient_nr'); $params = array(MUtil_Model::REQUEST_ID1 => 'gr2o_patient_nr', MUtil_Model::REQUEST_ID2 => 'gr2o_id_organization'); // MAIN RESPONDENTS ITEM Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2012-10-25 12:55:41 UTC (rev 997) +++ trunk/library/classes/Gems/Util/DbLookup.php 2012-10-25 15:05:27 UTC (rev 998) @@ -92,7 +92,7 @@ return $organizations; } - + /** * Return key/value pairs of all active staff members * @@ -338,6 +338,27 @@ return $organizations; } + /** + * Find the respondent id corresponding to this patientNr / Orgid combo + * + * @param string $patientNr + * @param int $orgid + * @return int A respondent id or null + */ + public function getRespondentId($patientNr, $orgid) + { + $result = $this->db->fetchOne("SELECT gr2o_id_user FROM gems__respondent2org WHERE gr2o_patient_nr = ? AND gr2o_id_organization = ?", array($patientNr, $orgid)); + + if ($result !== false) { + return $result; + } + } + + /** + * Returns the roles in the acl + * + * @return array roleId => ucfirst(roleId) + */ public function getRoles() { $roles = array(); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-10-25 12:55:41 UTC (rev 997) +++ trunk/library/classes/GemsEscort.php 2012-10-25 15:05:27 UTC (rev 998) @@ -572,9 +572,9 @@ if ($menuItem) { $contactDiv = MUtil_Html::create()->div( - $args, - array('id' => 'contact') - ); // tooltip + $args, + array('id' => 'contact') + ); // tooltip $contactDiv->a($menuItem->toHRefAttribute(), $menuItem->get('label')); $ul = $menuItem->toUl(); @@ -689,13 +689,13 @@ $icon = isset($this->project->favicon) ? $this->project->favicon : 'favicon.ico'; if (file_exists(GEMS_WEB_DIR . '/' . $icon)) { $this->view->headLink( - array( - 'rel' => 'shortcut icon', - 'href' => $this->basepath->getBasePath() . '/' . $icon, - 'type' => 'image/x-icon' - ), - Zend_View_Helper_Placeholder_Container_Abstract::PREPEND - ); + array( + 'rel' => 'shortcut icon', + 'href' => $this->basepath->getBasePath() . '/' . $icon, + 'type' => 'image/x-icon' + ), + Zend_View_Helper_Placeholder_Container_Abstract::PREPEND + ); } } @@ -749,12 +749,15 @@ if ($locale == $this->view->locale) { $localeDiv->span(strtoupper($locale)); } else { - $localeDiv->a(array( + $localeDiv->a( + array( 'controller' => 'language', 'action' => 'change-ui', 'language' => urlencode($locale), 'current_uri' => $currentUri - ), strtoupper($locale)); + ), + strtoupper($locale) + ); } $localeDiv[] = ' '; } @@ -914,7 +917,12 @@ $url = $this->view->url(array('controller' => 'organization', 'action' => 'change-ui'), null, true); $formDiv = $orgSwitch->form(array('method' => 'get', 'action' => $url))->div(); - $formDiv->input(array('type' => "hidden", 'name' => "current_uri", 'value' => base64_encode($currentUri))); + $formDiv->input( + array( + 'type' => "hidden", + 'name' => "current_uri", + 'value' => base64_encode($currentUri)) + ); $select = $formDiv->select(array('name' => "org", 'onchange' => "javascript:this.form.submit();")); foreach ($orgs as $id => $org) { @@ -1122,7 +1130,9 @@ protected function createProjectClass($className, $paramOne = null, $paramTwo = null) { - if (file_exists(APPLICATION_PATH . '/classes/' . GEMS_PROJECT_NAME_UC . '/' . str_replace('_', '/', $className) . '.php')) { + $filename = APPLICATION_PATH . '/classes/' . GEMS_PROJECT_NAME_UC . '/'; + $filename .= str_replace('_', '/', $className) . '.php'; + if (file_exists($filename)) { $className = GEMS_PROJECT_NAME_UC . '_' . $className; } else { $className = 'Gems_' . $className; @@ -1140,7 +1150,9 @@ return new $className($paramOne, $paramTwo); default: - throw new Gems_Exception_Coding(__CLASS__ . '->' . __FUNCTION__ . '() called with more parameters than possible.'); + throw new Gems_Exception_Coding( + __CLASS__ . '->' . __FUNCTION__ . '() called with more parameters than possible.' + ); } } @@ -1167,7 +1179,9 @@ { // Check the installation if (! isset($this->db)) { - $this->setException(new Gems_Exception_Coding('No database registered in ' . GEMS_PROJECT_NAME . 'Application.ini for key resources.db.')); + $this->setException(new Gems_Exception_Coding( + 'No database registered in ' . GEMS_PROJECT_NAME . 'Application.ini for key resources.db.') + ); } } @@ -1315,7 +1329,9 @@ break; default: - throw new Zend_Application_Exception('Invalid configuration file provided; unknown config type ' . $extension); + throw new Zend_Application_Exception( + 'Invalid configuration file provided; unknown config type ' . $extension + ); } @@ -1402,7 +1418,8 @@ if ($request->isDispatched()) { // Only when we need to render the layout, we run the layout prepare - if (Zend_Controller_Action_HelperBroker::hasHelper('layout') && Zend_Controller_Action_HelperBroker::getExistingHelper('layout')->isEnabled()) { + if (Zend_Controller_Action_HelperBroker::hasHelper('layout') && + Zend_Controller_Action_HelperBroker::getExistingHelper('layout')->isEnabled()) { // Per project layout preparation if (isset($this->project->layoutPrepare)) { @@ -1609,7 +1626,8 @@ // Gems does not use index/index $action = $request->getActionName(); - if (('index' == $request->getControllerName()) && (('index' == $action) || ($user->isActive() && ('login' == $action)))) { + if (('index' == $request->getControllerName()) && + (('index' == $action) || ($user->isActive() && ('login' == $action)))) { // Instead Gems routes to the first available menu item when this is the request target if (! $user->gotoStartPage($this->menu, $request)) { $this->setError( @@ -1758,7 +1776,10 @@ // Count todo $tSelect = $this->getLoader()->getTracker()->getTokenSelect(array( 'all' => 'COUNT(*)', - 'track' => $this->db->quoteInto('SUM(CASE WHEN gto_id_respondent_track = ? THEN 1 ELSE 0 END)', $tokenData['gto_id_respondent_track']))); + 'track' => $this->db->quoteInto( + 'SUM(CASE WHEN gto_id_respondent_track = ? THEN 1 ELSE 0 END)', + $tokenData['gto_id_respondent_track']) + )); $tSelect->andSurveys(array()) ->forRespondent($tokenData['gto_id_respondent'], $tokenData['gto_id_organization']) ->forGroupId($tokenData['gsu_id_primary_group']) @@ -1770,7 +1791,8 @@ $result['{first_name}'] = $tokenData['grs_first_name']; $result['{full_name}'] = implode(' ', $hello); $result['{greeting}'] = implode(' ', $greeting); - $result['{last_name}'] = ($tokenData['grs_surname_prefix'] ? $tokenData['grs_surname_prefix'] . ' ' : '') . $tokenData['grs_last_name']; + $result['{last_name}'] = ($tokenData['grs_surname_prefix'] ? $tokenData['grs_surname_prefix'] . ' ' : ''); + $result['{last_name}'] .= $tokenData['grs_last_name']; array_shift($hello); $result['{name}'] = implode(' ', $hello); @@ -1780,8 +1802,9 @@ $result['{site_ask_url}'] = $orgResults['organization_login_url'] . '/ask/'; // Url's - $url = $orgResults['organization_login_url'] . '/ask/forward/' . MUtil_Model::REQUEST_ID . '/' . $tokenData['gto_id_token']; - $url_input = $result['{site_ask_url}'] . 'index/' . MUtil_Model::REQUEST_ID . '/' . $tokenData['gto_id_token']; + $url = $orgResults['organization_login_url'] . '/ask/forward/' . MUtil_Model::REQUEST_ID . '/'; + $url .= $tokenData['gto_id_token']; + $urlInput = $result['{site_ask_url}'] . 'index/' . MUtil_Model::REQUEST_ID . '/' . $tokenData['gto_id_token']; $result['{survey}'] = $tokenData['gsu_survey_name']; @@ -1792,14 +1815,14 @@ $result['{token}'] = strtoupper($tokenData['gto_id_token']); $result['{token_from}'] = MUtil_Date::format($tokenData['gto_valid_from'], Zend_Date::DATE_LONG, 'yyyy-MM-dd', $locale); - // $result['{token_input}'] = MUtil_Html::create()->a($url_input, $tokenData['gsu_survey_name']); + // $result['{token_input}'] = MUtil_Html::create()->a($urlInput, $tokenData['gsu_survey_name']); // $result['{token_link}'] = MUtil_Html::create()->a($url, $tokenData['gsu_survey_name']); // $result['{token_link}'] = '<a href="' . $url . '">' . $tokenData['gsu_survey_name'] . '</a>'; $result['{token_link}'] = '[url=' . $url . ']' . $tokenData['gsu_survey_name'] . '[/url]'; $result['{token_until}'] = MUtil_Date::format($tokenData['gto_valid_until'], Zend_Date::DATE_LONG, 'yyyy-MM-dd', $locale); $result['{token_url}'] = $url; - $result['{token_url_input}'] = $url_input; + $result['{token_url_input}'] = $urlInput; $result['{track}'] = $tokenData['gtr_track_name']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-11-09 12:13:59
|
Revision: 1009 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1009&view=rev Author: matijsdejong Date: 2012-11-09 12:13:47 +0000 (Fri, 09 Nov 2012) Log Message: ----------- Fix for HtmlElement.php '0' was not seen as content. Speed improvement: removed __call() use in standard Zend_Translate Traits Modified Paths: -------------- trunk/library/classes/Gems/Default/SurveyAction.php trunk/library/classes/Gems/Export/ExportAbstract.php trunk/library/classes/Gems/Export/RespondentExport.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Controller/Action.php trunk/library/classes/MUtil/Html/HtmlElement.php trunk/library/classes/MUtil/Snippets/SnippetAbstract.php Modified: trunk/library/classes/Gems/Default/SurveyAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyAction.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/Gems/Default/SurveyAction.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -56,33 +56,41 @@ public $trackType = 'S'; + /** + * Overrules specific translations for this action + * + * @param string $text Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ public function _($text, $locale = null) { // Thanks to Potemkin adapter there is always a translate variable in MUtil_Controller_Action switch ($text) { case 'Add track': - return $this->translate->_('Add survey', $locale); + return $this->translate->getAdapter()->_('Add survey', $locale); case 'Add another %s track': - return $this->translate->_('Add another %s survey', $locale); + return $this->translate->getAdapter()->_('Add another %s survey', $locale); case 'Adding the %s track to respondent %s': - return $this->translate->_('Adding the %s survey to respondent %s', $locale); + return $this->translate->getAdapter()->_('Adding the %s survey to respondent %s', $locale); case 'Available tracks': - return $this->translate->_('Available surveys', $locale); + return $this->translate->getAdapter()->_('Available surveys', $locale); case 'No tracks found': - return $this->translate->_('No surveys found', $locale); + return $this->translate->getAdapter()->_('No surveys found', $locale); case 'Overview of %s track for respondent %s: %s': - return $this->translate->_('Overview of %s survey for respondent %s: %s', $locale); + return $this->translate->getAdapter()->_('Overview of %s survey for respondent %s: %s', $locale); case 'This track is currently not assigned to this respondent.': - return $this->translate->_('This survey has not been assigned to this respondent.', $locale); + return $this->translate->getAdapter()->_('This survey has not been assigned to this respondent.', $locale); case 'Track %s does not exist.': - return $this->translate->_('Survey %s does not exist.', $locale); + return $this->translate->getAdapter()->_('Survey %s does not exist.', $locale); default: return parent::_($text, $locale); Modified: trunk/library/classes/Gems/Export/ExportAbstract.php =================================================================== --- trunk/library/classes/Gems/Export/ExportAbstract.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/Gems/Export/ExportAbstract.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -79,6 +79,6 @@ */ public function _($text, $locale = null) { - return $this->translate->_($text, $locale); + return $this->translate->getAdapter()->_($text, $locale); } } \ No newline at end of file Modified: trunk/library/classes/Gems/Export/RespondentExport.php =================================================================== --- trunk/library/classes/Gems/Export/RespondentExport.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/Gems/Export/RespondentExport.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -2,7 +2,7 @@ /** * 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 @@ -13,7 +13,7 @@ * * 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 @@ -52,21 +52,21 @@ * @var GemsEscort */ public $escort; - + protected $html; - + /** * * @var Gems_Loader */ public $loader; - + /** * * @var Gems_Project_ProjectSettings */ public $project; - + /** * @var Zend_Translate_Adapter */ @@ -79,7 +79,7 @@ public $util; public $view; - + /** * @var Gems_Pdf */ @@ -88,13 +88,24 @@ public function afterRegistry() { parent::afterRegistry(); - + $this->_pdf = $this->loader->getPdf(); } - + + /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string + * returns the translation + * + * @param string $text Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ public function _($messageid, $locale = null) { - return $this->translate->_($messageid, $locale); + return $this->translate->getAdapter()->_($messageid, $locale); } /** @@ -125,7 +136,7 @@ if ($token->getReceptionCode()->isSuccess()) { return true; } - + return false; } @@ -178,7 +189,7 @@ } } - if ($showToken) { + if ($showToken) { $params = array( 'token' => $token, 'tokenId' => $token->getTokenId(), @@ -187,16 +198,16 @@ 'showSelected' => false, 'showTakeButton' => false, 'grouped' => $groupSurveys); - + $snippets = $token->getAnswerSnippetNames(); - + if (is_array($snippets)) { list($snippets, $snippetParams) = MUtil_Ra::keySplit($snippets); $params = $params + $snippetParams; } - + $this->html->snippet('Export_SurveyHeaderSnippet', 'token', $token); - + foreach($snippets as $snippet) { $this->html->snippet($snippet, $params); } @@ -288,7 +299,7 @@ $this->_exportTrack($track); } } - + /** * Constructs the form * Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -56,9 +56,20 @@ protected $_subItems; + /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string + * returns the translation + * + * @param string $text Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ public function _($text, $locale = null) { - return $this->escort->translate->_($text, $locale); + return $this->escort->translate->getAdapter()->_($text, $locale); } public function __construct(GemsEscort $escort) @@ -604,6 +615,26 @@ abstract public function isVisible(); /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string using plural notations + * Returns the translated string + * + * @see Zend_Locale + * @param string $singular Singular translation string + * @param string $plural Plural translation string + * @param integer $number Number for detecting the correct plural + * @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with + * locale identifier, @see Zend_Locale for more information + * @return string + */ + public function plural($singular, $plural, $number, $locale = null) + { + $args = func_get_args(); + return call_user_func_array(array($this->escort->translate->getAdapter(), 'plural'), $args); + } + + /** * Make sure only the active branch is visible * * @param array $activeBranch Of Gems_Menu_Menu Abstract items Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -130,7 +130,7 @@ */ public function _($text, $locale = null) { - return $this->translate->_($text, $locale); + return $this->translate->getAdapter()->_($text, $locale); } /** Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/GemsEscort.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -66,13 +66,24 @@ */ public $menu; + /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string + * returns the translation + * + * @param string $text Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ public function _($text, $locale = null) { if (! isset($this->request)) { // Locale is fixed by request. $this->setException(new Gems_Exception_Coding('Requested translation before request was made available.')); } - return $this->translate->_($text, $locale); + return $this->translate->getAdapter()->_($text, $locale); } /** @@ -1456,6 +1467,26 @@ } /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string using plural notations + * Returns the translated string + * + * @see Zend_Locale + * @param string $singular Singular translation string + * @param string $plural Plural translation string + * @param integer $number Number for detecting the correct plural + * @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with + * locale identifier, @see Zend_Locale for more information + * @return string + */ + public function plural($singular, $plural, $number, $locale = null) + { + $args = func_get_args(); + return call_user_func_array(array($this->translate->getAdapter(), 'plural'), $args); + } + + /** * Hook 8: Start of dispatchLoop. Called before an action is dispatched * by Zend_Controller_Dispatcher. * Modified: trunk/library/classes/MUtil/Controller/Action.php =================================================================== --- trunk/library/classes/MUtil/Controller/Action.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/MUtil/Controller/Action.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -138,7 +138,7 @@ */ public function _($text, $locale = null) { - return $this->translate->_($text, $locale); + return $this->translate->getAdapter()->_($text, $locale); } /** @@ -483,7 +483,7 @@ public function plural($singular, $plural, $number, $locale = null) { $args = func_get_args(); - return call_user_func_array(array($this->translate, 'plural'), $args); + return call_user_func_array(array($this->translate->getAdapter(), 'plural'), $args); } /* currently not in use Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -1068,8 +1068,11 @@ return $html; } - } elseif ($content = $renderer->renderAny($view, $this->_content)) { - return $content; + } else { + $content = $renderer->renderAny($view, $this->_content); + if (strlen($content)) { + return $content; + } } } Modified: trunk/library/classes/MUtil/Snippets/SnippetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Snippets/SnippetAbstract.php 2012-11-09 11:30:20 UTC (rev 1008) +++ trunk/library/classes/MUtil/Snippets/SnippetAbstract.php 2012-11-09 12:13:47 UTC (rev 1009) @@ -102,7 +102,7 @@ */ public function _($text, $locale = null) { - return $this->translate->_($text, $locale); + return $this->translate->getAdapter()->_($text, $locale); } /** @@ -230,7 +230,7 @@ public function plural($singular, $plural, $number, $locale = null) { $args = func_get_args(); - return call_user_func_array(array($this->translate, 'plural'), $args); + return call_user_func_array(array($this->translate->getAdapter(), 'plural'), $args); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-11-15 14:18:53
|
Revision: 1017 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1017&view=rev Author: matijsdejong Date: 2012-11-15 14:18:41 +0000 (Thu, 15 Nov 2012) Log Message: ----------- Made it possible to declare certain tables in a join model to be update or insert only Modified Paths: -------------- trunk/library/classes/Gems/Model/JoinModel.php trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/Gems/Model.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php trunk/library/classes/MUtil/Model/FormBridge.php trunk/library/classes/MUtil/Model/JoinModel.php Modified: trunk/library/classes/Gems/Model/JoinModel.php =================================================================== --- trunk/library/classes/Gems/Model/JoinModel.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/Gems/Model/JoinModel.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -49,14 +49,14 @@ /** * Create a model that joins two or more tables * - * @param string $name the name of the model - * @param string $startTable The base table for the model - * @param string $fieldPrefix Prefix to use for change fields (date/userid) - * @param bool $saveable Will changes to this table be saved + * @param string $name A name for the model + * @param string $startTable The base table for the model + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants */ public function __construct($name, $startTable, $fieldPrefix = null, $saveable = null) { - parent::__construct($name, $startTable, (null === $saveable ? $fieldPrefix : $saveable)); + parent::__construct($name, $startTable, $this->_checkSaveable($saveable, $fieldPrefix)); if ($fieldPrefix) { Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix); @@ -64,18 +64,33 @@ } /** + * + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @return mixed The saveable setting to use + */ + protected function _checkSaveable($saveable, $fieldPrefix) + { + if (null === $saveable) { + return $fieldPrefix ? parent::SAVE_MODE_ALL : null; + } + + return $saveable; + } + + /** * Add a table to the model with a left join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param string $fieldPrefix Prefix to use for change fields (date/userid) - * @param bool $saveable Will changes to this table be saved + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * * @return Gems_Model_JoinModel */ public function addLeftTable($table, array $joinFields, $fieldPrefix = null, $saveable = null) { - parent::addLeftTable($table, $joinFields, (null === $saveable ? $fieldPrefix : $saveable)); + parent::addLeftTable($table, $joinFields, $this->_checkSaveable($saveable, $fieldPrefix)); if ($fieldPrefix) { Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix); @@ -87,16 +102,16 @@ /** * Add a table to the model with a right join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param string $fieldPrefix Prefix to use for change fields (date/userid) - * @param bool $saveable Will changes to this table be saved + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * * @return Gems_Model_JoinModel */ public function addRightTable($table, array $joinFields, $fieldPrefix = null, $saveable = null) { - parent::addRightTable($table, $joinFields, (null === $saveable ? $fieldPrefix : $saveable)); + parent::addRightTable($table, $joinFields, $this->_checkSaveable($saveable, $fieldPrefix)); if ($fieldPrefix) { Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix); @@ -108,16 +123,16 @@ /** * Add a table to the model with an inner join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param string $fieldPrefix Prefix to use for change fields (date/userid) - * @param bool $saveable Will changes to this table be saved + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * * @return Gems_Model_JoinModel */ public function addTable($table, array $joinFields, $fieldPrefix = null, $saveable = null) { - parent::addTable($table, $joinFields, (null === $saveable ? $fieldPrefix : $saveable)); + parent::addTable($table, $joinFields, $this->_checkSaveable($saveable, $fieldPrefix)); if ($fieldPrefix) { Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix); @@ -127,14 +142,14 @@ /** * - * @param string $table_name Does not test for existence - * @param string $fieldPrefix Prefix to use for change fields (date/userid) - * @param bool $saveable Will changes to this table be saved + * @param string $table_name Does not test for existence + * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * @return Gems_Model_JoinModel */ public function setTableSaveable($table_name, $fieldPrefix = null, $saveable = null) { - parent::setTableSaveable($table_name, (null === $saveable ? $fieldPrefix : $saveable)); + parent::setTableSaveable($table_name, $this->_checkSaveable($saveable, $fieldPrefix)); if ($fieldPrefix) { Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix); Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -128,9 +128,17 @@ */ public function addLoginCheck() { - $this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul'); - $this->addColumn("CASE WHEN gul_id_user IS NULL OR gul_user_class = 'NoLogin' OR gul_can_login = 0 THEN 0 ELSE 1 END", 'has_login'); + $this->addLeftTable( + 'gems__user_logins', + array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), + 'gul', + MUtil_Model_DatabaseModelAbstract::SAVE_MODE_UPDATE | + MUtil_Model_DatabaseModelAbstract::SAVE_MODE_DELETE); + $this->addColumn( + "CASE WHEN gul_id_user IS NULL OR gul_user_class = 'NoLogin' OR gul_can_login = 0 THEN 0 ELSE 1 END", + 'has_login'); + return $this; } Modified: trunk/library/classes/Gems/Model.php =================================================================== --- trunk/library/classes/Gems/Model.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/Gems/Model.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -104,7 +104,13 @@ */ protected function addUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField) { - $model->addTable('gems__user_logins', array($loginField => 'gul_login', $organizationField => 'gul_id_organization'), 'gul'); + $model->addTable( + 'gems__user_logins', + array($loginField => 'gul_login', $organizationField => 'gul_id_organization'), + 'gul', + MUtil_Model_DatabaseModelAbstract::SAVE_MODE_UPDATE | + MUtil_Model_DatabaseModelAbstract::SAVE_MODE_DELETE + ); } /** Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -62,6 +62,30 @@ const KEY_COPIER = '__c_1_3_copy__%s__key_k_0_p_1__'; /** + * Default save mode: execute all saves + */ + const SAVE_MODE_ALL = 7; + + /** + * Allow deletes to be executed + */ + const SAVE_MODE_DELETE = 4; + + /** + * Allow inserts to be executed + */ + const SAVE_MODE_INSERT = 2; + + /** + * Allow updates to be executed + */ + const SAVE_MODE_UPDATE = 1; + + /** + * Do nothing + */ + const SAVE_MODE_NONE = 0; + /** * Name for query filter transformers */ const TEXTFILTER_TRANSFORMER = 'filter_transformer'; @@ -257,7 +281,6 @@ } } } - return $this->_filterDataForSave($tableData, $isNew); } @@ -373,142 +396,148 @@ * @see copyKeys() * * @param Zend_Db_Table_Abstract $table The table to save - * @param array $newValues The values to save, including those for other tables - * @param array $oldKeys The original keys as they where before the changes + * @param array $newValues The values to save, including those for other tables + * @param array $oldKeys The original keys as they where before the changes + * @param int $saveMode Should updates / inserts occur * @return array The values for this table as they were updated */ - protected function _saveTableData(Zend_Db_Table_Abstract $table, array $newValues, array $oldKeys = null) + protected function _saveTableData(Zend_Db_Table_Abstract $table, array $newValues, + array $oldKeys = null, $saveMode = self::SAVE_MODE_ALL) { - if ($newValues) { - $table_name = $this->_getTableName($table); - $primaryKeys = $this->_getKeysFor($table_name); - $primaryCount = count($primaryKeys); - $filter = array(); - $update = true; + if (! $newValues) { + return array(); + } - // MUtil_Echo::r($newValues, $table_name); + $table_name = $this->_getTableName($table); + $primaryKeys = $this->_getKeysFor($table_name); + $primaryCount = count($primaryKeys); + $filter = array(); + $update = true; - foreach ($primaryKeys as $key) { - if (array_key_exists($key, $newValues) && (0 == strlen($newValues[$key]))) { - // Never include null key values - unset($newValues[$key]); - if (MUtil_Model::$verbose) { - MUtil_Echo::r('Null key value: ' . $key, 'INSERT!!'); - } + // MUtil_Echo::r($newValues, $table_name); + foreach ($primaryKeys as $key) { + if (array_key_exists($key, $newValues) && (0 == strlen($newValues[$key]))) { + // Never include null key values + unset($newValues[$key]); + if (MUtil_Model::$verbose) { + MUtil_Echo::r('Null key value: ' . $key, 'INSERT!!'); + } - // Now we know we are not updating - $update = false; + // Now we know we are not updating + $update = false; - } elseif (isset($oldKeys[$key])) { + } elseif (isset($oldKeys[$key])) { + if (MUtil_Model::$verbose) { + MUtil_Echo::r($key . ' => ' . $oldKeys[$key], 'Old key'); + } + $filter[$key . ' = ?'] = $oldKeys[$key]; + // Key values left in $returnValues in case of partial key insert + + } else { + // Check for old key values being stored using copyKeys() + $copyKey = $this->getKeyCopyName($key); + + if (isset($newValues[$copyKey])) { + $filter[$key . ' = ?'] = $newValues[$copyKey]; if (MUtil_Model::$verbose) { - MUtil_Echo::r($key . ' => ' . $oldKeys[$key], 'Old key'); + MUtil_Echo::r($key . ' => ' . $newValues[$copyKey], 'Copy key'); } - $filter[$key . ' = ?'] = $oldKeys[$key]; - // Key values left in $returnValues in case of partial key insert - } else { - // Check for old key values being stored using copyKeys() - $copyKey = $this->getKeyCopyName($key); - - if (isset($newValues[$copyKey])) { - $filter[$key . ' = ?'] = $newValues[$copyKey]; - if (MUtil_Model::$verbose) { - MUtil_Echo::r($key . ' => ' . $newValues[$copyKey], 'Copy key'); - } - - } elseif (isset($newValues[$key])) { - $filter[$key . ' = ?'] = $newValues[$key]; - if (MUtil_Model::$verbose) { - MUtil_Echo::r($key . ' => ' . $newValues[$key], 'Key'); - } + } elseif (isset($newValues[$key])) { + $filter[$key . ' = ?'] = $newValues[$key]; + if (MUtil_Model::$verbose) { + MUtil_Echo::r($key . ' => ' . $newValues[$key], 'Key'); } } } + } + if (! $filter) { + $update = false; + } - if ($update) { - // MUtil_Echo::r($filter, 'Filter'); + if ($update) { + // MUtil_Echo::r($filter, 'Filter'); - $adapter = $this->getAdapter(); - $wheres = array(); - foreach ($filter as $text => $value) { - $wheres[] = $adapter->quoteInto($text, $value); - } - // Retrieve the record from the database - $oldValues = $table->fetchRow('(' . implode(' ) AND (', $wheres) . ')'); + $adapter = $this->getAdapter(); + $wheres = array(); + foreach ($filter as $text => $value) { + $wheres[] = $adapter->quoteInto($text, $value); + } + // Retrieve the record from the database + $oldValues = $table->fetchRow('(' . implode(' ) AND (', $wheres) . ')'); + if (! $oldValues) { + // MUtil_Echo::r('INSERT!!', 'Old not found'); + // Apparently the record does not exist in the database + $update = false; + } else { + $oldValues = $oldValues->toArray(); + } + } - if (! $oldValues) { - // MUtil_Echo::r('INSERT!!', 'Old not found'); - // Apparently the record does not exist in the database - $update = false; - } else { - $oldValues = $oldValues->toArray(); - } + // Check for actual values for this table to save. + // MUtil_Echo::track($newValues); + if ($returnValues = $this->_filterDataFor($table_name, $newValues, ! $update)) { + if (true || MUtil_Model::$verbose) { + MUtil_Echo::r($returnValues, 'Return'); } + // MUtil_Echo::track($returnValues); - // Check for actual values for this table to save. - // MUtil_Echo::track($newValues); - if ($returnValues = $this->_filterDataFor($table_name, $newValues, ! $update)) { - if (MUtil_Model::$verbose) { - MUtil_Echo::r($returnValues, 'Return'); - } - // MUtil_Echo::track($returnValues); + if ($update) { + // MUtil_Echo::r($filter); - if ($update) { - // MUtil_Echo::r($filter); + // Check for actual changes + foreach ($oldValues as $name => $value) { - // Check for actual changes - foreach ($oldValues as $name => $value) { + // The name is in the set being stored + if (array_key_exists($name, $returnValues)) { - // The name is in the set being stored - if (array_key_exists($name, $returnValues)) { + // Detect change that is not auto update + if (! (($returnValues[$name] == $value) || $this->isAutoSave($name))) { + // MUtil_Echo::rs($name, $returnValues[$name], $value); + // MUtil_Echo::r($returnValues); - // Detect change that is not auto update - if (! (($returnValues[$name] == $value) || $this->isAutoSave($name))) { - // MUtil_Echo::rs($name, $returnValues[$name], $value); - // MUtil_Echo::r($returnValues); + // Update the row, if the saveMode allows it + if (($saveMode & self::SAVE_MODE_UPDATE) && + $changed = $table->update($returnValues, $filter)) { + $this->addChanged($changed); + // Make sure the copy keys (if any) have the new values as well + $returnValues = $this->_updateCopyKeys($primaryKeys, $returnValues); - // Update the row - if ($changed = $table->update($returnValues, $filter)) { - $this->addChanged($changed); - // Make sure the copy keys (if any) have the new values as well - $returnValues = $this->_updateCopyKeys($primaryKeys, $returnValues); + // Add the old values as we have them and they may be of use later on. + $returnValues = $returnValues + $oldValues; - // Add the old values as we have them and they may be of use later on. - $returnValues = $returnValues + $oldValues; - - return $returnValues; - } + return $returnValues; } } } - // Add the old values as we have them and they may be of use later on. - return $returnValues + $oldValues; + } + // Add the old values as we have them and they may be of use later on. + return $returnValues + $oldValues; + } elseif ($saveMode & self::SAVE_MODE_INSERT) { + // Perform insert + // MUtil_Echo::r($returnValues); + $newKeyValues = $table->insert($returnValues); + $this->addChanged(); + // MUtil_Echo::rs($newKeyValues, $primaryKeys); + + // Composite key returned. + if (is_array($newKeyValues)) { + foreach ($newKeyValues as $key => $value) { + $returnValues[$key] = $value; + } + return $this->_updateCopyKeys($primaryKeys, $returnValues); } else { - // Perform insert - // MUtil_Echo::r($returnValues); - $newKeyValues = $table->insert($returnValues); - $this->addChanged(); - // MUtil_Echo::rs($newKeyValues, $primaryKeys); - - // Composite key returned. - if (is_array($newKeyValues)) { - foreach ($newKeyValues as $key => $value) { - $returnValues[$key] = $value; + // Single key returned + foreach ($primaryKeys as $key) { + // Fill the first empty value + if (! isset($returnValues[$key])) { + $returnValues[$key] = $newKeyValues; + return $this->_updateCopyKeys($primaryKeys, $returnValues); } - return $this->_updateCopyKeys($primaryKeys, $returnValues); - } else { - // Single key returned - foreach ($primaryKeys as $key) { - // Fill the first empty value - if (! isset($returnValues[$key])) { - $returnValues[$key] = $newKeyValues; - return $this->_updateCopyKeys($primaryKeys, $returnValues); - } - } - // But if all the key values were already filled, make sure the new values are returned. - return $this->_updateCopyKeys($primaryKeys, $returnValues); } + // But if all the key values were already filled, make sure the new values are returned. + return $this->_updateCopyKeys($primaryKeys, $returnValues); } } } Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -245,7 +245,7 @@ // First strip the options that are not allowed if (MUtil_Model::$verbose) { - $strippedKeys = array_keys(array_diff_key($options, $allowedOptionsflipped)); + $strippedKeys = array_keys(array_diff_key($options, $allowedOptionsFlipped)); if (!empty($strippedKeys)) { MUtil_Echo::r($strippedKeys, 'stripped from options for ' . $name); } @@ -349,7 +349,7 @@ // Make sure form knows it is a jQuery form $this->form->activateJQuery(); - + return $this->_addToForm($name, 'DatePicker', $options); } @@ -379,14 +379,14 @@ $options = func_get_args(); $options = MUtil_Ra::pairs($options, 2); - //MUtil_Echo::track($elements); + // MUtil_Echo::track($elements); if (isset($elements['elements'])) { - MUtil_Echo::track($elements, $options); + // MUtil_Echo::track($elements, $options); $tmpElements = $elements['elements']; unset($elements['elements']); $options = $elements + $options; $elements = $tmpElements; - //MUtil_Echo::track($elements, $options); + // MUtil_Echo::track($elements, $options); } $options = $this->_mergeOptions($name, $options, Modified: trunk/library/classes/MUtil/Model/JoinModel.php =================================================================== --- trunk/library/classes/MUtil/Model/JoinModel.php 2012-11-13 12:48:38 UTC (rev 1016) +++ trunk/library/classes/MUtil/Model/JoinModel.php 2012-11-15 14:18:41 UTC (rev 1017) @@ -60,9 +60,9 @@ /** * Create a model that joins two or more tables * - * @param string $name the name of the model - * @param string $startTable The base table for the model - * @param bool $saveable Will changes to this table be saved + * @param string $name A name for the model + * @param string $startTable The base table for the model + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants */ public function __construct($name, $startTable, $saveable = false) { @@ -77,6 +77,40 @@ $this->_select->from($this->_getTableName($table), array()); } + /** + * Check the passed saveTable information and return 'new style' SAVE_MODE + * constant array + * + * @param array $saveTables Optional array containing the table names to save, + * otherwise the tables set to save at model level will be saved. + * @return array Containing savetable data + */ + protected function _checkSaveTables($saveTables) + { + if (null === $saveTables) { + return $this->_saveTables; + } + + $results = array(); + foreach ((array) $saveTables as $tableName => $setting) { + if (is_numeric($tableName) || (true === $setting)) { + $results[$setting] = self::SAVE_MODE_ALL; + } elseif ($setting) { + $results[$tableName] = $setting; + } + } + + return $results; + } + + /** + * Join a table to the select statement and load the table information + * + * @param string $join Join function name specifying the type of join + * @param mixed $table The name of the table to join or a table object + * @param array $joinFields Array of field pairs that form the join statement + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants + */ protected function _joinTable($join, $table, array $joinFields, $saveable = false) { $table = $this->_loadTable($table, $saveable); @@ -91,32 +125,58 @@ $this->_select->$join($table_name, implode(' ' . Zend_Db_Select::SQL_AND . ' ', $joinSql), array()); } + /** + * Load table meta data and set the models table properties + * + * @param mixed $table The name of the table to join or a table object + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants + * @return Zend_DB_Table + */ protected function _loadTable($table, $saveable = false) { if ($table instanceof Zend_Db_Table_Abstract) { - $table_name = $this->_getTableName($table); + $tableName = $this->_getTableName($table); } else { - $table_name = (string) $table; - $table = new Zend_DB_Table($table_name); + $tableName = (string) $table; + $table = new Zend_DB_Table($tableName); } - $this->_tables[$table_name] = $table; + $this->_tables[$tableName] = $table; - if ($saveable) { - $this->_saveTables[] = $table_name; - } - + $this->_setTableSaveable($tableName, $saveable); $this->_loadTableMetaData($table); return $table; } /** + * Add the table to the default save tables. + * + * This private functions saves against overloading + * + * Only tables marked as save tables are saved during a save() or delete(), + * unless this is overuled by the extra parameter for those functions in + * this object. + * + * @param string $tableName Does not test for existence + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants + */ + private function _setTableSaveable($tableName, $saveable) + { + if (true === $saveable) { + $this->_saveTables[$tableName] = self::SAVE_MODE_ALL; + } elseif ($saveable) { + $this->_saveTables[$tableName] = $saveable; + } else { + unset($this->_saveTables[$tableName]); + } + } + + /** * Add a table to the model with a left join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param bool $saveable Will changes to this table be saved - * + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * @return MUtil_Model_JoinModel */ public function addLeftTable($table, array $joinFields, $saveable = false) @@ -128,9 +188,9 @@ /** * Add a table to the model with a right join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param bool $saveable Will changes to this table be saved + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * * @return MUtil_Model_JoinModel */ @@ -143,9 +203,9 @@ /** * Add a table to the model with an inner join * - * @param string $table The name of the table to join - * @param array $joinFields Array of source->dest primary keys for this join - * @param bool $saveable Will changes to this table be saved + * @param string $table The name of the table to join + * @param array $joinFields Array of source->dest primary keys for this join + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * * @return Gems_Model_JoinModel */ @@ -169,10 +229,8 @@ */ public function delete($filter = true, array $saveTables = null) { - if (null === $saveTables) { - $saveTables = $this->_saveTables; - } - $filter = $this->_checkFilterUsed($filter); + $saveTables = $this->_checkSaveTables($saveTables); + $filter = $this->_checkFilterUsed($filter); if ($this->_deleteValues) { // First get the old values so we can have all the key values @@ -182,12 +240,12 @@ $changed = $this->save($this->_deleteValues + $oldValues, $filter, $saveTables); } else { $changed = 0; - foreach ($saveTables as $table_name) { + foreach ($saveTables as $tableName => $saveMode) { $table_filter = array(); - $delete = true; + $delete = $saveMode & self::SAVE_MODE_DELETE; // Find per table key filters - foreach ($this->_getKeysFor($table_name) as $key) { + foreach ($this->_getKeysFor($tableName) as $key) { if (isset($filter[$key])) { $table_filter[$key] = $filter[$key]; } else { @@ -213,7 +271,7 @@ // MUtil_Echo::r($table_filter, $table_name); if ($delete && $table_filter) { - $changed = max($changed, $this->_deleteTableData($this->_tables[$table_name], $table_filter)); + $changed = max($changed, $this->_deleteTableData($this->_tables[$tableName], $table_filter)); } } } @@ -253,16 +311,13 @@ */ public function save(array $newValues, array $filter = null, array $saveTables = null) { - if (null === $saveTables) { - $saveTables = $this->_saveTables; - } - + $saveTables = $this->_checkSaveTables($saveTables); $oldChanged = $this->getChanged(); // MUtil_Echo::track($newValues, $filter, $saveTables, $this->_joinFields); $oldValues = $newValues; - foreach ($saveTables as $table_name) { + foreach ($saveTables as $tableName => $saveMode) { // Gotta repeat this every time, as keys may be set later foreach ($this->_joinFields as $source => $target) { // Use is_string as $target and $target can be e.g. a Zend_Db_Expr() object @@ -280,7 +335,9 @@ } elseif (! (isset($newValues[$source]) && $newValues[$source])) { $newValues[$source] = $newValues[$target]; - } elseif ((strlen($newValues[$target]) > 0) && (strlen($newValues[$source]) > 0) && $newValues[$target] != $newValues[$source]) { + } elseif ((strlen($newValues[$target]) > 0) && + (strlen($newValues[$source]) > 0) && + $newValues[$target] != $newValues[$source]) { // Join key values changed. // // Set the old values as the filter @@ -293,13 +350,15 @@ // The changing field must be stated first in the join statement. $newValues[$target] = $newValues[$source]; } - } elseif ($target instanceof Zend_Db_Expr && (! (isset($newValues[$source]) && $newValues[$source]))) { + } elseif ($target instanceof Zend_Db_Expr && + (! (isset($newValues[$source]) && $newValues[$source]))) { $newValues[$source] = $target; } } //$this->_saveTableData returns the new row values, including any automatic changes. - $newValues = $this->_saveTableData($this->_tables[$table_name], $newValues, $filter) + $oldValues; + $newValues = $this->_saveTableData($this->_tables[$tableName], $newValues, $filter, $saveMode) + + $oldValues; // MUtil_Echo::track($oldValues, $newValues, $filter); $oldValues = $newValues; } @@ -345,22 +404,13 @@ * unless this is overuled by the extra parameter for those functions in * this object. * - * @param string $table_name Does not test for existence - * @param boolean $saveable Will changes to this table be saved + * @param string $tableName Does not test for existence + * @param mixed $saveable Will changes to this table be saved, true or a combination of SAVE_MODE constants * @return MUtil_Model_JoinModel (continuation pattern) */ - public function setTableSaveable($table_name, $saveable = true) + public function setTableSaveable($tableName, $saveable = true) { - // MUtil_Echo::r(func_get_args(), __CLASS__ . '->' . __FUNCTION__); - if ($saveable) { - if (! in_array($table_name, $this->_saveTables)) { - $this->_saveTables[] = $table_name; - } - } else { - $key = array_search($table_name, $this->_saveTables); - unset($this->_saveTables[$key]); - } - + $this->_setTableSaveable($tableName, $saveable); return $this; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-11-29 13:13:40
|
Revision: 1047 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1047&view=rev Author: matijsdejong Date: 2012-11-29 13:13:28 +0000 (Thu, 29 Nov 2012) Log Message: ----------- Renewed fix for #564 using formatFunction instead Modified Paths: -------------- trunk/library/classes/Gems/Default/RespondentAction.php trunk/library/classes/MUtil/Model/ModelAbstract.php Modified: trunk/library/classes/Gems/Default/RespondentAction.php =================================================================== --- trunk/library/classes/Gems/Default/RespondentAction.php 2012-11-29 11:06:23 UTC (rev 1046) +++ trunk/library/classes/Gems/Default/RespondentAction.php 2012-11-29 13:13:28 UTC (rev 1047) @@ -50,13 +50,6 @@ public $filterStandard = array('grc_success' => 1); - /** - * Variable for correctly displaying e-mail addresses - * - * @var MUtil_Lazy_LazyAbstract - */ - protected $grs_email; - public $showSnippets = array( 'RespondentDetailsSnippet', 'AddTracksSnippet', @@ -79,9 +72,8 @@ */ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { - $this->grs_email = $bridge->getLazy('grs_email'); $model->setIfExists('gr2o_opened', 'tableDisplay', 'small'); - $model->setIfExists('grs_email', 'itemDisplay', array($this, 'ifmail')); + $model->setIfExists('grs_email', 'formatFunction', 'MUtil_Html_AElement::ifmail'); if ($menuItem = $this->findAllowedMenuItem('show')) { $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); @@ -471,23 +463,6 @@ } /** - * Helper function for preventing the marker value being mixed up in the output - * - * @param MUtil_Lazy_LazyAbstract $value - * @return MUtil_Html_AElement - */ - public function ifmail($value) - { - return MUtil_Lazy::iff($this->grs_email, - new MUtil_Html_AElement( - array('mailto:', $this->grs_email), - $value, - array('onclick' => 'event.cancelBubble=true;') - ) - ); - } - - /** * Overrule default index for the case that the current * organization cannot have users. */ Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-11-29 11:06:23 UTC (rev 1046) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-11-29 13:13:28 UTC (rev 1047) @@ -977,7 +977,13 @@ */ public function remove($name, $key = null) { - if (isset($this->_model[$name][$key])) unset($this->_model[$name][$key]); + if (null === $key) { + if (isset($this->_model[$name])) { + unset($this->_model[$name]); + } + } elseif (isset($this->_model[$name][$key])) { + unset($this->_model[$name][$key]); + } return $this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-12-27 14:23:30
|
Revision: 1072 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1072&view=rev Author: matijsdejong Date: 2012-12-27 14:23:23 +0000 (Thu, 27 Dec 2012) Log Message: ----------- Updated to use latest 1.8.3 version of jQuery User can switch to local files for jQuery Modified Paths: -------------- trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2012-12-27 14:21:39 UTC (rev 1071) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2012-12-27 14:23:23 UTC (rev 1072) @@ -341,6 +341,22 @@ } /** + * Get the local jQuery directory (without base url) + * + * Instead of e.g. google Content Delivery Network. + * + * @return boolean + */ + public function getJQueryLocal() + { + if (isset($this['jquery']['local'])) { + return $this['jquery']['local']; + } else { + return null; + } + } + + /** * Get the logLevel to use with the Gems_Log * * Default settings is for development and testing environment to use Zend_Log::DEBUG and @@ -505,4 +521,16 @@ { return isset($this['password']['initialPassword']); } + + /** + * Does this project use a local jQuery + * + * Instead of e.g. google Content Delivery Network. + * + * @return boolean + */ + public function isJQueryLocal() + { + return isset($this['jquery']['local']); + } } \ No newline at end of file Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-12-27 14:21:39 UTC (rev 1071) +++ trunk/library/classes/GemsEscort.php 2012-12-27 14:23:23 UTC (rev 1072) @@ -723,14 +723,7 @@ if (MUtil_JQuery::usesJQuery($this->view)) { $jquery = $this->view->jQuery(); $jquery->uiEnable(); // enable user interface - $jquery->setUiVersion('1.8.9'); - if (MUtil_Https::on()) { - $jquery->setCdnSsl(true); - } - - // $jquery->setLocalPath('jquery-1.3.2.min.js'); - if (isset($this->project->jquerycss)) { foreach ((array) $this->project->jquerycss as $css) { $jquery->addStylesheet($this->basepath->getBasePath() . '/' . $css); @@ -1579,6 +1572,27 @@ // Set the base path, the route is now fixed $this->basepath->setBasePath($request->getBasePath()); + + // Set the jQuery version and other information needed + // by classes using jQuery + $jquery = MUtil_JQuery::jQuery(); + + $jqueryVersion = '1.8.3'; + $jqueryUiVersion = '1.9.2'; + $jquery->setVersion($jqueryVersion); + $jquery->setUiVersion($jqueryUiVersion); + + if ($this->project->isJQueryLocal()) { + $jqueryDir = $request->getBasePath() . $this->project->getJQueryLocal(); + + $jquery->setLocalPath($jqueryDir . 'jquery-' . $jqueryVersion . '.js'); + $jquery->setUiLocalPath($jqueryDir . 'jquery-ui-' . $jqueryUiVersion . '.js'); + + } else { + if (MUtil_Https::on()) { + $jquery->setCdnSsl(true); + } + } } Modified: trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php =================================================================== --- trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php 2012-12-27 14:21:39 UTC (rev 1071) +++ trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php 2012-12-27 14:23:23 UTC (rev 1072) @@ -189,19 +189,6 @@ public function setView(Zend_View_Interface $view = null) { - /* - http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/i18n/jquery-ui-i18n.min.js" - - $(function() { - $.datepicker.setDefaults($.datepicker.regional['']); - $("#datepicker").datepicker($.datepicker.regional['fr']); - $("#locale").change(function() { - $('#datepicker').datepicker('option', $.datepicker.regional[$(this).val()]); - }); - }); - - */ - $element = parent::setView($view); if (null !== $view) { @@ -210,20 +197,28 @@ } } - if ($locale = Zend_Registry::get('Zend_Locale')) { $language = $locale->getLanguage(); + // We have a language, but only when not english if ($language && $language != 'en') { - //TODO : work out correct link / setup: now defaults to last language - // $view->jquery()->addJavascriptFile(ZendX_JQuery::CDN_BASE_GOOGLE . ZendX_JQuery::CDN_SUBFOLDER_JQUERYUI . ZendX_JQuery::DEFAULT_UI_VERSION . '/i18n/jquery-ui-i18n.min.js'); + $jquery = $view->JQuery(); - // $ljs = "$('#" . $this->getId() . "').datepicker('option', $.datepicker.regional['" . $language . "']);"; - // $view->JQuery()->addOnLoad($ljs); + if ($uiPath = $jquery->getUiLocalPath()) { + $baseUrl = dirname($uiPath); - $http = MUtil_Https::on() ? ZendX_JQuery::CDN_BASE_GOOGLE_SSL : ZendX_JQuery::CDN_BASE_GOOGLE ; - $version = ZendX_JQuery::DEFAULT_UI_VERSION; - $version = '1.8.9'; //Overrule want vertaling nederlands wordt anders niet gevonden - $view->JQuery()->addJavascriptFile($http . ZendX_JQuery::CDN_SUBFOLDER_JQUERYUI . $version . '/i18n/jquery.ui.datepicker-' . $language . '.js'); + } else { + $baseUrl = MUtil_Https::on() ? ZendX_JQuery::CDN_BASE_GOOGLE_SSL : ZendX_JQuery::CDN_BASE_GOOGLE; + $baseUrl .= ZendX_JQuery::CDN_SUBFOLDER_JQUERYUI; + $baseUrl .= $jquery->getUiVersion(); + } + // Option 1: download single language file + $jquery->addJavascriptFile($baseUrl . '/i18n/jquery.ui.datepicker-' . $language . '.js'); + + // Option 2: download all languages and select current + // $jquery->addJavascriptFile($baseUrl . '/i18n/jquery-ui-i18n.min.js'); + // $jquery->addOnLoad("$.datepicker.setDefaults($.datepicker.regional['$language'])"); + + // TODO: Option 3: enable language setting for each individual date } } Modified: trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php =================================================================== --- trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php 2012-12-27 14:21:39 UTC (rev 1071) +++ trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php 2012-12-27 14:23:23 UTC (rev 1072) @@ -53,7 +53,7 @@ $this->jquery->addOnLoad($js); } - if (isset($params['dateFormat']) && ($format = $params['dateFormat'])) { + if (isset($params['dateFormat']) && $params['dateFormat']) { //* $js = array(); $js[] = '{'; @@ -61,10 +61,7 @@ $js[] = ''; $js[] = " datePick.blur(function() {"; $js[] = " var dateused;"; - $js[] = " var dateformat = '" . $format . "';"; - // TODO: Why won't this work - // $js[] = " var dateformat = datePick.datepicker('option', 'dateFormat');"; - // $js[] = " alert(dateformat);"; + $js[] = " var dateformat = datePick.datepicker('option', 'dateFormat');"; $js[] = " dateused = datePick.attr('value');"; $js[] = " dateused = $.datepicker.parseDate(dateformat, dateused);"; $js[] = " datePick.attr('value', $.datepicker.formatDate(dateformat, dateused));"; @@ -72,7 +69,6 @@ $js[] = '}'; $this->jquery->addOnLoad(implode("\n", $js)); - //$this->view->inlineScript()->appendScript(implode("\n", $js)); // */ } return $result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2013-01-03 17:24:07
|
Revision: 1087 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1087&view=rev Author: matijsdejong Date: 2013-01-03 17:23:59 +0000 (Thu, 03 Jan 2013) Log Message: ----------- Added info to ProjectInformationAction.php Made a non-functional start on CachedLoader.php Modified Paths: -------------- trunk/library/classes/Gems/Default/ProjectInformationAction.php trunk/library/classes/Gems/Loader/LoaderAbstract.php Added Paths: ----------- trunk/library/classes/MUtil/Loader/ trunk/library/classes/MUtil/Loader/CachedLoader.php Modified: trunk/library/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- trunk/library/classes/Gems/Default/ProjectInformationAction.php 2013-01-03 08:22:06 UTC (rev 1086) +++ trunk/library/classes/Gems/Default/ProjectInformationAction.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -136,7 +136,8 @@ $data[$this->_('Gems version')] = $versions->getGemsVersion(); $data[$this->_('Gems build')] = $versions->getBuild(); $data[$this->_('Gems project')] = GEMS_PROJECT_NAME; - $data[$this->_('Gems web directory')] = GEMS_ROOT_DIR; + $data[$this->_('Gems web directory')] = GEMS_WEB_DIR; + $data[$this->_('Gems root directory')] = GEMS_ROOT_DIR; $data[$this->_('Gems code directory')] = GEMS_LIBRARY_DIR; $data[$this->_('MUtil version')] = MUtil_Version::get(); $data[$this->_('Zend version')] = Zend_Version::VERSION; Modified: trunk/library/classes/Gems/Loader/LoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-03 08:22:06 UTC (rev 1086) +++ trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -162,6 +162,8 @@ $cname = trim(str_replace('/', '_', ucfirst($name)), '_'); $cfile = str_replace('_', '/', $cname) . '.php'; + // MUtil_Loader_CachedLoader::getInstance(GEMS_ROOT_DIR . '\var\cache'); + $found = false; /** @@ -189,7 +191,7 @@ $found = true; $this->_loaded[$cname] = get_class($obj); break 2; - } + } } } } Added: trunk/library/classes/MUtil/Loader/CachedLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/CachedLoader.php (rev 0) +++ trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -0,0 +1,165 @@ +<?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 <COPYRIGHT HOLDER> 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 MUtil + * @subpackage Loader + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: CachedLoader.php$ + */ + +/** + * + * + * @package MUtil + * @subpackage Loader + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since MUtil version 1.2 + */ +class MUtil_Loader_CachedLoader +{ + /** + * + * @var array + */ + protected $_cacheArray = array(); + + /** + * + * @var string + */ + protected $_cacheDir = null; + + /** + * + * @var string + */ + protected $_cacheFile = 'cached.loader.mutil.php'; + + /** + * + * @param string $dir + */ + protected function __construct($dir = null) + { + if (null === $dir) { + $dir = getenv('TMP'); + } + + $this->_cacheDir = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR; + $this->_cacheFile = $this->_cacheDir . $this->_cacheFile; + + if (! file_exists($this->_cacheDir)) { + throw new Zend_Exception(sprintf('Cache directory %s does not exist.', $this->_cacheDir)); + } + + if (! is_writable($this->_cacheDir)) { + throw new Zend_Exception(sprintf('Cache directory %s is not writeable.', $this->_cacheFile)); + } + + if (! file_exists($this->_cacheFile)) { + $this->_saveCache(); + } else { + if (! is_writable($this->_cacheFile)) { + throw new Zend_Exception(sprintf('Cache file %s not writeable.', $this->_cacheFile)); + } + + $this->_loadCache(); + } + // MUtil_Echo::track($this->_cacheFile, $this->_cacheDir, file_exists($this->_cacheDir)); + } + + /** + * Append a new found file to the cache + * + * @param string $class The name of the class to load + * @param mixed $file String path to file or false if does not exist + */ + protected function _appendToCache($class, $file) + { + $this->_cacheArray[$class] = $file; + + if (! file_exists($this->_cacheFile)) { + $this->_saveCache(); + } else { + if (false === $file) { + $content = "\$this->_cacheArray['$class'] = false;\n"; + } else { + $content = "\$this->_cacheArray['$class'] = '$file';\n"; + } + file_put_contents($this->_cacheFile, $content, FILE_APPEND | LOCK_EX ); + } + } + + protected function _loadCache() + { + include $this->_cacheFile; + } + + protected function _saveCache() + { + $content = "<?php\n"; + + foreach ($this->_cacheArray as $class => $file) { + if (false === $file) { + $content .= "\$this->_cacheArray['$class'] = false;\n"; + } else { + $content .= "\$this->_cacheArray['$class'] = '$file';\n"; + } + } + file_put_contents($this->_cacheFile, $content, LOCK_EX); + } + + /** + * + * @static MUtil_Loader_CachedLoader $instance + * @param stirng $dir + * @return MUtil_Loader_CachedLoader + */ + public static function getInstance($dir = null) + { + static $instance; + + if (! $instance) { + $instance = new self($dir); + } + + return $instance;; + } + + protected function isClass($className, $paths) + { + // Zend_Loader::standardiseFile($file) + //if (file_exists($path . $className)) { + +// /} + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2013-01-21 13:54:02
|
Revision: 1114 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1114&view=rev Author: matijsdejong Date: 2013-01-21 13:53:54 +0000 (Mon, 21 Jan 2013) Log Message: ----------- Extended ComplianceAction.php with link for each (existing) token CrossTabTransformer.php can now crosstab over multiple values Added Legenda to Compliance overview Moved status code to new Util/TokenData.php Modified Paths: -------------- trunk/library/classes/Gems/Default/ComplianceAction.php trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php trunk/library/classes/Gems/Util.php trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php Added Paths: ----------- trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php trunk/library/classes/Gems/Util/TokenData.php Modified: trunk/library/classes/Gems/Default/ComplianceAction.php =================================================================== --- trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-18 17:28:15 UTC (rev 1113) +++ trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -61,6 +61,13 @@ protected $indexStartSnippets = array('Generic_ContentTitleSnippet', 'Tracker_Compliance_ComplianceSearchFormSnippet'); /** + * The snippets used for the index action, after those in autofilter + * + * @var mixed String or array of snippets name + */ + protected $indexStopSnippets = array('Tracker_TokenStatusLegenda', 'Generic_CurrentButtonRowSnippet'); + + /** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed @@ -117,6 +124,7 @@ $status = new Zend_Db_Expr(" CASE + WHEN grc_success = 0 THEN 'D' WHEN gto_completion_time IS NOT NULL THEN 'A' WHEN gto_valid_from IS NULL THEN 'U' WHEN gto_valid_from > CURRENT_TIMESTAMP THEN 'W' @@ -126,10 +134,13 @@ "); $select = $this->db->select(); - $select->from('gems__tokens', array('gto_id_respondent_track', 'gto_id_round', 'status' => $status)) + $select->from('gems__tokens', array( + 'gto_id_respondent_track', 'gto_id_round', 'gto_id_token', 'status' => $status, + )) ->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array()) - ->where('grc_success = 1') + // ->where('grc_success = 1') ->where('gto_id_track = ?', $filter['gr2t_id_track']) + ->order('grc_success') ->order('gto_id_respondent_track') ->order('gto_round_order'); @@ -138,15 +149,17 @@ $newModel->setKeys(array('gto_id_respondent_track')); $transformer = new MUtil_Model_Transform_CrossTabTransformer(); - $transformer->setCrosstabFields('gto_id_round', 'status'); + $transformer->addCrosstabField('gto_id_round', 'status', 'stat_') + ->addCrosstabField('gto_id_round', 'gto_id_token', 'tok_'); foreach ($data as $row) { - $name = 'col_' . $row['gro_id_round']; + $name = 'stat_' . $row['gro_id_round']; $transformer->set($name, 'label', MUtil_Lazy::call('substr', $row['gsu_survey_name'], 0, 2), 'description', sprintf("%s\n[%s]", $row['gsu_survey_name'], $row['gro_round_description']), 'noSort', true, 'round', $row['gro_round_description'] ); + $transformer->set('tok_' . $row['gro_id_round']); } $newModel->addTransformer($transformer); Modified: trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-18 17:28:15 UTC (rev 1113) +++ trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -47,6 +47,12 @@ class Gems_Snippets_Tracker_Compliance_ComplianceTableSnippet extends Gems_Snippets_ModelTableSnippetGeneric { /** + * + * @var Gems_Util + */ + protected $util; + + /** * 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 @@ -58,6 +64,7 @@ */ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { + $tUtil = $this->util->getTokenData(); $table = $bridge->getTable(); $table->appendAttrib('class', 'compliance'); @@ -89,14 +96,30 @@ } if ($model->get($name, 'noSort')) { - $tds = $bridge->addColumn( + // http://localhost/pulse/track/show/id/afw8-o725 + $title = array( + MUtil_Lazy::method($tUtil, 'getStatusDescription', $bridge->$name), + "\n" . $model->get($name, 'description') + ); + $token = 'tok_' . substr($name, 5); + + $tds = $bridge->addColumn( array( - $bridge->$name, - 'class' => array('round', MUtil_Lazy::method($this, 'getClassFor', $bridge->$name)), - 'title' => array( - MUtil_Lazy::method($this, 'getDescriptionFor', $bridge->$name), - "\n" . $model->get($name, 'description') - ), + MUtil_Html_AElement::iflink( + $bridge->$token, + array( + 'href' => array( + 'controller' => 'track', + 'action' => 'show', + MUtil_Model::REQUEST_ID => $bridge->$token, + ), + 'onclick' => 'event.cancelBubble = true;', + 'title' => $title, + $bridge->$name, + ), + $bridge->$name), + 'class' => array('round', MUtil_Lazy::method($tUtil, 'getStatusClass', $bridge->$name)), + 'title' => $title, ), array($label, 'title' => $model->get($name, 'description'), 'class' => 'round') ); @@ -113,54 +136,6 @@ } /** - * Returns the class to display the answer - * - * @param string $value Character - * @return string - */ - public function getClassFor($value) - { - switch ($value) { - case 'A': - return 'answered'; - case 'M': - return 'missed'; - case 'O': - return 'open'; - case 'U': - return 'unknown'; - case 'W': - return 'waiting'; - default: - return 'empty'; - } - } - - /** - * Returns the decription to add to the answer - * - * @param string $value Character - * @return string - */ - public function getDescriptionFor($value) - { - switch ($value) { - case 'A': - return $this->_('Answered'); - case 'M': - return $this->_('Missed deadline'); - case 'O': - return $this->_('Open - can be answered now'); - case 'U': - return $this->_('Valid from date unknown'); - case 'W': - return $this->_('Valid from date in the future'); - default: - return $this->_('Token does not exist'); - } - } - - /** * Returns a show menu item, if access is allowed by privileges * * @return Gems_Menu_SubMenuItem Added: trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -0,0 +1,81 @@ +<?php + +/** + * Copyright (c) 2012, 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) 2012 Erasmus MC + * @license New BSD License + * @version $id: TokenStatusLegenda.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Snippets_Tracker_TokenStatusLegenda extends MUtil_Snippets_SnippetAbstract +{ + /** + * + * @var Gems_Util + */ + protected $util; + + /** + * 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) + { + $tUtil = $this->util->getTokenData(); + + $repeater = new MUtil_Lazy_RepeatableByKeyValue($tUtil->getEveryStatus()); + $table = new MUtil_Html_TableElement(); + $table->class = 'compliance timeTable rightFloat'; + $table->setRepeater($repeater); + + $table->throw($this->_('Legend')); + $table->td($repeater->key)->class = array( + 'round', + MUtil_Lazy::method($tUtil, 'getStatusClass', $repeater->key) + ); + $table->td($repeater->value); + + return $table; + } +} Added: trunk/library/classes/Gems/Util/TokenData.php =================================================================== --- trunk/library/classes/Gems/Util/TokenData.php (rev 0) +++ trunk/library/classes/Gems/Util/TokenData.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -0,0 +1,115 @@ +<?php + +/** + * Copyright (c) 2012, 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 Util + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: TokenData.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Class that bundles information on tokens + * + * @package Gems + * @subpackage Util + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.6 + */ +class Gems_Util_TokenData extends MUtil_Translate_TranslateableAbstract +{ + /** + * Returns a status code => decription array + * + * @static $status array + * @return array + */ + public function getEveryStatus() + { + static $status; + + if ($status) { + return $status; + } + + $status = array( + 'U' => $this->_('Valid from date unknown'), + 'W' => $this->_('Valid from date in the future'), + 'O' => $this->_('Open - can be answered now'), + 'A' => $this->_('Answered'), + 'M' => $this->_('Missed deadline'), + 'D' => $this->_('Token does not exist'), + ); + + return $status; + } + + /** + * Returns the class to display the answer + * + * @param string $value Character + * @return string + */ + public function getStatusClass($value) + { + switch ($value) { + case 'A': + return 'answered'; + case 'M': + return 'missed'; + case 'O': + return 'open'; + case 'U': + return 'unknown'; + case 'W': + return 'waiting'; + default: + return 'empty'; + } + } + + /** + * Returns the decription to add to the answer + * + * @param string $value Character + * @return string + */ + public function getStatusDescription($value) + { + $status = $this->getEveryStatus(); + + if (isset($status[$value])) { + return $status[$value]; + } + + return $status['D']; + } +} Modified: trunk/library/classes/Gems/Util.php =================================================================== --- trunk/library/classes/Gems/Util.php 2013-01-18 17:28:15 UTC (rev 1113) +++ trunk/library/classes/Gems/Util.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -91,6 +91,12 @@ /** * + * @var Gems_Util_TokenData + */ + protected $tokenData; + + /** + * * @var Gems_Util_TrackData */ protected $trackData; @@ -275,6 +281,15 @@ /** * + * @return Gems_Util_TokenData + */ + public function getTokenData() + { + return $this->_getClass('tokenData'); + } + + /** + * * @return Gems_Util_TrackData */ public function getTrackData() Modified: trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php 2013-01-18 17:28:15 UTC (rev 1113) +++ trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -126,24 +126,28 @@ $args = func_get_args(); $args = MUtil_Ra::pairs($args, 1); - foreach ($args as $key => $value) { - // If $key end with ] it is array value - if (substr($key, -1) == ']') { - if (substr($key, -2) == '[]') { - // If $key ends with [], append it to array - $key = substr($key, 0, -2); - $this->_fields[$name][$key][] = $value; + if ($args) { + foreach ($args as $key => $value) { + // If $key end with ] it is array value + if (substr($key, -1) == ']') { + if (substr($key, -2) == '[]') { + // If $key ends with [], append it to array + $key = substr($key, 0, -2); + $this->_fields[$name][$key][] = $value; + } else { + // Otherwise extract subkey + $pos = strpos($key, '['); + $subkey = substr($key, $pos + 1, -1); + $key = substr($key, 0, $pos); + + $this->_fields[$name][$key][$subkey] = $value; + } } else { - // Otherwise extract subkey - $pos = strpos($key, '['); - $subkey = substr($key, $pos + 1, -1); - $key = substr($key, 0, $pos); - - $this->_fields[$name][$key][$subkey] = $value; + $this->_fields[$name][$key] = $value; } - } else { - $this->_fields[$name][$key] = $value; } + } elseif (!array_key_exists($name, $this->_fields)) { + $this->_fields[$name] = array(); } return $this; Modified: trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php =================================================================== --- trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php 2013-01-18 17:28:15 UTC (rev 1113) +++ trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php 2013-01-21 13:53:54 UTC (rev 1114) @@ -47,29 +47,47 @@ class MUtil_Model_Transform_CrossTabTransformer extends MUtil_Model_ModelTransformerAbstract { /** - * The field to crosstab over + * The fields to crosstab over * - * @var string + * @var array Nested array: index => array('id' => idField, 'val' => valueField, 'pre' => prefix) */ - protected $idField; + protected $crossTabs; /** + * The fields to exclude from the crosstab result * - * @var string + * Calculated by setCrosstabFields + * + * @var array idField => idField */ - protected $valueField; + protected $excludes; /** + * Set the idField / crossTab output fields for the transformer. * - * @param string $idField The field values to perform the crosstab over + * You can define multiple crossTabs over the same id value. + * + * @param string $idField The field values to perform the crosstab over * @param string $valueField The field values to crosstab + * @param string $prefix Optional prefix to add before the $idField value as the identifier + * for the output field, otherwise * @return MUtil_Model_Transform_CrossTabTransformer (continuation pattern) */ - public function setCrosstabFields($idField, $valueField) + public function addCrosstabField($idField, $valueField, $prefix = null) { - $this->idField = $idField; - $this->valueField = $valueField; + if (null === $prefix) { + $prefix = $valueField . '_'; + } + $this->crossTabs[] = array( + 'id' => $idField, + 'val' => $valueField, + 'pre' => $prefix, + ); + + $this->excludes[$idField] = $idField; + $this->excludes[$valueField] = $valueField; + return $this; } @@ -90,33 +108,33 @@ //* $row = reset($data); - if (! ($this->idField && - $this->valueField && - isset($row[$this->idField]) && - array_key_exists($this->valueField, $row) - )) { + if (! ($this->crossTabs)) { return $data; } $keys = $model->getKeys(); $keys = array_combine($keys, $keys); - $default = array_fill_keys(array_keys($this->_fields), null); - $except = array($this->idField => 1, $this->valueField => 1); + $default = array_fill_keys(array_keys(array_diff_key($this->_fields, $this->excludes)), null); $results = array(); + // MUtil_Echo::track($default); + foreach ($data as $row) { - $name = 'col_' . $row[$this->idField]; + foreach ($this->crossTabs as $crossTab) { + $name = $crossTab['pre'] . $row[$crossTab['id']]; - if (isset($this->_fields[$name])) { $key = implode("\t", array_intersect_key($row, $keys)); if (! isset($results[$key])) { - $results[$key] = array_diff_key($row, $except) + $default; + $results[$key] = array_diff_key($row, $this->excludes) + $default; } - $results[$key][$name] = $row[$this->valueField]; + + $results[$key][$name] = $row[$crossTab['val']]; } } - // MUtil_Echo::track($results, $data); + if (MUtil_Model::$verbose) { + MUtil_Echo::r($results, 'Transform output'); + } return $results; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2013-03-25 11:53:16
|
Revision: 1205 http://sourceforge.net/p/gemstracker/code/1205 Author: mennodekker Date: 2013-03-25 11:53:12 +0000 (Mon, 25 Mar 2013) Log Message: ----------- OpenRosa: Moved scan forms from controller to Source Modified Paths: -------------- trunk/library/classes/Gems/Default/DatabaseAction.php trunk/library/classes/Gems/Default/OpenrosaAction.php trunk/library/classes/Gems/Menu.php trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa.php Modified: trunk/library/classes/Gems/Default/DatabaseAction.php =================================================================== --- trunk/library/classes/Gems/Default/DatabaseAction.php 2013-03-22 14:27:33 UTC (rev 1204) +++ trunk/library/classes/Gems/Default/DatabaseAction.php 2013-03-25 11:53:12 UTC (rev 1205) @@ -401,7 +401,7 @@ if ($translations) { $filedir = APPLICATION_PATH . '/languages'; if (! file_exists($filedir)) { - mkdir($filedir, 0777, true); + @mkdir($filedir, 0777, true); } $filename = $filedir . '/' . GEMS_PROJECT_NAME . 'DatabaseTranslations.php'; Modified: trunk/library/classes/Gems/Default/OpenrosaAction.php =================================================================== --- trunk/library/classes/Gems/Default/OpenrosaAction.php 2013-03-22 14:27:33 UTC (rev 1204) +++ trunk/library/classes/Gems/Default/OpenrosaAction.php 2013-03-25 11:53:12 UTC (rev 1205) @@ -269,43 +269,6 @@ } } } - - public function scanAction() - { - $model = $this->getModel(); - - //Perform a scan of the form directory, to update the database of forms - $eDir = dir($this->formDir); - - $formCnt = 0; - $addCnt = 0; - while (false !== ($filename = $eDir->read())) { - if (substr($filename, -4) == '.xml') { - $formCnt++; - $form = new OpenRosa_Tracker_Source_OpenRosa_Form($this->formDir . $filename); - $filter['gof_form_id'] = $form->getFormID(); - $filter['gof_form_version'] = $form->getFormVersion(); - $forms = $model->load($filter); - - if (!$forms) { - $newValues = array(); - $newValues['gof_id'] = null; - $newValues['gof_form_id'] = $form->getFormID(); - $newValues['gof_form_version'] = $form->getFormVersion(); - $newValues['gof_form_title'] = $form->getTitle(); - $newValues['gof_form_xml'] = $filename; - $newValues = $model->save($newValues); - MUtil_Echo::r($newValues, 'added form'); - $addCnt++; - } - } - } - - $cache = GemsEscort::getInstance()->cache; - $cache->clean(); - - $this->html[] = sprintf('Checked %s forms and added %s forms', $formCnt, $addCnt); - } public function scanresponsesAction() { Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2013-03-22 14:27:33 UTC (rev 1204) +++ trunk/library/classes/Gems/Menu.php 2013-03-25 11:53:12 UTC (rev 1205) @@ -292,7 +292,6 @@ $parent = $this; } $page = $parent->addBrowsePage($label, 'pr.openrosa','openrosa'); - $page->addButtonOnly($this->_('Scan FormDefs'), 'pr.openrosa.scan', 'openrosa', 'scan'); $page->addButtonOnly($this->_('Scan Responses'), 'pr.openrosa.scan', 'openrosa', 'scanresponses'); $this->addPage(null, null, 'openrosa', 'submission'); $this->addPage(null, null, 'openrosa', 'formList'); //mind the capital L here Modified: trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa.php =================================================================== --- trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa.php 2013-03-22 14:27:33 UTC (rev 1204) +++ trunk/library/classes/OpenRosa/Tracker/Source/OpenRosa.php 2013-03-25 11:53:12 UTC (rev 1205) @@ -51,19 +51,64 @@ { /** * This holds the path to the location where the form definitions will be stored. - * Will be set on init to: GEMS_ROOT_DIR . '/var/uploads/openrosa/forms/'; * * @var string */ - public $formDir; + protected $formDir; + + /** + * This holds the path to the location where OpenRosa will store it's files. + * Will be set on init to: GEMS_ROOT_DIR . '/var/uploads/openrosa/'; + * + * @var string + */ + protected $baseDir; + + /** + * + * @var Gems_Loader + */ + protected $loader; + + /** + * + * @var Zend_Translate + */ + protected $translate; + public function __construct(array $sourceData, Zend_Db_Adapter_Abstract $gemsDb) { parent::__construct($sourceData, $gemsDb); - $this->formDir = GEMS_ROOT_DIR . '/var/uploads/openrosa/forms/'; + $this->baseDir = GEMS_ROOT_DIR . '/var/uploads/openrosa/'; + $this->formDir = $this->baseDir . 'forms/'; } - + /** + * Open the dir, suppressing possible errors and try to + * create when it does not exist + * + * @param type $directory + * @return Directory + */ + protected function _checkDir($directory) + { + $eDir = @dir($directory); + if (false == $eDir) { + // Dir does probably not exist + if (!is_dir($directory)) { + if (false === @mkdir($directory, 0777, true)) { + MUtil_Echo::pre(sprintf($this->translate->_('Directory %s not found and unable to create'), $directory), 'OpenRosa ERROR'); + } else { + $eDir = @dir($directory); + } + } + } + + return $eDir; + } + + /** * Returns the source surveyId for a given Gems survey Id * * @param type $surveyId @@ -73,7 +118,47 @@ { return $this->tracker->getSurvey($surveyId)->getSourceSurveyId(); } + + protected function _scanForms() + { + $messages = array(); + $formCnt = 0; + $addCnt = 0; + $eDir = $this->_checkDir($this->formDir); + + if ($eDir !== false) { + $model = $this->loader->getModels()->getOpenRosaFormModel(); + while (false !== ($filename = $eDir->read())) { + if (substr($filename, -4) == '.xml') { + $formCnt++; + $form = new OpenRosa_Tracker_Source_OpenRosa_Form($this->formDir . $filename); + $filter['gof_form_id'] = $form->getFormID(); + $filter['gof_form_version'] = $form->getFormVersion(); + $forms = $model->load($filter); + if (!$forms) { + $newValues = array(); + $newValues['gof_id'] = null; + $newValues['gof_form_id'] = $form->getFormID(); + $newValues['gof_form_version'] = $form->getFormVersion(); + $newValues['gof_form_title'] = $form->getTitle(); + $newValues['gof_form_xml'] = $filename; + $newValues = $model->save($newValues); + if (Gems_Tracker::$verbose) { + MUtil_Echo::r($newValues, 'added form'); + } + $addCnt++; + } + } + } + } + + $cache = GemsEscort::getInstance()->cache; + $cache->clean(); + + $messages[] = sprintf('Checked %s forms and added %s forms', $formCnt, $addCnt); + } + //put your code here public function checkSourceActive($userId) { @@ -247,6 +332,8 @@ public function synchronizeSurveys($userId) { + $messages = $this->_scanForms(); + // Surveys in LS $db = $this->getSourceDatabase(); @@ -258,8 +345,9 @@ if (!$openRosaSurveys) { //If no surveys present, just use an empty array as array_combine fails $openRosaSurveys = array(); + $openRosaSurveyIds = array(); } else { - $openRosaSurveyIds = array_combine(array_keys($openRosaSurveys), array_keys($openRosaSurveys)); + $openRosaSurveyIds = array_combine(array_keys($openRosaSurveys), array_keys($openRosaSurveys)); } // Surveys in Gems @@ -293,6 +381,8 @@ $survey->exists = false; $survey->saveSurvey($values, $userId); } + + return $messages; } public function updateConsent(Gems_Tracker_Token $token, $surveyId, $sourceSurveyId = null, $consentCode = null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |