From: <gem...@li...> - 2011-09-27 12:43:43
|
Revision: 79 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=79&view=rev Author: matijsdejong Date: 2011-09-27 12:43:37 +0000 (Tue, 27 Sep 2011) Log Message: ----------- - fix for #11 forgot to add variables for error logging - made logger a resource just like the other resources Modified Paths: -------------- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2011-09-27 11:18:56 UTC (rev 78) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2011-09-27 12:43:37 UTC (rev 79) @@ -83,6 +83,18 @@ /** * + * @var Gems_Log + */ + protected $logger; + + /** + * + * @var Zend_Controller_Request_Abstract + */ + protected $request; + + /** + * * @var Zend_Translate */ protected $translate; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-09-27 11:18:56 UTC (rev 78) +++ trunk/library/classes/GemsEscort.php 2011-09-27 12:43:37 UTC (rev 79) @@ -62,17 +62,10 @@ /** * The menu variable * - * @var GemsMenu + * @var Gems_Menu */ public $menu; - /** - * The logger - * - * @var Zend_Log - */ - public $logger; - public function _($text, $locale = null) { if (! isset($this->request)) { @@ -147,9 +140,9 @@ /** * Initialize the logger */ - protected function _initLog() + protected function _initLogger() { - $this->logger = Gems_Log::getLogger(); + $logger = Gems_Log::getLogger(); $log_path = GEMS_ROOT_DIR . '/var/logs'; @@ -160,14 +153,16 @@ die(sprintf($this->translate->_('Path %s not writable'), $log_path)); } - $this->logger->addWriter($writer); + $logger->addWriter($writer); // OPTIONAL STARTY OF FIREBUG LOGGING. if ($this->_startFirebird) { - $this->logger->addWriter(new Zend_Log_Writer_Firebug()); + $logger->addWriter(new Zend_Log_Writer_Firebug()); } - Zend_Registry::set('logger', $this->logger); + Zend_Registry::set('logger', $logger); + + return $logger; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-09-27 14:44:03
|
Revision: 81 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=81&view=rev Author: matijsdejong Date: 2011-09-27 14:43:57 +0000 (Tue, 27 Sep 2011) Log Message: ----------- - added documentation to ModelAbstract and JoinModel - fix in JoinModel for warning when join is not on strings - cleanup of menu use / pdf upload in SurveyMaintenanceAction.php Modified Paths: -------------- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/MUtil/Model/JoinModel.php trunk/library/classes/MUtil/Model/ModelAbstract.php Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2011-09-27 13:00:35 UTC (rev 80) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2011-09-27 14:43:57 UTC (rev 81) @@ -44,7 +44,7 @@ * @license New BSD License * @since Class available since version 1.0 */ -class Gems_Default_SurveyMaintenanceAction extends Gems_Controller_BrowseEditAction implements Gems_Menu_ParameterSourceInterface +class Gems_Default_SurveyMaintenanceAction extends Gems_Controller_BrowseEditAction { public $autoFilter = true; @@ -55,12 +55,6 @@ public $sortKey = array('gsu_survey_name' => SORT_ASC); /** - * - * @var array - */ - protected $data = array(); - - /** * Adds columns from the model to the bridge that creates the browse table. * * Adds a button column to the model, if such a button exists in the model. @@ -93,8 +87,7 @@ */ protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false) { - //MUtil_Echo::r($data, __CLASS__ . '->' . __FUNCTION__); - $data = array_merge($model->loadFirst(), $data); + // MUtil_Echo::track($data); // Prepare variables $currentId = $data['gsu_id_survey']; @@ -381,15 +374,6 @@ return MUtil_Html::raw(strip_tags($value)); } - public function getMenuParameter($name, $default) - { - if (isset($this->data[$name])) { - return $this->data[$name]; - } else { - return $default; - } - } - public function getTrackCount($currentId) { $singleTrack = ($this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) ? $this->escort->getTrackId() : null; @@ -440,8 +424,6 @@ $source = $this->menu->getParameterSource(); $source->offsetSet('gsu_has_pdf', $data['gsu_survey_pdf'] ? 1 : 0); $source->offsetSet(MUtil_Model::REQUEST_ID, $data['gsu_id_survey']); - $this->data['gsu_has_pdf'] = $data['gsu_survey_pdf'] ? 1 : 0; - $this->data[MUtil_Model::REQUEST_ID] = $data['gsu_id_survey']; return $this; } @@ -470,7 +452,7 @@ $this->html[] = $table; if ($this->escort->hasPrivilege('pr.project.questions')) { - $this->addSnippet('SurveyQuestionsSnippet', 'surveyId', $this->data[MUtil_Model::REQUEST_ID]); + $this->addSnippet('SurveyQuestionsSnippet', 'surveyId', $this->_getIdParam()); } } } \ No newline at end of file Modified: trunk/library/classes/MUtil/Model/JoinModel.php =================================================================== --- trunk/library/classes/MUtil/Model/JoinModel.php 2011-09-27 13:00:35 UTC (rev 80) +++ trunk/library/classes/MUtil/Model/JoinModel.php 2011-09-27 14:43:57 UTC (rev 81) @@ -27,11 +27,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * - * @author Matijs de Jong <mj...@ma...> - * @since 1.0 - * @version 1.1 - * @package MUtil + * @package MUtil * @subpackage Model + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** @@ -42,9 +43,11 @@ * but you can override this when calling save() and delete(). * * - * @author Matijs de Jong <mj...@ma...> - * @package MUtil + * @package MUtil * @subpackage Model + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Model_JoinModel extends MUtil_Model_DatabaseModelAbstract { @@ -230,6 +233,14 @@ return $select; } + /** + * Save a single model item. + * + * @param array $newValues The values to store for a single model item. + * @param array $filter If the filter contains old key values these are used + * to decide on update versus insert. + * @return array The values as they are after saving (they may change). + */ public function save(array $newValues, array $filter = null, array $saveTables = null) { if (null === $saveTables) { @@ -245,13 +256,14 @@ foreach ($saveTables as $table_name) { // Gotta repeat this every time, as keys may be set later foreach ($this->_joinFields as $source => $target) { - if (! (isset($newValues[$target]) && $newValues[$target])) { - if (! (isset($newValues[$source]) && $newValues[$source])) { + // 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])) { continue; } $newValues[$target] = $newValues[$source]; - } elseif (! (isset($newValues[$source]) && $newValues[$source])) { + } elseif (! (is_string($source) && isset($newValues[$source]) && $newValues[$source])) { $newValues[$source] = $newValues[$target]; } } Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-27 13:00:35 UTC (rev 80) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-27 14:43:57 UTC (rev 81) @@ -834,6 +834,18 @@ return $this; } + /** + * Reset the processing / display order for getItemsOrdered(). + * + * Model items are displayed in the order they are first set() by the code. + * Using this functions resets this list and allows you to start over + * and determine the display order by the order you set() the items from + * now on. + * + * @see getItemsOrdered() + * + * @return MUtil_Model_ModelAbstract (continuation pattern) + */ public function resetOrder() { $this->_model_order = null; @@ -845,7 +857,7 @@ * * @param array $newValues The values to store for a single model item. * @param array $filter If the filter contains old key values these are used - * te decide on update versus insert. + * to decide on update versus insert. * @return array The values as they are after saving (they may change). */ abstract public function save(array $newValues, array $filter = null); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-09-28 13:59:45
|
Revision: 85 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=85&view=rev Author: matijsdejong Date: 2011-09-28 13:59:38 +0000 (Wed, 28 Sep 2011) Log Message: ----------- - documentation changes for GemsEscort.php and ModelAbstract.php - fix for RespondentModel.php: auto organization filter now applied in _checkFilterUsed Modified Paths: -------------- trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Model/ModelAbstract.php Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2011-09-28 12:56:41 UTC (rev 84) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2011-09-28 13:59:38 UTC (rev 85) @@ -50,6 +50,8 @@ */ class Gems_Model_RespondentModel extends Gems_Model_HiddenOrganizationModel { + protected $hashBsn = true; + public function __construct() { // gems__respondents MUST be first table for INSERTS!! @@ -65,10 +67,32 @@ $this->setOnSave('gr2o_opened_by', GemsEscort::getInstance()->session->user_id); $this->setSaveOnChange('gr2o_opened_by'); - $this->setSaveWhenNotNull('grs_bsn'); - $this->setOnSave('grs_bsn', array($this, 'formatBSN')); + if ($this->hashBsn) { + $this->setSaveWhenNotNull('grs_bsn'); + $this->setOnSave('grs_bsn', array($this, 'formatBSN')); + } } + /** + * Add an organization filter if it wasn't specified in the filter. + * + * Checks the filter on sematic correctness and replaces the text seacrh filter + * with the real filter. + * + * @param mixed $filter True for the filter stored in this model or a filter array + * @return array The filter to use + */ + protected function _checkFilterUsed($filter) + { + $filter = parent::_checkFilterUsed($filter); + + if (! isset($filter['gr2o_id_organization'])) { + $filter['gr2o_id_organization'] = $this->getCurrentOrganization(); + } + + return $filter; + } + public function formatBSN($name, $value, $new = false) { return md5($value); @@ -90,16 +114,6 @@ return $this; } - public function getSelect() - { - $select = parent::getSelect(); - $adapter = $select->getAdapter(); - - $select->where($adapter->quoteIdentifier('gr2o_id_organization') . ' = ?', $this->getCurrentOrganization()); - - return $select; - } - public function getRespondentTracksModel() { $model = new Gems_Model_JoinModel('surveys', 'gems__respondent2track'); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-09-28 12:56:41 UTC (rev 84) +++ trunk/library/classes/GemsEscort.php 2011-09-28 13:59:38 UTC (rev 85) @@ -139,6 +139,8 @@ /** * Initialize the logger + * + * @return Gems_Log */ protected function _initLogger() { Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-28 12:56:41 UTC (rev 84) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-28 13:59:38 UTC (rev 85) @@ -79,6 +79,13 @@ $this->_model_name = $modelName; } + /** + * Checks the filter on sematic correctness and replaces the text seacrh filter + * with the real filter. + * + * @param mixed $filter True for the filter stored in this model or a filter array + * @return array The filter to use + */ protected function _checkFilterUsed($filter) { if (true === $filter) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-13 10:37:16
|
Revision: 99 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=99&view=rev Author: mennodekker Date: 2011-10-13 10:37:10 +0000 (Thu, 13 Oct 2011) Log Message: ----------- Staff edit now can only assign groups he is in or that he inherits from Modified Paths: -------------- trunk/library/classes/Gems/Controller/BrowseEditAction.php trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/MUtil/Acl.php Modified: trunk/library/classes/Gems/Controller/BrowseEditAction.php =================================================================== --- trunk/library/classes/Gems/Controller/BrowseEditAction.php 2011-10-13 10:30:21 UTC (rev 98) +++ trunk/library/classes/Gems/Controller/BrowseEditAction.php 2011-10-13 10:37:10 UTC (rev 99) @@ -294,7 +294,9 @@ { if ($this->useTabbedForms) { //Create the tabs tried in $form->render() but somehow that is never reached - Gems_TabForm::htmlElementsToTabs($form); + 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)) { Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2011-10-13 10:30:21 UTC (rev 98) +++ trunk/library/classes/Gems/Default/StaffAction.php 2011-10-13 10:37:10 UTC (rev 99) @@ -124,16 +124,11 @@ $bridge->addText( 'gsf_email', array('size' => 30))->addValidator('SimpleEmail')->addValidator($model->createUniqueValidator('gsf_email')); if ($this->escort->hasPrivilege('pr.staff.edit.all')) { - $this->_groups = MUtil_Lazy::call($dbLookup->getStaffGroups); - $bridge->addSelect('gsf_id_organization'); $bridge->addSelect('gsf_id_primary_group'); } else { - $sql = "SELECT ggp_id_group, ggp_name FROM gems__groups WHERE ggp_group_active=1 AND ggp_staff_members=1 AND ggp_role != 'super' ORDER BY ggp_name"; - $this->_groups = MUtil_Lazy::call(array($this->db, 'fetchPairs'), $sql); - $bridge->addExhibitor('gsf_id_organization'); - $bridge->addSelect( 'gsf_id_primary_group', 'multiOptions', $dbLookup->getStaffGroupsNoSuper()); + $bridge->addSelect( 'gsf_id_primary_group', 'multiOptions', $dbLookup->getAllowedStaffGroups()); } $bridge->addCheckbox('gsf_logout_on_survey', 'description', $this->_('If checked the user will logoff when answering a survey.')); Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2011-10-13 10:30:21 UTC (rev 98) +++ trunk/library/classes/Gems/Util/DbLookup.php 2011-10-13 10:37:10 UTC (rev 99) @@ -69,6 +69,12 @@ */ protected $util; + /** + * + * @var Zend_Session + */ + protected $session; + public function getActiveOrganizations() { static $organizations; @@ -186,19 +192,31 @@ return $groups; } - public function getStaffGroupsNoSuper() + /** + * Retrieve an array of groups the user is allowed to assign: his own group and all groups + * he inherits rights from + * + * @return array + */ + public function getAllowedStaffGroups() { $groups = $this->getActiveStaffGroups(); - $roles = $this->db->fetchPairs('SELECT ggp_id_group, ggp_role FROM gems__groups WHERE ggp_group_active=1 AND ggp_staff_members=1 ORDER BY ggp_name'); - $result = array(); + if ($this->session->user_role === 'super') { + return $groups; - foreach ($roles as $id => $role) { - if (($role !== 'super') && isset($groups[$id])) { - $result[$id] = $groups[$id]; + } else { + $rolesAllowed = $this->acl->getRoleAndParents($this->session->user_role); + $roles = $this->db->fetchPairs('SELECT ggp_id_group, ggp_role FROM gems__groups WHERE ggp_group_active=1 AND ggp_staff_members=1 ORDER BY ggp_name'); + $result = array(); + + foreach ($roles as $id => $role) { + if ((in_array($role, $rolesAllowed)) && isset($groups[$id])) { + $result[$id] = $groups[$id]; + } } + + return $result; } - - return $result; } public function getUserConsents() Modified: trunk/library/classes/MUtil/Acl.php =================================================================== --- trunk/library/classes/MUtil/Acl.php 2011-10-13 10:30:21 UTC (rev 98) +++ trunk/library/classes/MUtil/Acl.php 2011-10-13 10:37:10 UTC (rev 99) @@ -1,31 +1,31 @@ <?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. - * + +/** + * 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 $Id$ @@ -37,7 +37,7 @@ /** * Extends Zend_Acl with a couple of overview functions/ - * + * * @author Matijs de Jong * @package MUtil * @subpackage Acl @@ -80,14 +80,14 @@ foreach ($rule['byPrivilegeId'] as $privilege => $pdata) { if (! isset($results[$privilege])) { $results[$privilege] = array( - parent::TYPE_ALLOW => array(), + parent::TYPE_ALLOW => array(), parent::TYPE_DENY => array()); } if (isset($pdata['type'])) { if ($pdata['type'] === parent::TYPE_ALLOW) { $results[$privilege][parent::TYPE_ALLOW][] = $role; - } elseif ($pdata['type'] === parent::TYPE_DENY) { + } elseif ($pdata['type'] === parent::TYPE_DENY) { $results[$privilege][parent::TYPE_DENY][] = $role; } } @@ -101,6 +101,26 @@ } /** + * Retrieve an array of the current role and all parents + * + * @param string $role + * @param array $parents + * @return array + */ + public function getRoleAndParents($role, $parents = array()) { + $results = $parents; + $result = $this->_getRoleRegistry()->getParents($role); + foreach($result as $roleId => $selRole) { + if (!in_array($roleId, $results)) { + $results = $this->getRoleAndParents($roleId, $results); + } + $results[$roleId] = $roleId; + } + $results[$role] = $role; + return $results; + } + + /** * Returns an array of roles with all direct and inherited privileges * * Sample output: @@ -147,15 +167,15 @@ /** * Returns all allow and deny rules for a given role - * + * * Sample output: * <code> * [Zend_Acl::TYPE_ALLOW]=>array(<index>=>privilege), * [Zend_Acl::TYPE_DENY]=>array(<index>=>privilege) * </code> - * + * * @param string $role - * @return array + * @return array */ public function getPrivileges ($role) { $rule = $this->_getRules(null, $this->getRole($role)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-17 12:03:16
|
Revision: 106 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=106&view=rev Author: mennodekker Date: 2011-10-17 12:03:09 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Fixed #17: Implement maintenance mode where only superadmin are allowed to login Modified Paths: -------------- trunk/library/classes/Gems/Default/ProjectInformationAction.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Menu/SubMenuItem.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-17 11:22:46 UTC (rev 105) +++ trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-17 12:03:09 UTC (rev 106) @@ -135,6 +135,17 @@ $this->_showTable($this->_('Version information'), $data); } + public function maintenanceAction() + { + $lockFile = GEMS_ROOT_DIR . '/var/settings/lock.txt'; + if(file_exists($lockFile)) { + unlink($lockFile); + } else { + touch($lockFile); + } + $this->_forward('index'); + } + public function phpAction() { $this->html->h2($this->_('Server PHP Info')); Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-17 11:22:46 UTC (rev 105) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-17 12:03:09 UTC (rev 106) @@ -300,6 +300,7 @@ $page->addAction($this->_('PHP'), null, 'php'); $page->addAction($this->_('Project'), null, 'project'); $page->addAction($this->_('Session'), null, 'session'); + $page->addAction($this->_('Maintenance mode'), 'pr.maintenance', 'maintenance'); return $page; } Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php =================================================================== --- trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-10-17 11:22:46 UTC (rev 105) +++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-10-17 12:03:09 UTC (rev 106) @@ -348,6 +348,16 @@ return null; } + /** + * Add an action to the current subMenuItem + * + * @param string $label The label to display for the menu item + * @param string $privilege The privilege for the item + * @param string $controller What controller to use + * @param string $action The name of the action + * @param array $other Array of extra options for this item, e.g. 'visible', 'allowed', 'class', 'icon', 'target', 'type', 'button_only' + * @return Gems_Menu_SubMenuItem + */ public function addAction($label, $privilege = null, $action = 'index', array $other = array()) { $other['label'] = $label; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-10-17 11:22:46 UTC (rev 105) +++ trunk/library/classes/GemsEscort.php 2011-10-17 12:03:09 UTC (rev 106) @@ -1519,6 +1519,25 @@ $this->menu = $this->getLoader()->createMenu($this); $this->_updateVariable('menu'); + /** + * Check if we are in maintenance mode or not. This is triggeren by a file in the var/settings + * directory with the name lock.txt + */ + if(file_exists(GEMS_ROOT_DIR . '/var/settings/lock.txt')) { + if ($this->session->user_id && $this->session->user_role !== 'super') { + //Still allow logoff so we can relogin as super + if (!('index' == $request->getControllerName() && 'logoff' == $request->getActionName())) { + $this->setError( + $this->_('Please check back later.'), + 401, + $this->_('System is in maintenance mode')); + } + } else { + $this->getMessenger()->addMessage($this->_('System is in maintenance mode')); + MUtil_Echo::r($this->_('System is in maintenance mode')); + } + } + // Gems does not use index/index if (('index' == $request->getControllerName()) && ('index' == $request->getActionName())) { // Instead Gems routes to the first available menu item when this is the request target This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-20 14:12:38
|
Revision: 121 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=121&view=rev Author: matijsdejong Date: 2011-10-20 14:12:29 +0000 (Thu, 20 Oct 2011) Log Message: ----------- Fix for #25: Ask button showed in between screen. Modified Paths: -------------- trunk/library/classes/Gems/Menu/SubMenuItem.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php =================================================================== --- trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-10-20 13:56:34 UTC (rev 120) +++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-10-20 14:12:29 UTC (rev 121) @@ -551,11 +551,12 @@ return $menu; } - public function applyHiddenParameters(Gems_Menu_ParameterSource $source) + public function applyHiddenParameters(Zend_Controller_Request_Abstract $request, Gems_Menu_ParameterSource $source) { if ($this->_hiddenParameters) { - foreach ($this->_hiddenParameters as $key => $name) { - $source[$key] = $name; + foreach ($this->_hiddenParameters as $key => $value) { + $request->setParam($key, $value); + $source[$key] = $value; } } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-10-20 13:56:34 UTC (rev 120) +++ trunk/library/classes/GemsEscort.php 2011-10-20 14:12:29 UTC (rev 121) @@ -1607,7 +1607,7 @@ } if (isset($menuItem)) { - $menuItem->applyHiddenParameters($this->menu->getParameterSource()); + $menuItem->applyHiddenParameters($request, $this->menu->getParameterSource()); $this->menu->setCurrent($menuItem); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-25 12:17:46
|
Revision: 136 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=136&view=rev Author: mennodekker Date: 2011-10-25 12:17:39 +0000 (Tue, 25 Oct 2011) Log Message: ----------- project.ini login gets role 'master' with all privileges, existing 'super' user can be edited again. It is now a choice if one wants to create a group that has the master role or not. when there is no such group the right can not be assigned to staff. When decided so, the elevation of rights can be done by updating the role in the session to 'master'. Also removed obsolete methods as project Roles are not allowed since the introduction of db-storage. Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Roles.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-10-25 12:17:39 UTC (rev 136) @@ -161,10 +161,10 @@ $this->session->user_id = 2000; $this->session->user_name = $_POST['userlogin']; $this->session->user_group = 800; - $this->session->user_role = 'super'; + $this->session->user_role = 'master'; $this->session->user_organization_id = 70; $this->session->user_organization_name = 'SUPER ADMIN'; - $this->session->user_style = 'pulse'; + $this->session->user_style = 'gems'; //Als er nog geen tabellen zijn, moet dit ingesteld worden //@@TODO Nog kijken hoe beter op te lossen (met try op tabel ofzo) $this->session->allowedOrgs = array($this->session->user_organization_id=>$this->session->user_organization_name); Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/Gems/Default/RoleAction.php 2011-10-25 12:17:39 UTC (rev 136) @@ -120,7 +120,7 @@ $disabled = $checkbox->getAttrib('disable'); if ($disabled) { - $values = array_merge($values, $disabled); + $values = array_merge((array) $values, $disabled); } $checkbox->setValue($values); return $form; @@ -151,6 +151,11 @@ $data['grl_privileges'] = implode(',', $data['grl_privileges']); } + if(isset($data['grl_name']) && $data['grl_name'] == 'master') { + $form->getElement('grl_name')->setErrors(array($this->_('Illegal name'))); + return false; + } + return true; } @@ -184,9 +189,9 @@ $model = $this->getModel(); $data = $model->loadFirst(); - //If we try to edit super, add an error message and reroute - if (isset($data['grl_name']) && $data['grl_name']=='super') { - $this->addMessage($this->_('Editing `super` is not allowed')); + //If we try to edit master, add an error message and reroute + if (isset($data['grl_name']) && $data['grl_name']=='master') { + $this->addMessage($this->_('Editing `master` is not allowed')); $this->_reroute(array('action'=>'index'), true); } Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/Gems/Default/StaffAction.php 2011-10-25 12:17:39 UTC (rev 136) @@ -92,7 +92,7 @@ { $dbLookup = $this->util->getDbLookup(); - $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getActiveStaffGroups)); + $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups)); if ($new) { $model->set('gsf_id_primary_group', 'default', $dbLookup->getDefaultGroup()); } else { @@ -125,11 +125,10 @@ if ($this->escort->hasPrivilege('pr.staff.edit.all')) { $bridge->addSelect('gsf_id_organization'); - $bridge->addSelect('gsf_id_primary_group'); } else { $bridge->addExhibitor('gsf_id_organization'); - $bridge->addSelect( 'gsf_id_primary_group', 'multiOptions', $dbLookup->getAllowedStaffGroups()); } + $bridge->addSelect('gsf_id_primary_group'); $bridge->addCheckbox('gsf_logout_on_survey', 'description', $this->_('If checked the user will logoff when answering a survey.')); $bridge->addSelect('gsf_iso_lang'); Modified: trunk/library/classes/Gems/Roles.php =================================================================== --- trunk/library/classes/Gems/Roles.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/Gems/Roles.php 2011-10-25 12:17:39 UTC (rev 136) @@ -1,6 +1,4 @@ <?php - - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -26,27 +24,29 @@ * 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 Roles + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** - * This is the generic Roles class to be extended by the project + * This is the generic Roles class * - * It loads the ACL in four stages: + * It loads the ACL in two stages when there is no db present, otherwise it just loads from the db: * * 1. $this->loadDefaultRoles() * 2. $this->loadDefaultPrivileges() * Normally you should not touch this to make upgrading easier * - * 3. $this->loadProjectRoles() - * 4. $this->loadProjectPrivileges() - * This is where you can revoke or add privileges and/or add your own roles. * - * - * @version $Id$ - * @author user - * @filesource - * @package Gems + * @package Gems * @subpackage Roles + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ class Gems_Roles { @@ -134,15 +134,15 @@ //Voeg standaard rollen en privileges in $this->loadDefaultRoles(); $this->loadDefaultPrivileges(); - - //Voeg project rollen em privileges in - $this->loadProjectRoles(); - $this->loadProjectPrivileges(); } - //Now allow super admin all access, except for the actions that have the nologin privilege (->the login action) - // $this->_acl->allow('super'); - // $this->_acl->deny('super', null, 'pr.nologin'); + //Now allow 'master' all access, except for the actions that have the nologin privilege (->the login action) + if (!$this->_acl->hasRole('master')) { + //Add role if not already present + $this->_acl->addRole('master'); + } + $this->_acl->allow('master'); + $this->_acl->deny('master', null, 'pr.nologin'); } public function load() { @@ -222,98 +222,22 @@ } public function loadDefaultPrivileges() { + /** + * Only add the nologin role, as the others should come from the database when it is initialized + */ $this->addPrivilege('nologin', 'pr.contact.bugs', 'pr.contact.support', 'pr.nologin' - ) - ->addPrivilege('guest', - 'pr.ask', - 'pr.contact.bugs', 'pr.contact.support', - 'pr.islogin', - 'pr.respondent' - ) - // ->allow('respondent', null, array('islogin')) - ->addPrivilege('staff', - 'pr.option.edit', 'pr.option.password', - 'pr.plan', 'pr.plan.overview', 'pr.plan.token', - 'pr.project', 'pr.project.questions', - 'pr.respondent.create', 'pr.respondent.edit', - 'pr.respondent.who', //Who filled out the survey instead of just the role - 'pr.setup', - 'pr.staff', - 'pr.survey', 'pr.survey.create', - 'pr.token', 'pr.token.answers', 'pr.token.delete', 'pr.token.edit', 'pr.token.mail', 'pr.token.print', - 'pr.track', 'pr.track.create', 'pr.track.delete', 'pr.track.edit' - ) - ->addPrivilege('researcher', - 'pr.invitation', - 'pr.result', - 'pr.islogin' - ) - // ->allow('security', null, array()) - ->addPrivilege('admin', - 'pr.consent', 'pr.consent.create', 'pr.consent.edit', - 'pr.group', - 'pr.role', - 'pr.mail', 'pr.mail.create', 'pr.mail.delete', 'pr.mail.edit', - 'pr.organization', 'pr.organization-switch', - 'pr.plan.overview.excel', 'pr.plan.respondent', 'pr.plan.respondent.excel', 'pr.plan.token.excel', - 'pr.project-information', - 'pr.reception', 'pr.reception.create', 'pr.reception.edit', - 'pr.respondent.choose-org', 'pr.respondent.delete', - 'pr.respondent.result', //Show the result of the survey in the overview - 'pr.source', - 'pr.staff.create', 'pr.staff.delete', 'pr.staff.edit', - 'pr.survey-maintenance', - 'pr.track-maintenance', - 'pr.token.mail.freetext' - ) - ->addPrivilege('super', - 'pr.consent.delete', - 'pr.country', 'pr.country.create', 'pr.country.delete', 'pr.country.edit', - 'pr.database', 'pr.database.create', 'pr.database.delete', 'pr.database.edit', 'pr.database.execute', 'pr.database.patches', - 'pr.group.create', 'pr.group.edit', - 'pr.role.create', 'pr.role.edit', - 'pr.language', - 'pr.organization.create', 'pr.organization.edit', - 'pr.plan.choose-org', 'pr.plan.mail-as-application', - 'pr.reception.delete', - 'pr.source.create', 'pr.source.edit', - 'pr.staff.edit.all', - 'pr.survey-maintenance.edit', - 'pr.track-maintenance.create', 'pr.track-maintenance.edit' - ); - - /* * *************************************** - * UNASSIGNED RIGHTS (by default) - * - * 'pr.group.delete' - * 'pr.organization.delete' - * 'pr.source.delete' - * 'pr.track-maintenance.delete' - * *************************************** */ + ); } public function loadDefaultRoles() { - $this->addRole(new Zend_Acl_Role('nologin')) - ->addRole(new Zend_Acl_Role('guest')) - ->addRole(new Zend_Acl_Role('respondent'), 'guest') - ->addRole(new Zend_Acl_Role('staff'), 'guest') - ->addRole(new Zend_Acl_Role('physician'), 'staff') - ->addRole(new Zend_Acl_Role('researcher')) - ->addRole(new Zend_Acl_Role('security'), 'guest') - ->addRole(new Zend_Acl_Role('admin'), array('staff', 'researcher', 'security')) - ->addRole(new Zend_Acl_Role('super'), 'admin'); + /** + * Only add the nologin role, as the others should come from the database when it is initialized + */ + $this->addRole(new Zend_Acl_Role('nologin')); } - public function loadProjectPrivileges() { - - } - - public function loadProjectRoles() { - - } - private function save() { if ($this->_cache instanceof Zend_Cache_Core) { if (!$this->_cache->save($this->_acl, $this->_cacheid, array(), null)) Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/Gems/Util/DbLookup.php 2011-10-25 12:17:39 UTC (rev 136) @@ -131,7 +131,7 @@ public function getAllowedStaffGroups() { $groups = $this->getActiveStaffGroups(); - if ($this->session->user_role === 'super') { + if ($this->session->user_role === 'master') { return $groups; } else { Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-10-25 11:59:29 UTC (rev 135) +++ trunk/library/classes/GemsEscort.php 2011-10-25 12:17:39 UTC (rev 136) @@ -1533,8 +1533,8 @@ * directory with the name lock.txt */ if (file_exists($this->getMaintenanceLockFilename())) { - if ($this->session->user_id && $this->session->user_role !== 'super') { - //Still allow logoff so we can relogin as super + if ($this->session->user_id && $this->session->user_role !== 'master') { + //Still allow logoff so we can relogin as master if (!('index' == $request->getControllerName() && 'logoff' == $request->getActionName())) { $this->setError( $this->_('Please check back later.'), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-26 11:58:22
|
Revision: 143 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=143&view=rev Author: mennodekker Date: 2011-10-26 11:58:13 +0000 (Wed, 26 Oct 2011) Log Message: ----------- Fixed #30: Speedup of execution by using a cache, can probably be improved further by using APC instead of file, there is a new switch in project info to clean the cache using the privilege used to toggle maintenance mode Modified Paths: -------------- trunk/library/classes/Gems/Default/ProjectInformationAction.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-26 11:22:46 UTC (rev 142) +++ trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-26 11:58:13 UTC (rev 143) @@ -153,7 +153,8 @@ $request = $this->getRequest(); $buttonList = $this->menu->getMenuList(); $buttonList->addParameterSources($request) - ->addByController($request->getControllerName(), 'maintenance', $label); + ->addByController($request->getControllerName(), 'maintenance', $label) + ->addByController($request->getControllerName(), 'cacheclean'); // $this->html->buttonDiv($buttonList); @@ -180,6 +181,15 @@ $this->_reroute(array($request->getActionKey() => 'index')); } + public function cachecleanAction() + { + $this->escort->cache->clean(); + $this->addMessage($this->_('Cache cleaned')); + // Redirect + $request = $this->getRequest(); + $this->_reroute(array($request->getActionKey() => 'index')); + } + public function phpAction() { $this->html->h2($this->_('Server PHP Info')); Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-26 11:22:46 UTC (rev 142) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-26 11:58:13 UTC (rev 143) @@ -316,6 +316,7 @@ $page->addAction($this->_('Project'), null, 'project'); $page->addAction($this->_('Session'), null, 'session'); $page->addButtonOnly($this->_('Maintenance mode'), 'pr.maintenance', 'project-information', 'maintenance'); + $page->addButtonOnly($this->_('Clean cache'), 'pr.maintenance', 'project-information', 'cacheclean'); return $page; } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-10-26 11:22:46 UTC (rev 142) +++ trunk/library/classes/GemsEscort.php 2011-10-26 11:58:13 UTC (rev 143) @@ -138,6 +138,36 @@ } /** + * Create a default file cache for the Translate and DB adapters to speed up execution + * + * @return Zend_Cache_Core + */ + protected function _initCache() + { + $exists = false; + $cacheDir = GEMS_ROOT_DIR . "/var/cache/"; + if (!file_exists($cacheDir)) { + if (mkdir($cacheDir, 0777, true)) { + $exists = true; + } + } else { + $exists = true; + } + + if ($exists) { + $cacheFrontendOptions = array('automatic_serialization' => true); + $cacheBackendOptions = array('cache_dir' => $cacheDir); + + $cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions); + + Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); + Zend_Translate::setCache($cache); + } + + return $cache; + } + + /** * Initialize the logger * * @return Gems_Log This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-02 11:36:03
|
Revision: 164 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=164&view=rev Author: mennodekker Date: 2011-11-02 11:35:57 +0000 (Wed, 02 Nov 2011) Log Message: ----------- Hopefully transparent fix for huge tabform performance ->removes the duplicate steps in htmlElementsToTabs Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/Model/FormBridge.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 11:35:57 UTC (rev 164) @@ -120,7 +120,7 @@ $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)), - array('Tooltip'), + '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 . ' ' . $group->getName(). ' ' . $group->getAttrib('class'))) @@ -133,7 +133,7 @@ $decorators = array( array('Description', array('class'=>'description')), 'Errors', - array('Tooltip'), + 'Tooltip', ); //If we want to see the individual fields labels, do so: @@ -179,7 +179,7 @@ $decorators = array( array('Description', array('class'=>'description')), 'Errors', - array('Tooltip'), + '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->getName())) @@ -192,7 +192,7 @@ '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)), - array('Tooltip'), + '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())) ); @@ -202,7 +202,7 @@ '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)), - array('Tooltip'), + '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())) @@ -222,7 +222,7 @@ $decorator->setOption('class', $this->_alternate . ' ' . $element->getName()); } - return parent::addElement($element); + return $this; } /** Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/Gems/TabForm.php 2011-11-02 11:35:57 UTC (rev 164) @@ -42,6 +42,75 @@ class Gems_TabForm extends Gems_Form { /** + * @var Gems_Form_TabSubForm + */ + private $currentTab = null; + + public function addElement($element, $name = null, $options = null) + { + if ($this->currentTab) { + return $this->currentTab->addElement($element, $name, $options); + } else { + return parent::addElement($element, $name, $options); + } + } + + public function addTab($name, $title) + { + if ($title instanceof MUtil_Html_Sequence) $title = $title->render($form->getView()); + $tab = new Gems_Form_TabSubForm(array('name' => $name, 'title' => strip_tags($title))); + $this->currentTab = $tab; + $this->addSubForm($tab, $name); + return $tab; + } + + public function addDisplayGroup(array $elements, $name, $options = null) { + if ($this->currentTab) { + return $this->currentTab->addDisplayGroup($elements, $name, $options); + } else { + //Add the group as usual + parent::addDisplayGroup($elements, $name, $options); + + //Retrieve it and set decorators + $group = $this->getDisplayGroup($name); + $group->setDecorators( array('FormElements', + array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) + )); + return $this; + } + } + + public function getDisplayGroup($name) + { + if ($group = parent::getDisplayGroup($name)) { + return $group; + } else { + $subforms = $this->getSubForms(); + foreach($subforms as $subform) { + if ($group = $subform->getDisplayGroup($name)) { + return $group; + } + } + return; + } + } + + public function getElement($name) + { + if ($element = parent::getElement($name)) { + return $element; + } else { + $subforms = $this->getSubForms(); + foreach($subforms as $subform) { + if ($element = $subform->getElement($name)) { + return $element; + } + } + return; + } + } + + /** * Create tabs from MUtil_Form_Element_Tab elements * * All elements following an element of type MUtil_Form_Element_Tab will be in tabs @@ -51,12 +120,6 @@ */ public static function htmlElementsToTabs($form) { foreach ($form as $element) { - //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); - } switch (get_class($element)) { case 'MUtil_Form_Element_Tab': //Start a new tab @@ -75,6 +138,7 @@ //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; @@ -103,7 +167,12 @@ $remove[] = $element->getName(); } } else { - unset($tab); + //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; } @@ -218,15 +287,4 @@ return $form; } - - public function addDisplayGroup(array $elements, $name, $options = null) { - //Add the group as usual - parent::addDisplayGroup($elements, $name, $options); - - //Retrieve it and set decorators - $group = $this->getDisplayGroup($name); - $group->setDecorators( array('FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) - )); - } } \ No newline at end of file Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-02 11:35:57 UTC (rev 164) @@ -618,10 +618,13 @@ $options = $this->_mergeOptions($name, $options, self::DISPLAY_OPTIONS, self::TAB_OPTIONS); - $element = new MUtil_Form_Element_Tab($name, $options); + if (method_exists($this->form, 'addTab')) { + return $this->form->addTab($name, $options['value']); + } else { + $element = new MUtil_Form_Element_Tab($name, $options); + $this->form->addElement($element); + } - $this->form->addElement($element); - return $element; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-03 13:10:21
|
Revision: 171 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=171&view=rev Author: matijsdejong Date: 2011-11-03 13:10:10 +0000 (Thu, 03 Nov 2011) Log Message: ----------- #31 continued: stored of has can now be set on project level (by overruling RespondentModel.php) Modified Paths: -------------- trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2011-11-03 13:08:54 UTC (rev 170) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2011-11-03 13:10:10 UTC (rev 171) @@ -50,8 +50,25 @@ */ class Gems_Model_RespondentModel extends Gems_Model_HiddenOrganizationModel { - protected $hashBsn = true; + const SSN_HASH = 0; + const SSN_HIDE = 1; + const SSN_OPEN = 2; + /** + * Determines how the social security number is stored. + * + * Can be changed is derived classes. + * + * @var int One of the SSN_ constants + */ + public $hashSsn = self::SSN_HASH; + + /** + * + * @var Gems_Project_ProjectSettings + */ + protected $project; + public function __construct() { // gems__respondents MUST be first table for INSERTS!! @@ -67,9 +84,9 @@ $this->setOnSave('gr2o_opened_by', GemsEscort::getInstance()->session->user_id); $this->setSaveOnChange('gr2o_opened_by'); - if ($this->hashBsn) { + if (self::SSN_HASH === $this->hashSsn) { $this->setSaveWhenNotNull('grs_ssn'); - $this->setOnSave('grs_ssn', array($this, 'formatBSN')); + $this->setOnSave('grs_ssn', array($this, 'formatSSN')); } } @@ -93,17 +110,21 @@ return $filter; } - public function formatBSN($name, $value, $new = false) + /** + * Return a hashed version of the input value. + * + * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility + * @param string $value The value to hash. + * @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility + * @return string The salted hash as a 32-character hexadecimal number. + */ + public function formatSSN($name, $value, $new = false) { - return md5($value); + if ($value) { + return $this->project->getValueHash($value); + } } - public function addPhysicians() - { - $this->addLeftTable('gems__staff', array('gr2o_id_physician' => 'gsf_id_user')); - return $this; - } - public function copyKeys($reset = false) { $keys = $this->_getKeysFor('gems__respondent2org'); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-03 13:08:54 UTC (rev 170) +++ trunk/library/classes/GemsEscort.php 2011-11-03 13:10:10 UTC (rev 171) @@ -1308,7 +1308,7 @@ } /** - * Return a hashed of the string. + * Return a hashed version of the input value. * * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility * @param string $value The value to hash. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-03 13:37:27
|
Revision: 173 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=173&view=rev Author: michieltcs Date: 2011-11-03 13:37:18 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Move getRandomPassword() to escort, make it public Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-03 13:23:03 UTC (rev 172) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-03 13:37:18 UTC (rev 173) @@ -273,26 +273,6 @@ $this->_reroute(array('action' => 'index'), true); } - protected function _getRandomPassword() - { - $salt = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789"; - $pass = ""; - - srand((double)microtime()*1000000); - - $i = 0; - - while ($i <= 7) - { - $num = rand() % strlen($salt); - $tmp = substr($salt, $num, 1); - $pass = $pass . $tmp; - $i++; - } - - return $pass; - } - protected function _getResetForm() { $form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor)); @@ -362,7 +342,7 @@ if (!empty($result)) { // generate new password - $password = $this->_getRandomPassword(); + $password = $this->escort->getRandomPassword(); $passwordHash = $this->escort->passwordHash(null, $password, false); $mail->setSubject('New password'); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-03 13:23:03 UTC (rev 172) +++ trunk/library/classes/GemsEscort.php 2011-11-03 13:37:18 UTC (rev 173) @@ -1319,7 +1319,31 @@ { return $this->project->getValueHash($value); } + + /** + * Generate random password + * @return string + */ + public function getRandomPassword() + { + $salt = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789"; + $pass = ""; + srand((double)microtime()*1000000); + + $i = 0; + + while ($i <= 7) + { + $num = rand() % strlen($salt); + $tmp = substr($salt, $num, 1); + $pass = $pass . $tmp; + $i++; + } + + return $pass; + } + /** * Hook 12: Called after an action is dispatched by Zend_Controller_Dispatcher. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 08:18:58
|
Revision: 214 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=214&view=rev Author: mennodekker Date: 2011-11-15 08:18:52 +0000 (Tue, 15 Nov 2011) Log Message: ----------- No extra call needed to apply a request, can only be forgotten when switching outside Escort Modified Paths: -------------- trunk/library/classes/Gems/User/User.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-14 17:51:04 UTC (rev 213) +++ trunk/library/classes/Gems/User/User.php 2011-11-15 08:18:52 UTC (rev 214) @@ -173,22 +173,6 @@ } /** - * Applies any setttings coming from the request object, e.g. processing cookies. - * - * @param Zend_Controller_Request_Abstract $request - * @return Gems_User_User (continuation pattern) - */ - public function applyRequest(Zend_Controller_Request_Abstract $request) - { - // MUtil_Echo::track($this->getOrganizationId(), Gems_Cookies::getOrganization($request)); - if (! $this->getOrganizationId()) { - $this->_setVar('user_organization_id', Gems_Cookies::getOrganization($request)); - } - - return $this; - } - - /** * Return true if a password reset key can be created. * * @return boolean @@ -332,7 +316,13 @@ */ public function getOrganizationId() { - return $this->_getVar('user_organization_id'); + $orgId = $this->_getVar('user_organization_id'); + + //If not set, read it from the cookie + if (is_null($orgId)) { + $orgId = Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest()); + } + return $orgId; } /** Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-14 17:51:04 UTC (rev 213) +++ trunk/library/classes/GemsEscort.php 2011-11-15 08:18:52 UTC (rev 214) @@ -1434,8 +1434,7 @@ public function routeShutdown(Zend_Controller_Request_Abstract $request) { $loader = $this->getLoader(); - $user = $loader->getCurrentUser() - ->applyRequest($request); + $user = $loader->getCurrentUser(); // MUtil_Echo::r($request->getParams(), 'params'); // MUtil_Echo::r($request->getUserParams(), 'userparams'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-17 11:46:14
|
Revision: 228 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=228&view=rev Author: mennodekker Date: 2011-11-17 11:46:04 +0000 (Thu, 17 Nov 2011) Log Message: ----------- Fixing a problem with the order of viewhelpers and moving datepicker display code to viewhelper instead of setview (result: javascript code once instead of twice in some case) Modified Paths: -------------- trunk/library/classes/Gems/Default/ExportAction.php trunk/library/classes/Gems/JQuery/Form/Element/ToggleCheckboxes.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/Form.php trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php Added Paths: ----------- trunk/library/classes/MUtil/JQuery/View/ trunk/library/classes/MUtil/JQuery/View/Helper/ trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php Removed Paths: ------------- trunk/library/classes/MUtil/View/Helper/DatePicker.php Modified: trunk/library/classes/Gems/Default/ExportAction.php =================================================================== --- trunk/library/classes/Gems/Default/ExportAction.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/Gems/Default/ExportAction.php 2011-11-17 11:46:04 UTC (rev 228) @@ -89,8 +89,6 @@ $div[] = $form; } else { Zend_Layout::resetMvcInstance(); - $this->view->addHelperPath('Gems/JQuery/View/Helper', 'Gems_JQuery_View_Helper'); - $this->view->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper'); $this->html->raw($form->render($this->view)); //Now add all onload actions to make the form still work Modified: trunk/library/classes/Gems/JQuery/Form/Element/ToggleCheckboxes.php =================================================================== --- trunk/library/classes/Gems/JQuery/Form/Element/ToggleCheckboxes.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/Gems/JQuery/Form/Element/ToggleCheckboxes.php 2011-11-17 11:46:04 UTC (rev 228) @@ -79,14 +79,12 @@ */ public function setView(Zend_View_Interface $view = null) { + $element = parent::setView($view); if (null !== $view) { if (false === $view->getPluginLoader('helper')->getPaths('Gems_JQuery_View_Helper')) { $view->addHelperPath('Gems/JQuery/View/Helper', 'Gems_JQuery_View_Helper'); } - if (false === $view->getPluginLoader('helper')->getPaths('ZendX_JQuery_View_Helper')) { - $view->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper'); - } } - return parent::setView($view); + return $element; } } \ No newline at end of file Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/Gems/TabForm.php 2011-11-17 11:46:04 UTC (rev 228) @@ -319,10 +319,12 @@ */ public function setView(Zend_View_Interface $view = null) { $form = parent::setView($view); - ZendX_JQuery::enableView($view); - - if (false === $view->getPluginLoader('helper')->getPaths('Gems_JQuery_View_Helper')) { - $view->addHelperPath('Gems/JQuery/View/Helper', 'Gems_JQuery_View_Helper'); + + if ($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; Modified: trunk/library/classes/MUtil/Form.php =================================================================== --- trunk/library/classes/MUtil/Form.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/MUtil/Form.php 2011-11-17 11:46:04 UTC (rev 228) @@ -1,44 +1,44 @@ <?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 + +/** + * 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. * - * @version $Id$ + * @version $Id$ * @package MUtil * @subpackage Acl * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License - */ + */ /** * @package MUtil * @subpackage Form * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License - */ + */ class MUtil_Form extends Zend_Form { protected $_displayOrder = array('element', 'errors', 'description'); @@ -96,11 +96,11 @@ return; } } - + + ZendX_JQuery::enableView($view); + if (false === $view->getPluginLoader('helper')->getPaths('MUtil_JQuery_View_Helper')) { $view->addHelperPath('MUtil/JQuery/View/Helper', 'MUtil_JQuery_View_Helper'); - - ZendX_JQuery::enableView($view); } } Modified: trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php =================================================================== --- trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/MUtil/JQuery/Form/Element/DatePicker.php 2011-11-17 11:46:04 UTC (rev 228) @@ -213,26 +213,14 @@ } } - if ($format = $this->getJQueryParam('dateFormat')) { - //* - $js[] = '{'; - $js[] = " var datePick = $('#" . $this->getId() . "');"; - $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[] = " dateused = datePick.attr('value');"; - $js[] = " dateused = $.datepicker.parseDate(dateformat, dateused);"; - $js[] = " datePick.attr('value', $.datepicker.formatDate(dateformat, dateused));"; - $js[] = " });"; - $js[] = '}'; + $element = parent::setView($view); - $view->inlineScript()->appendScript(implode("\n", $js)); // */ + if (null !== $view) { + if (false === $view->getPluginLoader('helper')->getPaths('MUtil_JQuery_View_Helper')) { + $view->addHelperPath('MUtil/JQuery/View/Helper', 'MUtil_JQuery_View_Helper'); + } } - return parent::setView($view); + return $element; } } Copied: trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php (from rev 225, trunk/library/classes/MUtil/View/Helper/DatePicker.php) =================================================================== --- trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php (rev 0) +++ trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php 2011-11-17 11:46:04 UTC (rev 228) @@ -0,0 +1,78 @@ +<?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 + * @subpackage View + */ + +/** + * + * @author Matijs de Jong + * @package MUtil + * @subpackage View + */ +class MUtil_JQuery_View_Helper_DatePicker extends ZendX_JQuery_View_Helper_DatePicker +{ + public function datePicker($id, $value = null, array $params = array(), array $attribs = array()) { + $result = parent::datePicker($id, $value, $params, $attribs); + if (isset($attribs['disabled'])) { + $js = "$('#" . $attribs['id'] . "').datepicker('disable');"; + $this->jquery->addOnLoad($js); + } + + if ($format = $params['dateFormat']) { + //* + $js = array(); + $js[] = '{'; + $js[] = " var datePick = $('#" . $id . "');"; + $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[] = " dateused = datePick.attr('value');"; + $js[] = " dateused = $.datepicker.parseDate(dateformat, dateused);"; + $js[] = " datePick.attr('value', $.datepicker.formatDate(dateformat, dateused));"; + $js[] = " });"; + $js[] = '}'; + + $this->view->inlineScript()->appendScript(implode("\n", $js)); // */ + } + return $result; + } + +} \ No newline at end of file Deleted: trunk/library/classes/MUtil/View/Helper/DatePicker.php =================================================================== --- trunk/library/classes/MUtil/View/Helper/DatePicker.php 2011-11-17 10:59:27 UTC (rev 227) +++ trunk/library/classes/MUtil/View/Helper/DatePicker.php 2011-11-17 11:46:04 UTC (rev 228) @@ -1,57 +0,0 @@ -<?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 - * @subpackage View - */ - -/** - * - * @author Matijs de Jong - * @package MUtil - * @subpackage View - */ -class MUtil_View_Helper_DatePicker extends ZendX_JQuery_View_Helper_DatePicker -{ - public function datePicker($id, $value = null, array $params = array(), array $attribs = array()) { - $result = parent::datePicker($id, $value, $params, $attribs); - if (isset($attribs['disabled'])) { - $js = "$('#" . $attribs['id'] . "').datepicker('disable');"; - $this->jquery->addOnLoad($js); - } - return $result; - } - -} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-18 09:35:01
|
Revision: 233 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=233&view=rev Author: mennodekker Date: 2011-11-18 09:34:55 +0000 (Fri, 18 Nov 2011) Log Message: ----------- Minor improvement for file cache Invalidate cache when patches have been executed Modified Paths: -------------- trunk/library/classes/Gems/Default/DatabaseAction.php trunk/library/classes/Gems/Upgrades.php trunk/library/classes/Gems/UpgradesAbstract.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/DatabaseAction.php =================================================================== --- trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-18 09:11:12 UTC (rev 232) +++ trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-18 09:34:55 UTC (rev 233) @@ -352,6 +352,14 @@ $form->getElement('db_level')->setValue($data['db_level']); $this->addMessage(sprintf($this->_('%d patch(es) executed.'), $changed)); + + //As a lot of cache depends on the database, it is best to clean the cache now + //since import tables might have changed + $cache = $this->escort->cache; + if ($cache instanceof Zend_Cache_Core) { + $cache->clean(); + $this->addMessage($this->_('Cache cleaned')); + } } $tableSql = sprintf( Modified: trunk/library/classes/Gems/Upgrades.php =================================================================== --- trunk/library/classes/Gems/Upgrades.php 2011-11-18 09:11:12 UTC (rev 232) +++ trunk/library/classes/Gems/Upgrades.php 2011-11-18 09:34:55 UTC (rev 233) @@ -66,6 +66,9 @@ public function Upgrade143to15() { $this->patcher->executePatch(42); + + $this->invalidateCache(); + return true; } } \ No newline at end of file Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-18 09:11:12 UTC (rev 232) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-18 09:34:55 UTC (rev 233) @@ -326,6 +326,19 @@ } /** + * Convenience method for cleaning the cache as this is often needed during + * upgrades + */ + public function invalidateCache() + { + $cache = $this->escort->cache; + if ($cache instanceof Zend_Cache_Core) { + $cache->clean(); + $this->addMessage($this->_('Cache cleaned')); + } + } + + /** * Register an upgrade in the stack, it can be executed by using $this->execute * * Index and context are optional and will be generated when omitted. For the Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-18 09:11:12 UTC (rev 232) +++ trunk/library/classes/GemsEscort.php 2011-11-18 09:34:55 UTC (rev 233) @@ -169,8 +169,14 @@ } if ($exists) { + /** + * automatic_cleaning_factor disables automatic cleaning of the cache and should get rid of + * random delays on heavy traffic sites with File cache. Apc does + * not support automatic cleaning. + */ $cacheFrontendOptions = array('automatic_serialization' => true, - 'cache_id_prefix' => GEMS_PROJECT_NAME . '_'); + 'cache_id_prefix' => GEMS_PROJECT_NAME . '_', + 'automatic_cleaning_factor' => 0); $cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-21 09:53:16
|
Revision: 245 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=245&view=rev Author: michieltcs Date: 2011-11-21 09:53:10 +0000 (Mon, 21 Nov 2011) Log Message: ----------- Refs #453 - Move expiration setting to project configuration, add support in Gems_User_UserLoader Modified Paths: -------------- trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-21 09:41:35 UTC (rev 244) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-21 09:53:10 UTC (rev 245) @@ -114,6 +114,10 @@ // is removed from GemsEscort if (! $this->session instanceof Zend_Session_Namespace) { $this->session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.session'); + + $idleTimeout = ($this->project->session['idleTimeout'] ? $this->project->session['idleTimeout'] : 1800); + + $this->session->setExpirationSeconds($idleTimeout); $extras['session'] = $this->session; } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-21 09:41:35 UTC (rev 244) +++ trunk/library/classes/GemsEscort.php 2011-11-21 09:53:10 UTC (rev 245) @@ -60,14 +60,6 @@ private $_startFirebird; /** - * Lifetime of the session (determines the expiration of the session cookie(s)) - * Defaults to 1800 seconds = 30 minutes, you override this in your own - * Escort class - * @var int - */ - protected $_sessionLifetime = 1800; - - /** * The menu variable * * @var Gems_Menu @@ -394,7 +386,10 @@ protected function _initSession() { $session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.session'); - $session->setExpirationSeconds($this->_sessionLifetime); + + $idleTimeout = ($this->project->session['idleTimeout'] ? $this->project->session['idleTimeout'] : 1800); + + $session->setExpirationSeconds($idleTimeout); if (! isset($session->user_role)) { $session->user_role = 'nologin'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-21 10:24:04
|
Revision: 248 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=248&view=rev Author: matijsdejong Date: 2011-11-21 10:23:53 +0000 (Mon, 21 Nov 2011) Log Message: ----------- Moved login page while logged in to GemsEscort->routeShutdown() Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-21 10:18:22 UTC (rev 247) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-21 10:23:53 UTC (rev 248) @@ -263,17 +263,6 @@ */ public function loginAction() { - // If already logged in, try to redirect to the first allowed and visible menu item - // if that fails, try to reroute to respondent/index - if ($this->loader->getCurrentUser()->isActive()) { - if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) { - $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); - $redirector->gotoRoute($menuItem->toRouteUrl($this->getRequest())); - } else { - $this->_reroute(array('controller' => 'respondent', 'action'=>'index')); - } - } - $form = $this->_getLoginForm(); $request = $this->getRequest(); @@ -319,7 +308,7 @@ } else { //Now present the user with an error message $errors = $authResult->getMessages(); - $this->addMessage($errors); + $this->addMessage($errors); //Also log the error to the log table //when the project has logging enabled Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-21 10:18:22 UTC (rev 247) +++ trunk/library/classes/GemsEscort.php 2011-11-21 10:23:53 UTC (rev 248) @@ -1475,7 +1475,7 @@ } // Gems does not use index/index - if (('index' == $request->getControllerName()) && ('index' == $request->getActionName())) { + if (('index' == $request->getControllerName()) && (('index' == $request->getActionName()) || ('login' == $request->getActionName()))) { // Instead Gems routes to the first available menu item when this is the request target if (! $user->gotoStartPage($this->menu, $request)) { $this->setError( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-21 12:07:08
|
Revision: 253 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=253&view=rev Author: matijsdejong Date: 2011-11-21 12:06:59 +0000 (Mon, 21 Nov 2011) Log Message: ----------- Make the Right, that was to simple. This code redirects a little more intelligently to prevent eternal loops. Modified Paths: -------------- trunk/library/classes/Gems/User/User.php trunk/library/classes/GemsEscort.php Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-21 11:30:36 UTC (rev 252) +++ trunk/library/classes/Gems/User/User.php 2011-11-21 12:06:59 UTC (rev 253) @@ -451,8 +451,11 @@ } if ($menuItem) { - $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); - $redirector->gotoRoute($menuItem->toRouteUrl($request)); + // Prevent redirecting to the current page. + if (! ($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) { + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); + $redirector->gotoRoute($menuItem->toRouteUrl($request)); + } } return $menuItem; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-21 11:30:36 UTC (rev 252) +++ trunk/library/classes/GemsEscort.php 2011-11-21 12:06:59 UTC (rev 253) @@ -1475,7 +1475,8 @@ } // Gems does not use index/index - if (('index' == $request->getControllerName()) && (('index' == $request->getActionName()) || ('login' == $request->getActionName()))) { + $action = $request->getActionName(); + 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( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-12-15 17:21:28
|
Revision: 362 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=362&view=rev Author: matijsdejong Date: 2011-12-15 17:21:17 +0000 (Thu, 15 Dec 2011) Log Message: ----------- Progress on progress panel (#45) Documentation extended for HtmlElement.php and TBodyElement.php Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php trunk/library/classes/MUtil/Html/HtmlElement.php trunk/library/classes/MUtil/Html/ProgressPanel.js trunk/library/classes/MUtil/Html/ProgressPanel.php trunk/library/classes/MUtil/Html/TBodyElement.php Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/Gems/Default/SourceAction.php 2011-12-15 17:21:17 UTC (rev 362) @@ -243,7 +243,11 @@ $this->html->h3($this->_('Synchronize all sources of surveys')); $this->html->pInfo($this->_('Synchronization will update the status of all surveys imported into this project to the status at the sources.')); - // $progress = $this->html->progress('0%'); + /* + $progress = $this->html->progress('0%'); + if ($progress->run($this->getRequest())) { + MUtil_Echo::track('running'); + } // */ if ($data) { $rdata = MUtil_Lazy::repeat($data); Modified: trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php =================================================================== --- trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2011-12-15 17:21:17 UTC (rev 362) @@ -134,6 +134,36 @@ } /** + * Returns the current field value. + * + * No markers are used. If you want to replace '{path}' with 'x', you + * must specificy the name '{path}', not 'path'. + * + * @param string $name Full name of the field. + * @return string The value placed. + */ + public function getField($name) + { + if (isset($this->_fields[$name])) { + return $this->_fields[$name]; + } + } + + /** + * Checks for the existence of a field value. + * + * No markers are used. If you want to replace '{path}' with 'x', you + * must specificy the name '{path}', not 'path'. + * + * @param string $name Full name of the field. + * @return boolean True if it exists + */ + public function hasField($name) + { + return array_key_exists($name, $this->_fields); + } + + /** * Set a field to search and replace in the content. * * No markers are used. If you want to replace '{path}' with 'x', you Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2011-12-15 17:21:17 UTC (rev 362) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -286,7 +285,11 @@ /** - * @var boolean|string When true, no content is used, when a string content is added to an attribute with that name. + * Allows the addition of any string content to an attribute with the name specified. + * + * E.g. in the ImgElement all content is added to the 'alt' attribute. + * + * @var boolean|string When not false, content is not used as element content, but added to the attribute */ protected $_contentToTag = false; @@ -476,8 +479,24 @@ protected $_repeatTags = false; + /** + * Extra array with special types for subclasses. + * + * When an object of one of the key types is used, then use + * the class method defined as the value. + * + * @see $_specialTypesDefault + * + * @var array Of 'class or interfacename' => 'class method' of null + */ protected $_specialTypes; + /** + * When an object of one of the key types is used, then use + * the class method defined as the value. + * + * @var array Of 'class or interfacename' => 'class method' + */ private $_specialTypesDefault = array( 'MUtil_Lazy_RepeatableInterface' => 'setRepeater', 'Zend_Paginator' => 'setRepeater', @@ -608,6 +627,16 @@ unset($this->_attribs[$name]); } + /** + * Create an default element for content. + * + * Some elements put their content in a fixed sub element, e.g. table uses tbody, + * tbody uses tr and tr uses td or th. + * + * @param mixed $value + * @param string $offset or null + * @return MUtil_Html_HtmlElement + */ protected function _createDefaultTag($value, $offset = null) { if (null === $offset) { Modified: trunk/library/classes/MUtil/Html/ProgressPanel.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-15 17:21:17 UTC (rev 362) @@ -9,16 +9,19 @@ function FUNCTION_PREFIX_Update(data) { - document.getElementById('pg-percent').style.width = data.percent + '%'; + main = document.getElementById('{ID}'); // .style.width = data.percent + '%'; - document.getElementById('pg-text-1').innerHTML = data.text; - document.getElementById('pg-text-2').innerHTML = data.text; + inner = main.getElementsByTagName('{CHILD}')[0]; + inner.style.width = data.percent + '%'; + inner.innerHTML = data.text; } function FUNCTION_PREFIX_Finish() { - document.getElementById('pg-percent').style.width = '100%'; + document.getElementById('{id}').style.width = '100%'; document.getElementById('pg-text-1').innerHTML = 'Demo done'; document.getElementById('pg-text-2').innerHTML = 'Demo done'; -} \ No newline at end of file +} + +// FUNCTION_PREFIX_Start(); Modified: trunk/library/classes/MUtil/Html/ProgressPanel.php =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-15 17:21:17 UTC (rev 362) @@ -49,6 +49,21 @@ const CODE = "MUtil_Html_ProgressPanel_Code"; /** + * For some elements (e.g. table and tbody) the logical thing to do when content + * is added that does not have an $_allowedChildTags is to add that content to + * the last item (i.e. row: tr) instead of adding a new row to the table or element. + * + * This is different from the standard behaviour: if you add a non-li item to an ul + * item it is added in a new li item. + * + * @see $_allowedChildTags + * @see $_lastChild + * + * @var boolean When true new content not having a $_allowedChildTags is added to $_lastChild. + */ + protected $_addtoLastChild = true; + + /** * Usually no text is appended after an element, but for certain elements we choose * to add a "\n" newline character instead, to keep the output readable in source * view. @@ -68,6 +83,33 @@ ); /** + * When content must contain certain element types only the default child tag contains + * the tagname of the element that is created to contain the content. + * + * When not in $_allowedChildTags the value is added to it in __construct(). + * + * When empty set to the first value of $_allowedChildTags (if any) in __construct(). + * + * @see $_allowedChildTags + * + * @var string The tagname of the element that should be created for content not having an $_allowedChildTags. + */ + protected $_defaultChildTag = 'div'; + + /** + * Name to prefix the functions, to avoid naming clashes. + * + * @var string Default is the classname with an extra underscore + */ + protected $_functionPrefix; + + /** + * + * @var MUtil_Html_HtmlElement + */ + protected $_innerElement; + + /** * Usually no text is appended before an element, but for certain elements we choose * to add a "\n" newline character instead, to keep the output readable in source * view. @@ -77,6 +119,20 @@ protected $_prependString = "\n"; /** + * The name of the parameter used for progress panel signals + * + * @var string + */ + public $progressParameterName = 'progress'; + + /** + * The value required for the progress panel to start running + * + * @var string + */ + public $progressParameterRunValue = 'run'; + + /** * Creates a 'div' progress panel * * @param mixed $arg_array A MUtil_Ra::args data collection. @@ -99,18 +155,34 @@ */ public function getCode() { - if (! $this->offsetExists(self::CODE)) { + if (! isset($this->_content[self::CODE])) { $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanel.js'); // $js->setInHeader(false); - $js->setField('FUNCTION_PREFIX', __CLASS__); + $js->setField('FUNCTION_PREFIX_', $this->getFunctionPrefix()); + $js->setField('{CHILD}', $this->_defaultChildTag); + $js->setField('{ID}', $this->getAttrib('id')); - $this->offsetSet(self::CODE, $js); + $this->_content[self::CODE] = $js; } - return $this->offsetGet(self::CODE); + return $this->_content[self::CODE]; } /** + * Returns the prefix used for the function names to avoid naming clashes. + * + * @return string + */ + public function getFunctionPrefix() + { + if (! $this->_functionPrefix) { + $this->setFunctionPrefix(__CLASS__ . '_'); + } + + return (string) $this->_functionPrefix; + } + + /** * Creates a 'div' progress panel * * @param mixed $arg_array A MUtil_Ra::args data collection. @@ -134,9 +206,37 @@ */ protected function renderElement(Zend_View_Abstract $view) { - // Make sure the JS code is added - $this->getCode(); + $js = $this->getCode(); + if (! $js->hasField('{URL}')) { + $js->setField('{URL}', $view->url(array($this->progressParameterName => $this->progressParameterRunValue))); + } return parent::renderElement($view); } + + /** + * Checks whether the progress panel should be running + * + * @param Zend_Controller_Request_Abstract $request + * @return boolean + */ + public function run(Zend_Controller_Request_Abstract $request) + { + return $request->getParam($this->progressParameterName) === $this->progressParameterRunValue; + } + + /** + * Name prefix for functions. + * + * Set automatically to __CLASS___, use different name + * in case of name clashes. + * + * @param string $prefix + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setFunctionPrefix($prefix) + { + $this->_functionPrefix = $prefix; + return $this; + } } Modified: trunk/library/classes/MUtil/Html/TBodyElement.php =================================================================== --- trunk/library/classes/MUtil/Html/TBodyElement.php 2011-12-15 15:56:53 UTC (rev 361) +++ trunk/library/classes/MUtil/Html/TBodyElement.php 2011-12-15 17:21:17 UTC (rev 362) @@ -1,46 +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$ */ /** - * - * @author Matijs de Jong - * @package MUtil + * A standaard TBODY element, that puts all contents in TR elements, implements the + * ColomInterface and allows you to specify a row class. + * + * You can alternate row classes by using a lazy value. + * + * @see MUtil_Html_TableElement + * + * @package MUtil * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Html_TBodyElement extends MUtil_Html_HtmlElement implements MUtil_Html_ColumnInterface { @@ -58,6 +65,16 @@ protected $_onEmptyLocal = null; + /** + * Create an default element for content. + * + * Some elements put their content in a fixed sub element, e.g. table uses tbody, + * tbody uses tr and tr uses td or th. + * + * @param mixed $value + * @param string $offset or null + * @return MUtil_Html_HtmlElement + */ protected function _createDefaultTag($value, $offset = null) { $row = parent::_createDefaultTag($value, $offset = null); @@ -73,29 +90,29 @@ /** * Returns the cell or a MUtil_MultiWrapper containing cells that occupy the column position, taking colspan and other functions into account. - * + * * @param int $col The numeric column position, starting at 0; * @return MUtil_Html_HtmlElement Probably an element of this type, but can also be something else, posing as an element. */ public function getColumn($col) { $results = $this->getColumnArray($col); - + switch (count($results)) { case 0: return null; - + case 1: return reset($results); - + default: return new MUtil_MultiWrapper($results); } } - + /** * Returns the cells that occupies the column position, taking colspan and other functions into account, in an array. - * + * * @param int $col The numeric column position, starting at 0; * @return array Of probably one MUtil_Html_HtmlElement */ @@ -111,10 +128,10 @@ return $results; } - + /** * Return the number of columns, taking such niceties as colspan into account - * + * * @return int */ public function getColumnCount() @@ -201,12 +218,12 @@ } /** - * Repeat the element when rendering. - * - * When repeatTags is false (the default) only the content is repeated but + * Repeat the element when rendering. + * + * When repeatTags is false (the default) only the content is repeated but * not the element tags. When repeatTags is true the both the tags and the * content are repeated. - * + * * @param mixed $repeater MUtil_Lazy_RepeatableInterface or something that can be made into one. * @param mixed $onEmptyContent Optional. When not null the content to display when the repeater does not result in data is set. * @param boolean $repeatTags Optional when not null the repeatTags switch is set. @@ -248,7 +265,7 @@ /** * Static helper function for creation, used by @see MUtil_Html_Creator. - * + * * @param mixed $arg_array Optional MUtil_Ra::args processed settings * @return MUtil_Html_TBodyElement with tag 'tbody' */ @@ -260,7 +277,7 @@ /** * Static helper function for creation, used by @see MUtil_Html_Creator. - * + * * @param mixed $arg_array Optional MUtil_Ra::args processed settings * @return MUtil_Html_TBodyElement with tag 'tfoot' */ @@ -272,7 +289,7 @@ /** * Static helper function for creation, used by @see MUtil_Html_Creator. - * + * * @param mixed $arg_array Optional MUtil_Ra::args processed settings * @return MUtil_Html_TBodyElement with tag 'thead' */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-01-03 10:54:57
|
Revision: 394 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=394&view=rev Author: mennodekker Date: 2012-01-03 10:54:48 +0000 (Tue, 03 Jan 2012) Log Message: ----------- Minor fixes for better display of tabforms Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php trunk/library/classes/MUtil/Model/FormBridge.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-01-02 13:07:44 UTC (rev 393) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-01-03 10:54:48 UTC (rev 394) @@ -110,11 +110,6 @@ //Add the group as usual parent::addDisplayGroup($elements, $name, $options); - //Fix alternation when number of elements is not even - if (count($elements) % 2) { - $dropMe = $this->_alternate->__toString(); - } - //Retrieve it and set decorators $group = $this->getDisplayGroup($name); $group->setDecorators( array('FormElements', @@ -123,7 +118,7 @@ '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 . ' ' . $group->getName(). ' ' . $group->getAttrib('class'))) + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) )); //Now add the right decorators to the elements @@ -217,16 +212,6 @@ if (!is_null($dec1)) array_unshift($decorators, $dec1); $element->setDecorators($decorators); - if ($element instanceof Zend_Form_Element_Hidden) { - //Make row hidden so it takes no height - $decorator = $element->getDecorator('row'); - $decorator->setOption('style', 'display:none;'); - - } else { - $decorator = $element->getDecorator('row'); - $decorator->setOption('class', $this->_alternate . ' ' . $element->getName()); - } - return $this; } @@ -250,4 +235,23 @@ } return $this; } + + public function setView(Zend_View_Interface $view = null) + { + //If we set the view, fix the alternating rows + if ($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 . ' ' . $name); + } + } + } + } + + return parent::setView($view); + } } \ No newline at end of file Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2012-01-02 13:07:44 UTC (rev 393) +++ trunk/library/classes/Gems/TabForm.php 2012-01-03 10:54:48 UTC (rev 394) @@ -324,8 +324,8 @@ $decorators = $this->getDecorators(); if (empty($decorators)) { $this->setDecorators(array( - array('TabErrors'), - array('decorator' => array('SubformElements' => 'FormElements')), + 'TabErrors', + array(array('SubformElements' => 'FormElements')), array('HtmlTag', array('tag' => 'div', 'id' => 'tabContainer', 'class' => 'mainForm')), array('TabContainer', array('id' => 'tabContainer', 'style' => 'width: 99%;')), 'FormElements', Modified: trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php =================================================================== --- trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php 2012-01-02 13:07:44 UTC (rev 393) +++ trunk/library/classes/MUtil/JQuery/View/Helper/DatePicker.php 2012-01-03 10:54:48 UTC (rev 394) @@ -70,7 +70,8 @@ $js[] = " });"; $js[] = '}'; - $this->view->inlineScript()->appendScript(implode("\n", $js)); // */ + $this->jquery->addOnLoad(implode("\n", $js)); + //$this->view->inlineScript()->appendScript(implode("\n", $js)); // */ } return $result; } Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2012-01-02 13:07:44 UTC (rev 393) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2012-01-03 10:54:48 UTC (rev 394) @@ -465,7 +465,7 @@ } $element = new Zend_Form_Element_Password($name, $options); - $this->form->addElement($element); + $this->_applyValidators($name, $element); if ($stringlength) { $element->addValidator('StringLength', true, $stringlength); @@ -483,7 +483,7 @@ $repeatElement->addValidator(new MUtil_Validate_IsConfirmed($name, isset($options['label']) ? $options['label'] : null)); } - return $this->_addToForm($name, $element); + return $element; } public function addRadio($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-01-05 10:55:16
|
Revision: 396 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=396&view=rev Author: mennodekker Date: 2012-01-05 09:54:04 +0000 (Thu, 05 Jan 2012) Log Message: ----------- Fixed translation bug in form selects: When element was created and options added it didn't know about the translation status of the form it was being added to Modified Paths: -------------- trunk/library/classes/Gems/Default/GroupAction.php trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/MUtil/Model/FormBridge.php Modified: trunk/library/classes/Gems/Default/GroupAction.php =================================================================== --- trunk/library/classes/Gems/Default/GroupAction.php 2012-01-05 09:27:33 UTC (rev 395) +++ trunk/library/classes/Gems/Default/GroupAction.php 2012-01-05 09:54:04 UTC (rev 396) @@ -1,35 +1,35 @@ <?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. - */ - + /** + * 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 @@ -62,7 +62,7 @@ $bridge->addHidden('ggp_id_group'); $bridge->addText('ggp_name', 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('ggp_name')); $bridge->addText('ggp_description', 'size', 40); - $bridge->addSelect('ggp_role', 'disableTranslator', true); + $bridge->addSelect('ggp_role'); $bridge->addCheckbox('ggp_group_active'); $bridge->addCheckbox('ggp_staff_members'); $bridge->addCheckbox('ggp_respondent_members'); Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2012-01-05 09:27:33 UTC (rev 395) +++ trunk/library/classes/Gems/Default/RoleAction.php 2012-01-05 09:54:04 UTC (rev 396) @@ -77,9 +77,9 @@ $roles = $this->acl->getRoles(); $parents = array_combine($roles, $roles); - $bridge->addMultiCheckbox('grl_parents', 'disableTranslator', true, 'multiOptions', $parents, 'required', false); + $bridge->addMultiCheckbox('grl_parents', 'multiOptions', $parents, 'required', false); - $checkbox = $bridge->addMultiCheckbox('grl_privileges', 'disableTranslator', true, 'multiOptions', $this->getUsedPrivileges(), 'required', false); + $checkbox = $bridge->addMultiCheckbox('grl_privileges', 'multiOptions', $this->getUsedPrivileges(), 'required', false); //Get inherited privileges and disable tem $result = $this->escort->acl->getRolePrivileges(); Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2012-01-05 09:27:33 UTC (rev 395) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2012-01-05 09:54:04 UTC (rev 396) @@ -156,6 +156,12 @@ private function _mergeOptions($name, array $options, $allowedOptionKeys_array) { + //If not explicitly set, use the form value for translatorDisabled, since we + //create the element outside the form scope and later add it + if (!isset($options['disableTranslator'])) { + $options['disableTranslator'] = $this->form->translatorIsDisabled(); + } + $args = func_get_args(); $allowedOptionsKeys = MUtil_Ra::args($args, 2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-01-18 12:28:48
|
Revision: 410 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=410&view=rev Author: matijsdejong Date: 2012-01-18 12:28:40 +0000 (Wed, 18 Jan 2012) Log Message: ----------- Pull batch processing works (#45). Push is required though plus some code cleanup needed. Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php trunk/library/classes/MUtil/Batch/BatchAbstract.php trunk/library/classes/MUtil/Html/ProgressPanel.php Added Paths: ----------- trunk/library/classes/MUtil/Batch/BatchPull.js trunk/library/classes/MUtil/Batch/BatchPush.js trunk/library/classes/MUtil/Batch/WaitBatch.php trunk/library/classes/MUtil/ProgressBar/ trunk/library/classes/MUtil/ProgressBar/Adapter/ trunk/library/classes/MUtil/ProgressBar/Adapter/JsPush.php Removed Paths: ------------- trunk/library/classes/MUtil/Html/ProgressPanelPull.js trunk/library/classes/MUtil/Html/ProgressPanelPush.js Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-01-18 12:28:40 UTC (rev 410) @@ -243,8 +243,38 @@ $this->html->h3($this->_('Synchronize all sources of surveys')); $this->html->pInfo($this->_('Synchronization will update the status of all surveys imported into this project to the status at the sources.')); + /* - $batch = new Gems_Tracker_Batch_SynchronizeSourceBatch(); + $batch = new MUtil_Batch_WaitBatch(); + $batch->method = MUtil_Batch_BatchAbstract::PUSH; + if ($batch->isLoaded()) { + if ($batch->isFinished()) { + if (! $batch->showReport($this->getRequest())) { + $batch->reset(); + } + } else { + if ($batch->hasStarted($this->getRequest())) { + $batch->runAll(); + exit; + } + } + } else { + $batch->addWaits(4, 2); + $batch->addWaitsLater(15, 1); + $batch->addWaits(1, 1); + $batch->addWaitsLater(1, 2); + $batch->addWaits(4); + } + if ($batch->showReport($this->getRequest())) { + $this->addMessage($batch->getReport()); + $batch->reset(); + $this->html->pInfo()->actionLink(array($batch->progressParameterName => null), $this->_('Restart')); + } else { + $this->html->append($batch->getPanel($this->view)); + } + // */ + /* + // $batch = new Gems_Tracker_Batch_SynchronizeSourceBatch(); // $batch->method = 'Push'; if (! $batch->isLoaded()) { foreach ($data as $row) { Modified: trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-01-18 12:28:40 UTC (rev 410) @@ -1,7 +1,7 @@ <?php /** - * Copyright (c) 2011, Erasmus MC + * Copyright (c) 2012, Erasmus MC * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,7 @@ * @package Gems * @subpackage Tracker * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC + * @copyright Copyright (c) 2012 Erasmus MC * @license New BSD License * @version $Id$ */ @@ -40,7 +40,7 @@ * * @package Gems * @subpackage Tracker - * @copyright Copyright (c) 2011 Erasmus MC + * @copyright Copyright (c) 2012 Erasmus MC * @license New BSD License * @since Class available since version 1.5 */ @@ -70,8 +70,10 @@ $tokenId = $tokenData; } - MUtil_Echo::track($tokenData); - $this->addStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenData); + // MUtil_Echo::track($tokenData); + $this->setStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenData); + + return $this; } protected function checkTrackTokens($respTrackData, $userId) @@ -99,7 +101,7 @@ } if ($token->isCompleted()) { - $this->addStep('processTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId); + $this->setStep('processTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId); } } @@ -116,7 +118,7 @@ } $trackId = $respTrack->getRespondentTrackId(); - $this->addStep('checkTrackTokens', 'chktrck-' . $trackId, $trackId, $userid); + $this->setStep('checkTrackTokens', 'chktrck-' . $trackId, $trackId, $userid); } } } Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-01-18 12:28:40 UTC (rev 410) @@ -1,7 +1,7 @@ <?php /** - * Copyright (c) 2011, Erasmus MC + * Copyright (c) 2012, Erasmus MC * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,17 +30,30 @@ * @package MUtil * @subpackage Batch * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC + * @copyright Copyright (c) 2012 Erasmus MC * @license New BSD License - * @version $Id$ + * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $ */ /** + * The Batch package is for the sequential processing of commands which may + * take to long to execute in a single request. * + * To use this package just sub class this class, write methods that run + * the code to be execute and then write the code that add's those functions + * to be executed. * + * Each step in the sequence consists of a method name of the child object + * and any number of scalar variables and array's containing scalar variables. + * + * A nice future extension would be to separate the storage engine used so we + * could use e.g. Zend_Queue as an alternative for storing the command stack. + * However, as this package needs more state info than available in Zend_Queue + * we would need an extra extension for that. + * * @package MUtil * @subpackage Batch - * @copyright Copyright (c) 2011 Erasmus MC + * @copyright Copyright (c) 2012 Erasmus MC * @license New BSD License * @since Class available since version 1.5 */ @@ -50,33 +63,132 @@ const PUSH = 'Push'; /** + * Name to prefix the functions, to avoid naming clashes. * + * @var string Default is the classname with an extra underscore + */ + protected $_functionPrefix; + + /** + * An id unique for this session. + * + * @var string Unique id + */ + private $_id; + + /** + * Stack to keep existing id's. + * + * @var array + */ + private static $_idStack = array(); + + /** + * * @var Zend_Session_Namespace */ private $_session; /** + * When true the progressbar should start immediately. When false the user has to perform an action. * - * @param string $name The name of this batch, defaults to classname + * @var boolean */ - public function __construct($name = null) + public $autoStart = true; + + /** + * The mode to use for the panel: push or pull + * + * @var string + */ + public $method = self::PULL; + + /** + * + * @var Zend_ProgressBar + */ + protected $progressBar; + + /** + * + * @var Zend_ProgressBar_Adapter + */ + protected $progressBarAdapter; + + /** + * The name of the parameter used for progress panel signals + * + * @var string + */ + public $progressParameterName = 'progress'; + + /** + * The value required for the progress panel to report and reset + * + * @var string + */ + public $progressParameterReportValue = 'report'; + + /** + * The value required for the progress panel to start running + * + * @var string + */ + public $progressParameterRunValue = 'run'; + + /** + * + * @param string $id A unique name identifying this batch + */ + public function __construct($id = null) { - if (null === $name) { - $name = get_class($this); + if (null === $id) { + $id = 'batchId' . (1 + count(self::$_idStack)); } + foreach (self::$_idStack as $existingId) { + if ($existingId == $id) { + throw new MUtil_Batch_BatchException("Duplicate batch id created: $id"); + } + } + self::$_idStack[] = $id; + $this->_id = $id; - $this->_initSession($name); + $this->_initSession($id); } - private function _initSession($name) + /** + * Checks parameters and returns a command array. + * + * @param string $method + * @param array $params + * @return array A command array + */ + private function _checkParams($method, array $params) { - $this->_session = new Zend_Session_Namespace($name); + if (! method_exists($this, $method)) { + throw new MUtil_Batch_BatchException("Invalid batch method: '$method'."); + } + if (! MUtil_Ra::isScalar($params)) { + throw new MUtil_Batch_BatchException("Non scalar batch parameter for method: '$method'."); + } + $command['method'] = $method; + $command['parameters'] = $params; + + return $command; + } + + /** + * Initialize persistent storage + * + * @param string $name The id of this batch + */ + private function _initSession($id) + { + $this->_session = new Zend_Session_Namespace(get_class($this) . '_' . $id); + if (! isset($this->_session->commands)) { - $this->_session->commands = array(); - $this->_session->counters = array(); - $this->_session->count = 0; - $this->_session->processed = 0; + $this->reset(); } } @@ -84,29 +196,38 @@ * Add an execution step to the command stack. * * @param string $method Name of a method of this object - * @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 MUtil_Batch_BatchAbstract */ - protected function addStep($method, $id, $param1 = null) + protected function addStep($method, $param1 = null) { - $params = array_slice(func_get_args(), 2); + $params = array_slice(func_get_args(), 1); - if (! method_exists($this, $method)) { - throw new MUtil_Batch_BatchException("Invalid batch method: '$method'."); - } - if (! MUtil_Ra::isScalar($params)) { - throw new MUtil_Batch_BatchException("Non scalar batch parameter for method: '$method'."); - } + $this->_session->commands[] = $this->_checkParams($method, $params); - $command['method'] = $method; - $command['parameters'] = $params; + return $this; + } - $this->_session->commands[$id] = $command; + /** + * Add a message to the message stack. + * + * @param string $text A message to the user + * @return MUtil_Batch_BatchAbstract (continuation pattern) + */ + protected function addMessage($text) + { + $this->_session->messages[] = $text; return $this; } + /** + * Increment a named counter + * + * @param string $name + * @param integer $add + * @return integer + */ protected function addToCounter($name, $add = 1) { if (! isset($this->session->counters[$name])) { @@ -127,14 +248,101 @@ return count($this->_session->commands); } - public function getPanel() + /** + * Returns the prefix used for the function names to avoid naming clashes. + * + * @return string + */ + public function getFunctionPrefix() { - return new MUtil_Html_ProgressPanel('0%'); + if (! $this->_functionPrefix) { + $this->setFunctionPrefix(__CLASS__ . '_' . $this->_id . '_'); + } + + return (string) $this->_functionPrefix; } + /** + * Return + * @return MUtil_Html_ProgressPanel + */ + public function getPanel(Zend_View_Abstract $view) + { + ZendX_JQuery::enableView($view); + + if ($this->isFinished()) { + $content = '100%'; + } else { + $content = '100%'; + } + + $panel = new MUtil_Html_ProgressPanel('0%'); + + $panel->id = $this->_id; + $panel->method = $this->method; + + $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/Batch' . $this->method . '.js'); + $js->setInHeader(false); + // Set the fields, in case they where not set earlier + $js->setDefault('__AUTOSTART__', $this->autoStart ? 'true' : 'false'); + $js->setDefault('{ID}', $this->_id); + $js->setDefault('{TEXT_TAG}', $panel->getDefaultChildTag()); + $js->setDefault('{TEXT_CLASS}', $panel->progressTextClass); + $js->setDefault('{URL_FINISH}', addcslashes($view->url(array($this->progressParameterName => $this->progressParameterReportValue)), "/")); + $js->setDefault('{URL_START}', addcslashes($view->url(array($this->progressParameterName => $this->progressParameterRunValue)), "/")); + $js->setDefault('FUNCTION_PREFIX_', $this->getFunctionPrefix()); + + $panel->append($js); + + return $panel; + } + + /** + * + * @return Zend_ProgressBar + */ + public function getProgressBar() + { + if (! $this->progressBar instanceof Zend_ProgressBar) { + $this->setProgressBar(new Zend_ProgressBar($this->getProgressBarAdapter(), 0, 100)); + } + return $this->progressBar; + } + + /** + * + * @return Zend_ProgressBar_Adapter + */ + public function getProgressBarAdapter() + { + if (! $this->progressBarAdapter instanceof Zend_ProgressBar_Adapter) { + if ($this->method == self::PULL) { + $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPull()); + } else { + $this->setProgressBarAdapter(new MUtil_ProgressBar_Adapter_JsPush()); + $this->progressBarAdapter->extraPaddingKb = 3; + } + } + + return $this->progressBarAdapter; + } + + public function getReport() + { + $messages = $this->_session->messages; + + return $messages; + } + + /** + * Returns true when the parameters passed mean the program has started. + * + * @param Zend_Controller_Request_Abstract $request + * @return boolean + */ public function hasStarted(Zend_Controller_Request_Abstract $request) { - return false; + return $request->getParam($this->progressParameterName) === $this->progressParameterRunValue; } /** @@ -144,7 +352,7 @@ */ public function isFinished() { - return (0 == $this->_session->count()) && ($this->_session->processed > 0); + return (0 == $this->count()) && ($this->_session->processed > 0); } /** @@ -157,6 +365,15 @@ return $this->count() || $this->_session->processed; } + public function reset() + { + $this->_session->commands = array(); + $this->_session->counters = array(); + $this->_session->count = 0; + $this->_session->messages = array(); + $this->_session->processed = 0; + } + public function runAll() { while ($this->step()); @@ -164,15 +381,117 @@ return $this->_session->processed; } + /** + * Name prefix for functions. + * + * Set automatically to __CLASS___, use different name + * in case of name clashes. + * + * @param string $prefix + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setFunctionPrefix($prefix) + { + $this->_functionPrefix = $prefix; + return $this; + } + + /** + * Add/set a message on the message stack with a specific id. + * + * @param scalar $id + * @param string $text A message to the user + * @return MUtil_Batch_BatchAbstract (continuation pattern) + */ + protected function setMessage($id, $text) + { + $this->_session->messages[$id] = $text; + + return $this; + } + + /** + * + * @param Zend_ProgressBar $progressBar + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setProgressBar(Zend_ProgressBar $progressBar) + { + $this->progressBar = $progressBar; + return $this; + } + + /** + * + * @param Zend_ProgressBar_Adapter_Interface $adapter + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setProgressBarAdapter(Zend_ProgressBar_Adapter $adapter) + { + if ($adapter instanceof Zend_ProgressBar_Adapter_JsPush) { + $prefix = $this->getFunctionPrefix(); + + // Set the fields, in case they where not set earlier + $adapter->setUpdateMethodName($prefix . 'Update'); + $adapter->setFinishMethodName($prefix . 'Finish'); + } + + $this->progressBarAdapter = $adapter; + return $this; + } + + /** + * Add an execution step to the command stack. + * + * @param string $method Name of a method of this object + * @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 MUtil_Batch_BatchAbstract + */ + protected function setStep($method, $id, $param1 = null) + { + $params = array_slice(func_get_args(), 2); + + $this->_session->commands[$id] = $this->_checkParams($method, $params); + + return $this; + } + + /** + * Returns true when the parameters passed mean the program has started. + * + * @param Zend_Controller_Request_Abstract $request + * @return boolean + */ + public function showReport(Zend_Controller_Request_Abstract $request) + { + return $request->getParam($this->progressParameterName) === $this->progressParameterReportValue; + } + + /** + * Workhorse function that does all the real work. + * + * @return int + */ public function step() { + $bar = $this->getProgressBar(); + if (isset($this->_session->commands) && $this->_session->commands) { $command = array_shift($this->_session->commands); $this->_session->processed++; call_user_func_array(array($this, $command['method']), $command['parameters']); + + $percent = round($this->_session->processed / ($this->count() + $this->_session->processed) * 100, 2); + + $bar->update($percent, end($this->_session->messages)); + return true; + } else { + $bar->finish(); + + return false; } - return count($this->_session->commands) > 0; } } Added: trunk/library/classes/MUtil/Batch/BatchPull.js =================================================================== --- trunk/library/classes/MUtil/Batch/BatchPull.js (rev 0) +++ trunk/library/classes/MUtil/Batch/BatchPull.js 2012-01-18 12:28:40 UTC (rev 410) @@ -0,0 +1,86 @@ + + +// Creating the widget +jQuery.widget("ui.pullProgressPanel", { + + // default options + options: { + autoStart: false, + // target: the element whose content is replaced + timeout: 2000 + // url: the request url + }, + + _init: function() { + if (this.options.autoStart) { + this.start(); + } + }, + + complete: function (request, status) { + this.request = null; + + // Check for changes + // - if the input field was changed since the last request + // filter() will search on the new value + // - if the input field has not changed, then no new request + // is made. + // this.start(); + }, + + error: function (request, status) { + console.log(status); + /* if (request.status === 401) { + location.href = location.href; + } // */ + }, + + start: function() { + if (this.request == null) { + if (this.options.url) { + var self = this; + this.request = jQuery.ajax({ + url: this.options.url, + type: "GET", + dataType: "json", + // data: postData, + error: function(request, status, error) {self.error(request, status);}, + complete: function(request, status) {self.complete(request, status);}, + success: function(data, status, request) {self.success(data, status, request);} + }); + + } + } + }, + + success: function (data, status, request) { + // console.log(stringdata); + // data = jQuery.parseJSON(stringdata); + console.log(data); + + text = data.percent + '%'; + if (data.text) { + text = text + data.text; + } + + jQuery(this.options.target).html(text); + }, + + request: null +}); + +jQuery(document).ready(function() { + jQuery("#{ID}").pullProgressPanel({"url":"{URL_START}","autoStart":__AUTOSTART__,"target":"#{ID} {TEXT_TAG}.{TEXT_CLASS}"}); +}); + +function FUNCTION_PREFIX_Finish() +{ + main = jQuery("#{ID}"); + main.progressbar( "option", "value", 100); + + inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); + if (inner) { + inner.empty(); + inner.append('100% Done!'); + } +} Added: trunk/library/classes/MUtil/Batch/BatchPush.js =================================================================== --- trunk/library/classes/MUtil/Batch/BatchPush.js (rev 0) +++ trunk/library/classes/MUtil/Batch/BatchPush.js 2012-01-18 12:28:40 UTC (rev 410) @@ -0,0 +1,47 @@ + +function FUNCTION_PREFIX_Start() +{ + var iFrame = document.createElement('iframe'); + iFrame.setAttribute('style', 'position: absolute; left: -100px; top: -100px; width: 10px; height: 10px; overflow: hidden;'); + // iFrame.setAttribute('style', 'position: absolute; left: 0px; top: 0px; width: 100px; height: 100px; overflow: hidden;'); + document.getElementsByTagName('body')[0].appendChild(iFrame); + iFrame.src = '{URL_START}'; +} + +function FUNCTION_PREFIX_Update(data) +{ + main = jQuery("#{ID}"); + main.progressbar( "option", "value", data.percent); + main.progressbar({value: data.percent}); + + inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); + if (inner) { + text = data.percent + '%'; + if (data.text) { + text = text + ' ' + data.text; + } + inner.html(text); + } +} + +function FUNCTION_PREFIX_Finish() +{ + main = jQuery("#{ID}"); + main.progressbar( "option", "value", 100); + + inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); + if (inner) { + inner.empty(); + inner.append('100% Done!'); + } + + url = '{URL_FINISH}'; + if (url.length > 0) { + location.href = url; + } +} + + +if (__AUTOSTART__) { + jQuery().ready(FUNCTION_PREFIX_Start()); +} \ No newline at end of file Added: trunk/library/classes/MUtil/Batch/WaitBatch.php =================================================================== --- trunk/library/classes/MUtil/Batch/WaitBatch.php (rev 0) +++ trunk/library/classes/MUtil/Batch/WaitBatch.php 2012-01-18 12:28:40 UTC (rev 410) @@ -0,0 +1,82 @@ +<?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 Batch + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 203 2012-07-07 12:51:32Z matijs $ + */ + +/** + * + * + * @package MUtil + * @subpackage Batch + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class MUtil_Batch_WaitBatch extends MUtil_Batch_BatchAbstract +{ + public function addWait($seconds = 1) + { + $this->addStep('waitFor', $seconds); + + return $this; + } + + public function addWaits($times, $seconds = 1) + { + for ($i = 0; $i < $times; $i++) { + $this->addStep('waitFor', $seconds); + } + + return $this; + } + + public function addWaitsLater($times, $seconds = 1) + { + $this->addStep('addWaits', $times, $seconds); + + return $this; + } + + public function waitFor($seconds) + { + sleep($seconds); + + if ($seconds == 1) { + $this->addMessage("Waited for 1 second."); + } else { + $this->addMessage(sprintf("Waited for %d seconds.", $seconds)); + } + } +} Modified: trunk/library/classes/MUtil/Html/ProgressPanel.php =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.php 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/MUtil/Html/ProgressPanel.php 2012-01-18 12:28:40 UTC (rev 410) @@ -46,8 +46,6 @@ */ class MUtil_Html_ProgressPanel extends MUtil_Html_HtmlElement { - const CODE = "MUtil_Html_ProgressPanel_Code"; - /** * For some elements (e.g. table and tbody) the logical thing to do when content * is added that does not have an $_allowedChildTags is to add that content to @@ -83,13 +81,6 @@ ); /** - * When true the progressbar should start immediately. When false the user has to perform an action. - * - * @var boolean - */ - protected $_autoStart = true; - - /** * When content must contain certain element types only the default child tag contains * the tagname of the element that is created to contain the content. * @@ -104,13 +95,6 @@ protected $_defaultChildTag = 'div'; /** - * Name to prefix the functions, to avoid naming clashes. - * - * @var string Default is the classname with an extra underscore - */ - protected $_functionPrefix; - - /** * Usually no text is appended before an element, but for certain elements we choose * to add a "\n" newline character instead, to keep the output readable in source * view. @@ -120,54 +104,6 @@ protected $_prependString = "\n"; /** - * - * @var Zend_ProgressBar - */ - protected $_progressBar; - - /** - * - * @var Zend_ProgressBar_Adapter - */ - protected $_progressBarAdapter; - - /** - * Extra array with special types for subclasses. - * - * When an object of one of the key types is used, then use - * the class method defined as the value. - * - * @see $_specialTypesDefault - * - * @var array Of 'class or interfacename' => 'class method' of null - */ - protected $_specialTypes = array( - 'Zend_ProgressBar' => 'setProgressBar', - 'Zend_ProgressBar_Adapter' => 'setProgressBarAdapter', - ); - - /** - * The mode to use for the panel: push or pull - * - * @var string - */ - public $method = 'Pull'; - - /** - * The name of the parameter used for progress panel signals - * - * @var string - */ - public $progressParameterName = 'progress'; - - /** - * The value required for the progress panel to start running - * - * @var string - */ - public $progressParameterRunValue = 'run'; - - /** * Class name of inner element that displays text * * @var string @@ -187,82 +123,20 @@ } /** - * Update the progess panel + * Returns the tag name for the default child. * - * @return MUtil_Html_ProgressPanel (continuation pattern) - */ - public function finish() - { - $bar = $this->getProgressBar(); - $bar->finish(); - - return $this; - } - /** - * Returns the JavaScript object associated with this object. + * Exposed as needed by some classes using this class. * - * WARNING: calling this object sets it's position in the order the - * objects are rendered. If you use MUtil_Lazy objects, make sure they - * have the correct value when rendering. + * @see MUtil_Batch_BatchAbstract * - * @return MUtil_Html_Code_JavaScript - */ - public function getCode() - { - if (! isset($this->_content[self::CODE])) { - $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanel' . $this->method . '.js'); - $js->setInHeader(false); - - $this->_content[self::CODE] = $js; - } - - return $this->_content[self::CODE]; - } - - /** - * Returns the prefix used for the function names to avoid naming clashes. - * * @return string */ - public function getFunctionPrefix() + public function getDefaultChildTag() { - if (! $this->_functionPrefix) { - $this->setFunctionPrefix(__CLASS__ . '_' . $this->getAttrib('id'). '_'); - } - - return (string) $this->_functionPrefix; + return $this->_defaultChildTag; } /** - * - * @return Zend_ProgressBar - */ - public function getProgressBar() - { - if (! $this->_progressBar instanceof Zend_ProgressBar) { - $this->setProgressBar(new Zend_ProgressBar($this->getProgressBarAdapter(), 0, 100)); - } - return $this->_progressBar; - } - - /** - * - * @return Zend_ProgressBar_Adapter - */ - public function getProgressBarAdapter() - { - if (! $this->_progressBarAdapter instanceof Zend_ProgressBar_Adapter) { - if ($this->method == 'Pull') { - $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPull()); - } else { - $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPush()); - } - } - - return $this->_progressBarAdapter; - } - - /** * Creates a 'div' progress panel * * @param mixed $arg_array A MUtil_Ra::args data collection. @@ -275,7 +149,7 @@ } /** - * Function to allow overloading of tag rendering only + * Function to allow overloading of tag rendering only * * Renders the element tag with it's content into a html string * @@ -286,19 +160,6 @@ */ protected function renderElement(Zend_View_Abstract $view) { - ZendX_JQuery::enableView($view); - - if ($this->getProgressBarAdapter() instanceof Zend_ProgressBar_Adapter) { - $js = $this->getCode(); - - // Set the fields, in case they where not set earlier - $js->setDefault('__AUTOSTART__', $this->_autoStart ? 'true' : 'false'); - $js->setDefault('{ID}', $this->getAttrib('id')); - $js->setDefault('{TEXT_TAG}', $this->_defaultChildTag); - $js->setDefault('{TEXT_CLASS}', $this->progressTextClass); - $js->setDefault('{URL}', addcslashes($view->url(array($this->progressParameterName => $this->progressParameterRunValue)), "/")); - } - if ($this->_lastChild) { $this->_lastChild->class = $this->progressTextClass; @@ -316,77 +177,4 @@ return parent::renderElement($view); } - - /** - * Checks whether the progress panel should be running - * - * @param Zend_Controller_Request_Abstract $request - * @return boolean - */ - public function run(Zend_Controller_Request_Abstract $request) - { - return $request->getParam($this->progressParameterName) === $this->progressParameterRunValue; - } - - /** - * Name prefix for functions. - * - * Set automatically to __CLASS___, use different name - * in case of name clashes. - * - * @param string $prefix - * @return MUtil_Html_ProgressPanel (continuation pattern) - */ - public function setFunctionPrefix($prefix) - { - $this->_functionPrefix = $prefix; - return $this; - } - - /** - * - * @param Zend_ProgressBar $progressBar - * @return MUtil_Html_ProgressPanel (continuation pattern) - */ - public function setProgressBar(Zend_ProgressBar $progressBar) - { - $this->_progressBar = $progressBar; - return $this; - } - - /** - * - * @param Zend_ProgressBar_Adapter_Interface $adapter - * @return MUtil_Html_ProgressPanel (continuation pattern) - */ - public function setProgressBarAdapter(Zend_ProgressBar_Adapter $adapter) - { - if ($adapter instanceof Zend_ProgressBar_Adapter_JsPush) { - $js = $this->getCode(); - $prefix = $this->getFunctionPrefix(); - - // Set the fields, in case they where not set earlier - $js->setDefault('FUNCTION_PREFIX_', $prefix); - $adapter->setUpdateMethodName($prefix . 'Update'); - $adapter->setFinishMethodName($prefix . 'Finish'); - } - - $this->_progressBarAdapter = $adapter; - return $this; - } - - /** - * Update the progess panel - * - * @param int $value - * @param string $text - * @return MUtil_Html_ProgressPanel (continuation pattern) - */ - public function update($value, $text = null) - { - $bar = $this->getProgressBar(); - $bar->update($value, $text); - - return $this; - } } Deleted: trunk/library/classes/MUtil/Html/ProgressPanelPull.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanelPull.js 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/MUtil/Html/ProgressPanelPull.js 2012-01-18 12:28:40 UTC (rev 410) @@ -1,86 +0,0 @@ - - -// Creating the widget -jQuery.widget("ui.pullProgressPanel", { - - // default options - options: { - autoStart: false, - // target: the element whose content is replaced - timeout: 2000 - // url: the request url - }, - - _init: function() { - if (this.options.autoStart) { - this.start(); - } - }, - - complete: function (request, status) { - this.request = null; - - // Check for changes - // - if the input field was changed since the last request - // filter() will search on the new value - // - if the input field has not changed, then no new request - // is made. - // this.start(); - }, - - error: function (request, status) { - console.log(status); - /* if (request.status === 401) { - location.href = location.href; - } // */ - }, - - start: function() { - if (this.request == null) { - if (this.options.url) { - var self = this; - this.request = jQuery.ajax({ - url: this.options.url, - type: "GET", - dataType: "json", - // data: postData, - error: function(request, status, error) {self.error(request, status);}, - complete: function(request, status) {self.complete(request, status);}, - success: function(data, status, request) {self.success(data, status, request);} - }); - - } - } - }, - - success: function (data, status, request) { - // console.log(stringdata); - // data = jQuery.parseJSON(stringdata); - console.log(data); - - text = data.percent + '%'; - if (data.text) { - text = text + data.text; - } - - jQuery(this.options.target).html(text); - }, - - request: null -}); - -jQuery(document).ready(function() { - jQuery("#{ID}").pullProgressPanel({"url":"{URL}","autoStart":__AUTOSTART__,"target":"#{ID} {TEXT_TAG}.{TEXT_CLASS}"}); -}); - -function FUNCTION_PREFIX_Finish() -{ - main = jQuery("#{ID}"); - main.progressbar( "option", "value", 100); - - inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); - if (inner) { - inner.empty(); - inner.append('100% Done!'); - } -} Deleted: trunk/library/classes/MUtil/Html/ProgressPanelPush.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanelPush.js 2012-01-17 21:08:06 UTC (rev 409) +++ trunk/library/classes/MUtil/Html/ProgressPanelPush.js 2012-01-18 12:28:40 UTC (rev 410) @@ -1,46 +0,0 @@ - -function FUNCTION_PREFIX_Start() -{ - var iFrame = document.createElement('iframe'); - iFrame.setAttribute('style', 'position: absolute; left: -100px; top: -100px; width: 10px; height: 10px; overflow: hidden;'); - // iFrame.setAttribute('style', 'position: absolute; left: 0px; top: 0px; width: 100px; height: 100px; overflow: hidden;'); - document.getElementsByTagName('body')[0].appendChild(iFrame); - iFrame.src = '{URL}'; -} - -function FUNCTION_PREFIX_Update(data) -{ - main = jQuery("#{ID}"); - main.progressbar( "option", "value", data.percent); - main.progressbar({ - value: data.percent - }); - - inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); - if (inner) { - text = data.percent + '%'; - if (data.text) { - text = text + data.text; - } - inner.html(text); - } -} - -function FUNCTION_PREFIX_Finish() -{ - main = jQuery("#{ID}"); - main.progressbar( "option", "value", 100); - - inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); - if (inner) { - inner.empty(); - inner.append('100% Done!'); - } -} - - -if (__AUTOSTART__) { - // jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: 'Hi'})); - // jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: ''})); - jQuery().ready(FUNCTION_PREFIX_Start()); -} \ No newline at end of file Property changes on: trunk/library/classes/MUtil/ProgressBar ___________________________________________________________________ Added: bugtraq:url + http://survey.erasmusmc.nl/support/mantis/view.php?id=%BUGID% Added: bugtraq:logregex + #(\d+) Property changes on: trunk/library/classes/MUtil/ProgressBar/Adapter ___________________________________________________________________ Added: bugtraq:url + http://survey.erasmusmc.nl/support/mantis/view.php?id=%BUGID% Added: bugtraq:logregex + #(\d+) Added: trunk/library/classes/MUtil/ProgressBar/Adapter/JsPush.php =================================================================== --- trunk/library/classes/MUtil/ProgressBar/Adapter/JsPush.php (rev 0) +++ trunk/library/classes/MUtil/ProgressBar/Adapter/JsPush.php 2012-01-18 12:28:40 UTC (rev 410) @@ -0,0 +1,75 @@ +<?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 MUtil + * @subpackage ProgressBar + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $Id: JsPush.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * + * + * @package MUtil + * @subpackage ProgressBar + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class MUtil_ProgressBar_Adapter_JsPush extends Zend_ProgressBar_Adapter_JsPush +{ + /** + * The number of bytes to padd in Kilobytes + * + * This is needed as many servers need extra output passing to avoid buffering. + * + * Also this allows you to keep the server buffer high while using this JsPush. + * + * @var int + */ + public $extraPaddingKb = 0; + + /** + * Outputs given data the user agent. + * + * This split-off is required for unit-testing. + * + * @param string $data + * @return void + */ + protected function _outputData($data) + { + if ($this->extraPaddingKb) { + $data .= str_repeat(' ', 1024 * $this->extraPaddingKb); + } + return parent::_outputData($data); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-02-15 18:25:47
|
Revision: 488 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=488&view=rev Author: matijsdejong Date: 2012-02-15 18:25:37 +0000 (Wed, 15 Feb 2012) Log Message: ----------- Starting on source synchronization by batch (does not yet work) Modified Paths: -------------- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php trunk/library/classes/Gems/Tracker/Source/SourceInterface.php trunk/library/classes/MUtil/Batch/BatchAbstract.php Added Paths: ----------- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php Removed Paths: ------------- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourceBatch.php Deleted: trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourceBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourceBatch.php 2012-02-15 16:24:48 UTC (rev 487) +++ trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourceBatch.php 2012-02-15 18:25:37 UTC (rev 488) @@ -1,61 +0,0 @@ -<?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 Gems - * @subpackage Tracker - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $Id$ - */ - -/** - * - * - * @package Gems - * @subpackage Tracker - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.5 - */ -class Gems_Tracker_Batch_SynchronizeSourceBatch extends MUtil_Batch_BatchAbstract -{ - /** - * Construct as standard batch - */ - public function __construct() - { - parent::__construct(__CLASS__); - } - - public function addSource($sourceId, $sourceName) - { - - } -} Added: trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php (rev 0) +++ trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-15 18:25:37 UTC (rev 488) @@ -0,0 +1,106 @@ +<?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 Gems + * @subpackage Tracker + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Tracker_Batch_SynchronizesSourceBatch extends MUtil_Batch_BatchAbstract +{ + /** + * + * @var Gems_Tracker_Source_SourceInterface + */ + private $_currentSource; + + /** + * + * @var Gems_Tracker + */ + protected $tracker; + + /** + * + * @param mixed $sourceData Source Id or array containing source data + */ + public function addSource($sourceData, $userId, $updateTokens = true) + { + $this->_currentSource = $this->tracker->getSource($sourceData); + $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $updateTokens); + $this->_currentSource = null; + } + + /** + * + * @param mixed $sourceData Source Id or array containing source data + */ + public function addSourceFunction($function, $param_args = null) + { + if (null === $this->_currentSource) { + throw new Gems_Exception_Coding('Trying to add a Source Function without a current source.'); + } + + $params = array_slice(func_get_args(), 1); + + $this->addStep('sourceStep', $this->_currentSource->getId(), $function, $params); + } + + /** + * The basic steps + * + * @param int $sourceId + * @param string $function + * @param array $params + */ + protected function sourceStep($sourceId, $function, array $params) + { + $source = $this->tracker->getSource($sourceData); + + $messages = call_user_func_array(array($source, $function), $params); + + if ($messages) { + foreach ((array) $messages as $message) { + $this->addMessage($message); + } + } + } +} Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-15 16:24:48 UTC (rev 487) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-15 18:25:37 UTC (rev 488) @@ -296,6 +296,39 @@ } /** + * Add the commands to update this source to a source synchornization batch + * + * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param int $userId Id of the user who takes the action (for logging) + * @param bool $updateTokens Wether the tokens should be updated or not, default is true + * / + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + { + // Surveys in LS + $lsDb = $this->getSourceDatabase(); + $select = $lsDb->select(); + $select->from($this->_getSurveysTableName(), 'sid') + ->order('sid'); + $lsSurveys = $lsDb->fetchCol($select); + $lsSurveys = array_combine($lsSurveys, $lsSurveys); + + // Surveys in Gems + $gemsSurveys = $this->_getGemsSurveysForSynchronisation(); + + foreach ($gemsSurveys as $surveyId => $sourceSurveyId) { + if (isset($lsSurveys[$sourceSurveyId])) { + $batch->addSourceFunction('checkSurvey', $sourceSurveyId, $surveyId, $userId, $updateTokens); + } else { + $batch->addSourceFunction('checkSurvey', null, $surveyId, $userId, $updateTokens); + } + } + + foreach (array_diff($lsSurveys, $gemsSurveys) as $sourceSurveyId) { + $batch->addSourceFunction('checkSurvey', $sourceSurveyId, null, $userId, $updateTokens); + } + } + + /** * Check if the tableprefix exists in the source database, and change the status of this * adapter in the gems_sources table accordingly * @@ -322,6 +355,165 @@ } /** + * Internal function used for source synchronization + * + * @param int $sourceSurveyId + * @param int $surveyId + * @param int $userId + * @param boolean $updateTokens + */ + public function checkSurvey($sourceSurveyId, $surveyId, $userId, $updateTokens) + { + $messages = array(); + $survey = $this->tracker->getSurveyBySourceId($surveyId, $sourceSurveyId); + + if (null === $sourceSurveyId) { + // Was removed + $values['gsu_active'] = 0; + $values['gsu_surveyor_active'] = 0; + $values['gsu_status'] = 'Survey was removed from source.'; + + if ($survey->saveSurvey($values, $userId)) { + $messages[] = sprintf($this->translate->_('The \'%s\' survey is no longer active. The survey was removed from LimeSurvey!'), $survey->getName()); + } + } else { + $lsDb = $this->getSourceDatabase(); + + // SELECT sid, surveyls_title AS short_title, surveyls_description AS description, active, datestamp, ' . $this->_anonymizedField . ' + $select = $lsDb->select(); + $select->from($this->_getSurveysTableName(), array('active', 'datestamp', $this->_anonymizedField)) + ->joinInner( + $this->_getSurveyLanguagesTableName(), + 'sid = surveyls_survey_id AND language = surveyls_language', + array('surveyls_title', 'surveyls_description')) + ->where('sid = ?', $sourceSurveyId); + $lsSurvey = $lsDb->fetchRow($select); + + $surveyor_title = substr($lsSurvey['surveyls_title'], 0, 100); + $surveyor_status = ''; + + // ANONIMIZATION + switch ($lsSurvey[$this->_anonymizedField]) { + case 'Y': + $surveyor_status .= 'Uses anonymous answers. '; + break; + case 'N': + break; + default: + // This is for the case that $this->_anonymizedField is empty, we show an update statement. + // The answers already in the table can only be linked to the repsonse based on the completion time + // this requires a manual action as token table only hold minuts while survey table holds seconds + // and we might have responses with the same timestamp. + $lsDb->query("UPDATE " . $this->_getSurveysTableName() . " SET `" . $this->_anonymizedField . "` = 'N' WHERE sid = ?;", $sourceSurveyId); + $messages[] = sprintf($this->translate->_("Corrected anonymization for survey '%s'"), $surveyor_title); + + $lsDb->query("ALTER TABLE " . $this->_getSurveyTableName($sourceSurveyId) . " ADD `token` varchar(36) default NULL;"); + } + + // DATESTAMP + if ($lsSurvey['datestamp'] == 'N') { + $surveyor_status .= 'Not date stamped. '; + } + + // IS ACTIVE + if ($lsSurvey['active'] == 'Y') { + $surveyor_active = true; + try { + $tokenTable = $lsDb->fetchAssoc('SHOW COLUMNS FROM ' . $this->_getTokenTableName($sourceSurveyId)); + } catch (Zend_Exception $e) { + $tokenTable = false; + } + + if ($tokenTable) { + $lengths = array(); + if (preg_match('/\(([^\)]+)\)/', $tokenTable['token']['Type'], $lengths)) { + $tokenLength = $lengths[1]; + } else { + $tokenLength = 0; + } + if ($tokenLength < $token_library->getLength()) { + $surveyor_status .= 'Token field length is too short. '; + } + + $missingFields = array(); + foreach ($this->_attributeMap as $name => $field) { + if (! isset($tokenTable[$field])) { + $missingFields[$field] = "ADD $field varchar(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'"; + } + } + if ($missingFields) { + $sql = "ALTER TABLE " . $this->_getTokenTableName($sid) . " " . implode(', ', $missingFields); + try { + $lsDb->query($sql); + $messages[] = sprintf($this->translate->_("Added attribute fields to token table for '%s'"), $surveyor_title); + } catch (Zend_Exception $e) { + $surveyor_status .= 'Token attributes could not be created. '; + $surveyor_status .= $e->getMessage() . ' '; + + $messages[] = sprintf($this->translate->_("Attribute fields not created for token table for '%s'"), $surveyor_title); + $messages[] = sprintf($this->translate->_('Required fields: %s', implode($this->_(', '), array_keys($missingFields)))); + $messages[] = $e->getMessage(); + + // Maximum reporting for this case + MUtil_Echo::r($missingFields, 'Missing fields for ' . $surveyor_title); + MUtil_Echo::r($e); + } + } + } else { + $surveyor_status .= 'No token table created. '; + } + + + } else { + $surveyor_active = false; + $surveyor_status .= 'Not active. '; + } + + // Update Gems + $values = array(); + + if ($survey->exists) { // Update + if ($survey->isActiveInSource() != $surveyor_active) { + $values['gsu_surveyor_active'] = $surveyor_active ? 1 : 0; + + $messages[] = sprintf($this->translate->_('The status of the \'%s\' survey has changed.'), $survey->getName()); + } + + // Reset to inactive if the surveyor survey has become inactive. + if ($survey->isActive() && $surveyor_status) { + $values['gsu_active'] = 0; + $messages[] = sprintf($this->translate->_('Survey \'%s\' IS NO LONGER ACTIVE!!!'), $survey->getName()); + } + + if (substr($surveyor_status, 0, 127) != (string) $survey->getStatus()) { + if ($surveyor_status) { + $values['gsu_status'] = substr($surveyor_status, 0, 127); + $messages[] = sprintf($this->translate->_('The status of the \'%s\' survey has changed to \'%s\'.'), $survey->getName(), $values['gsu_status']); + } else { + $values['gsu_status'] = 'OK'; + $messages[] = sprintf($this->translate->_('The status warning for the \'%s\' survey was removed.'), $survey->getName()); + } + } + + if ($survey->getName() != $surveyor_title) { + $values['gsu_survey_name'] = $surveyor_title; + $messages[] = sprintf($this->translate->_('The name of the \'%s\' survey has changed to \'%s\'.'), $survey->getName(), $surveyor_title); + } + + } else { // New record + $values['gsu_survey_name'] = $surveyor_title; + $values['gsu_surveyor_active'] = $surveyor_active ? 1 : 0; + $values['gsu_active'] = 0; + $values['gsu_status'] = $surveyor_status; + + $messages[] = sprintf($this->translate->_('Imported the \'%s\' survey.'), $surveyor_title); + } + $values['gsu_survey_description'] = strtr(substr($surveyor_survey['description'], 0, 100), "\xA0\xC2", ' '); + $survey->saveSurvey($values, $userId); + } + } + + /** * Inserts the token in the source (if needed) and sets those attributes the source wants to set. * * @param Gems_Tracker_Token $token Modified: trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-15 16:24:48 UTC (rev 487) +++ trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-15 18:25:37 UTC (rev 488) @@ -87,6 +87,21 @@ } /** + * Returns all surveys for synchronization + * + * @return array Pairs if + */ + protected function _getGemsSurveysForSynchronisation() + { + $select = $this->_gemsDb->select(); + $select->from('gems__surveys', array('gsu_id_survey', 'gsu_surveyor_id')) + ->where('gsu_id_source = ', $this->getId()) + ->order('gsu_surveyor_id'); + + return $this->_gemsDb->fetchPairs($select); + } + + /** * Creates a where filter statement for tokens that do not * have a correct name and are in a tokens table * @@ -208,7 +223,19 @@ } /** + * Add the commands to update this source to a source synchornization batch * + * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param int $userId Id of the user who takes the action (for logging) + * @param bool $updateTokens Wether the tokens should be updated or not, default is true + */ + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + { + // Do nothing is default + } + + /** + * * @return string Base url for source */ protected function getBaseUrl() Modified: trunk/library/classes/Gems/Tracker/Source/SourceInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-15 16:24:48 UTC (rev 487) +++ trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-15 18:25:37 UTC (rev 488) @@ -55,6 +55,15 @@ public function __construct(array $sourceData, Zend_Db_Adapter_Abstract $gemsDb); /** + * Add the commands to update this source to a source synchornization batch + * + * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param int $userId Id of the user who takes the action (for logging) + * @param bool $updateTokens Wether the tokens should be updated or not, default is true + */ + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true); + + /** * Inserts the token in the source (if needed) and sets those attributes the source wants to set. * * @param Gems_Tracker_Token $token Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-15 16:24:48 UTC (rev 487) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-15 18:25:37 UTC (rev 488) @@ -754,7 +754,13 @@ $command = array_shift($this->_session->commands); $this->_session->processed++; - call_user_func_array(array($this, $command['method']), $command['parameters']); + try { + call_user_func_array(array($this, $command['method']), $command['parameters']); + } catch (Exception $e) { + $this->addMessage('ERROR!!!'); + $this->addMessage('While calling:' . $command['method'] . '(', implode(',', MUtil_Ra::flatten($command['parameters'])), ')'); + $this->addMessage($e->getMessage()); + } return true; } else { return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-02-16 13:45:34
|
Revision: 495 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=495&view=rev Author: matijsdejong Date: 2012-02-16 13:45:27 +0000 (Thu, 16 Feb 2012) Log Message: ----------- Added improved error reporting to BatchAbstract.php Restarting after failure shows correct starting percentage. (Though bar display still inadequate.) Source synchronization works, but does not yet the update tokens attributes. Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php trunk/library/classes/Gems/Tracker/Source/SourceInterface.php trunk/library/classes/Gems/Tracker/Survey.php trunk/library/classes/Gems/Tracker/TrackerInterface.php trunk/library/classes/Gems/Tracker.php trunk/library/classes/MUtil/Batch/BatchAbstract.php trunk/library/classes/MUtil/Batch/BatchPull.js Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 13:45:27 UTC (rev 495) @@ -102,6 +102,9 @@ $bridge->addExhibitor('gso_last_synch'); } + /** + * Check all the tokens for a single source + */ public function checkAction() { $sourceId = $this->getSourceId(); @@ -114,7 +117,7 @@ } else { $this->html->h3( sprintf($this->_('Checking survey results for %s source.'), - $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); + $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); if ($batch->isFinished()) { $this->addMessage($batch->getMessages(true)); @@ -122,8 +125,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $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.')); } @@ -131,6 +134,9 @@ } } + /** + * Check all the tokens for all sources + */ public function checkAllAction() { $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId()); @@ -146,8 +152,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $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.')); } @@ -240,8 +246,36 @@ $this->afterSaveRoute($this->getRequest()); } + /** + * Synchronize survey status for the surveys in a source + */ public function synchronizeAction() { + $sourceId = $this->getSourceId(); + + $batch = $this->loader->getTracker()->synchronizeSourcesBatch($sourceId, $this->loader->getCurrentUser()->getUserId(), false); + + if ($batch->run($this->getRequest())) { + exit; + } else { + $this->html->h3( + sprintf($this->_('Synchronize the %s source.'), + $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); + + 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 surveys'), $batch->getSurveyCounter()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); + } else { + $this->html->pInfo($this->_('No surveys to check.')); + } + } + } + /* $source = $this->getSourceById(); if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { @@ -251,6 +285,7 @@ } $this->afterSaveRoute($this->getRequest()); + // */ } public function synchronizeAllAction() Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 13:45:27 UTC (rev 495) @@ -263,6 +263,9 @@ return true; } + /** + * Check the tokens for a single survey + */ public function checkAction() { $surveyId = $this->_getParam(MUtil_Model::REQUEST_ID); @@ -283,8 +286,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $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.')); } @@ -292,6 +295,9 @@ } } + /** + * Check the tokens for all surveys + */ public function checkAllAction() { $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId()); @@ -307,8 +313,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $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.')); } Modified: trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-02-16 13:45:27 UTC (rev 495) @@ -63,6 +63,13 @@ */ public $minimalStepDurationMs = 3000; + /** + * Add the check of a single token to the batch. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + * @return Gems_Tracker_Batch_ProcessTokensBatch (Continuation pattern) + */ public function addToken($tokenData, $userId) { if (is_array($tokenData)) { @@ -75,11 +82,18 @@ } // MUtil_Echo::track($tokenData); - $this->setStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenData, $userId); + $this->setStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenId, $userId); + $this->addToCounter('tokens'); return $this; } + /** + * Check a single track for the effects of token completion. + * + * @param mixed $respTrackData Data array or a respondent track id + * @param int $userId Gems user id + */ protected function checkTrackTokens($respTrackData, $userId) { $respTrack = $this->tracker->getRespondentTrack($respTrackData); @@ -90,6 +104,18 @@ } } + /** + * Check for token completion and adds the processTokenCompletion + * command when the token is indeed completed. + * + * NOTE: The reasons to add the extra commands in this process are + * (1) that we are not sure in advance for which tokens we should + * process and (2) the processing commands should be executed + * AFTER all tokens have been checked for completion. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + */ protected function checkTokenCompletion($tokenData, $userId) { $this->addToCounter('checkedTokens'); @@ -109,6 +135,11 @@ } } + /** + * Returns a description of what was changed during this batch. + * + * @return array Of message strings + */ public function getCounterMessages() { if ($this->getCounter('checkedRespondentTracks')) { @@ -161,6 +192,21 @@ return array_merge($this->getCounterMessages(), parent::getMessages($reset)); } + /** + * The number of tokens to check + * + * @return int + */ + public function getTokenCount() + { + return $this->getCounter('tokens'); + } + + /** + * True when the batch changed anything. + * + * @return boolean + */ public function hasChanged() { return $this->getCounter('resultDataChanges') || @@ -171,6 +217,18 @@ $this->getCounter('createdTokens'); } + /** + * Processes token completion and adds the checkTrackTokens + * command when the token is indeed completed. + * + * NOTE: The reasons we add the checkTrackTokens command are + * that (1) we do not know in advance which tracks to check + * and (2) the tracks should be checked AFTER all tokens have + * been processed. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + */ protected function processTokenCompletion($tokenData, $userId) { $token = $this->tracker->getToken($tokenData); Modified: trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 13:45:27 UTC (rev 495) @@ -44,7 +44,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Tracker_Batch_SynchronizesSourceBatch extends MUtil_Batch_BatchAbstract +class Gems_Tracker_Batch_SynchronizeSourcesBatch extends MUtil_Batch_BatchAbstract { /** * @@ -60,12 +60,19 @@ /** * + * @var Zend_Translate + */ + protected $translate; + + /** + * * @param mixed $sourceData Source Id or array containing source data + * @param int $userId Gems user id */ - public function addSource($sourceData, $userId, $updateTokens = true) + public function addSource($sourceData, $userId) { $this->_currentSource = $this->tracker->getSource($sourceData); - $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $updateTokens); + $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $this->getTokenUpdate()); $this->_currentSource = null; } @@ -85,6 +92,67 @@ } /** + * Add one to the number of surveys checked + * + * @param int $add + * @return int + */ + public function addToSurveyCounter($add = 1) + { + return $this->addToCounter('surveys', $add); + } + + /** + * String of messages from the batch + * + * Do not forget to reset() the batch if you're done with it after + * displaying the report. + * + * @param boolean $reset When true the batch is reset afterwards + * @return array + */ + public function getMessages($reset = false) + { + $scounter = $this->getSurveyCounter(); + + $messages = parent::getMessages($reset); + + if (! $messages) { + $messages[] = $this->translate->_('No surveys were changed.'); + } + array_unshift($messages, sprintf($this->translate->_('%d surveys checked.'), $scounter)); + + return $messages; + } + /** + * Get the number of surveys checked + * + * @return int + */ + public function getSurveyCounter() + { + return $this->getCounter('surveys'); + } + + /** + * Is tokenUpdate on or off. + * + * @return boolean + */ + public function getTokenUpdate() + { + return $this->getVar('tokenUpdate'); + } + + /** + * Set tokenUpdate on or off. + */ + public function setTokenUpdate($value = true) + { + $this->setVar('tokenUpdate', $value); + } + + /** * The basic steps * * @param int $sourceId @@ -93,7 +161,7 @@ */ protected function sourceStep($sourceId, $function, array $params) { - $source = $this->tracker->getSource($sourceData); + $source = $this->tracker->getSource($sourceId); $messages = call_user_func_array(array($source, $function), $params); Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 13:45:27 UTC (rev 495) @@ -298,11 +298,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) * @param bool $updateTokens Wether the tokens should be updated or not, default is true - * / - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + */ + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) { // Surveys in LS $lsDb = $this->getSourceDatabase(); @@ -321,10 +321,12 @@ } else { $batch->addSourceFunction('checkSurvey', null, $surveyId, $userId, $updateTokens); } + $batch->addToSurveyCounter(); } foreach (array_diff($lsSurveys, $gemsSurveys) as $sourceSurveyId) { $batch->addSourceFunction('checkSurvey', $sourceSurveyId, null, $userId, $updateTokens); + $batch->addToSurveyCounter(); } } @@ -365,7 +367,7 @@ public function checkSurvey($sourceSurveyId, $surveyId, $userId, $updateTokens) { $messages = array(); - $survey = $this->tracker->getSurveyBySourceId($surveyId, $sourceSurveyId); + $survey = $this->tracker->getSurvey($surveyId); if (null === $sourceSurveyId) { // Was removed @@ -431,6 +433,7 @@ } else { $tokenLength = 0; } + $token_library = $this->tracker->getTokenLibrary(); if ($tokenLength < $token_library->getLength()) { $surveyor_status .= 'Token field length is too short. '; } @@ -442,7 +445,7 @@ } } if ($missingFields) { - $sql = "ALTER TABLE " . $this->_getTokenTableName($sid) . " " . implode(', ', $missingFields); + $sql = "ALTER TABLE " . $this->_getTokenTableName($sourceSurveyId) . " " . implode(', ', $missingFields); try { $lsDb->query($sql); $messages[] = sprintf($this->translate->_("Added attribute fields to token table for '%s'"), $surveyor_title); @@ -451,7 +454,7 @@ $surveyor_status .= $e->getMessage() . ' '; $messages[] = sprintf($this->translate->_("Attribute fields not created for token table for '%s'"), $surveyor_title); - $messages[] = sprintf($this->translate->_('Required fields: %s', implode($this->_(', '), array_keys($missingFields)))); + $messages[] = sprintf($this->translate->_('Required fields: %s', implode($this->translate->_(', '), array_keys($missingFields)))); $messages[] = $e->getMessage(); // Maximum reporting for this case @@ -489,7 +492,7 @@ if ($surveyor_status) { $values['gsu_status'] = substr($surveyor_status, 0, 127); $messages[] = sprintf($this->translate->_('The status of the \'%s\' survey has changed to \'%s\'.'), $survey->getName(), $values['gsu_status']); - } else { + } elseif ($survey->getStatus() != 'OK') { $values['gsu_status'] = 'OK'; $messages[] = sprintf($this->translate->_('The status warning for the \'%s\' survey was removed.'), $survey->getName()); } @@ -508,9 +511,11 @@ $messages[] = sprintf($this->translate->_('Imported the \'%s\' survey.'), $surveyor_title); } - $values['gsu_survey_description'] = strtr(substr($surveyor_survey['description'], 0, 100), "\xA0\xC2", ' '); + $values['gsu_survey_description'] = strtr(substr($lsSurvey['surveyls_description'], 0, 100), "\xA0\xC2", ' '); $survey->saveSurvey($values, $userId); } + + return $messages; } /** Modified: trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 13:45:27 UTC (rev 495) @@ -95,7 +95,7 @@ { $select = $this->_gemsDb->select(); $select->from('gems__surveys', array('gsu_id_survey', 'gsu_surveyor_id')) - ->where('gsu_id_source = ', $this->getId()) + ->where('gsu_id_source = ?', $this->getId()) ->order('gsu_surveyor_id'); return $this->_gemsDb->fetchPairs($select); @@ -225,11 +225,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) * @param bool $updateTokens Wether the tokens should be updated or not, default is true */ - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) { // Do nothing is default } Modified: trunk/library/classes/Gems/Tracker/Source/SourceInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 13:45:27 UTC (rev 495) @@ -57,11 +57,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) * @param bool $updateTokens Wether the tokens should be updated or not, default is true */ - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizesSourceBatch $batch, $userId, $updateTokens = true); + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true); /** * Inserts the token in the source (if needed) and sets those attributes the source wants to set. Modified: trunk/library/classes/Gems/Tracker/Survey.php =================================================================== --- trunk/library/classes/Gems/Tracker/Survey.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Survey.php 2012-02-16 13:45:27 UTC (rev 495) @@ -1,4 +1,5 @@ <?php + /** * Copyright (c) 2011, Erasmus MC * All rights reserved. Modified: trunk/library/classes/Gems/Tracker/TrackerInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 13:45:27 UTC (rev 495) @@ -54,7 +54,7 @@ * extension) and TokenValidator. * * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokens(). + * processCompletedTokens() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -283,12 +283,13 @@ * * Does not reflect changes to tracks or rounds. * - * @param int $userId Id of the user who takes the action (for logging) - * @param string $cond - * @return array of translated messages + * @param int $sourceId A source identifier + * @param int $userId Id of the user who takes the action (for logging) + * @param boolean $updateTokens When true each individual token must be synchronized as well + * @return Gems_Tracker_Batch_SynchronizeSourcesBatch A batch to process the synchronization */ - public function recalculateTokens($userId = null, $cond = null); - + public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false); + /** * Recalculates all token dates, timing and results * and outputs text messages. Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker.php 2012-02-16 13:45:27 UTC (rev 495) @@ -48,7 +48,7 @@ * extension) and TokenValidator. * * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokens(). + * processCompletedTokens() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -304,13 +304,15 @@ */ public function filterChangesOnly(array $oldValues, array &$newValues) { - if ($newValues) { + if ($newValues && $oldValues) { // MUtil_Echo::track($newValues); // Remove up unchanged values foreach ($newValues as $name => $value) { - // Extra condition for empty time in date values - if (($value === $oldValues[$name]) || ($value === $oldValues[$name] . ' 00:00:00')) { - unset($newValues[$name]); + if (array_key_exists($name, $oldValues)) { + // Extra condition for empty time in date values + if (($value === $oldValues[$name]) || ($value === $oldValues[$name] . ' 00:00:00')) { + unset($newValues[$name]); + } } } } @@ -858,32 +860,39 @@ * * Does not reflect changes to tracks or rounds. * - * @param Zend_Translate $t - * @param int $userId Id of the user who takes the action (for logging) - * @param string $cond - * @return array of translated messages + * @param int $sourceId A source identifier + * @param int $userId Id of the user who takes the action (for logging) + * @param boolean $updateTokens When true each individual token must be synchronized as well + * @return Gems_Tracker_Batch_SynchronizeSourcesBatch A batch to process the synchronization */ - public function recalculateTokens($userId = null, $cond = null) + public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false) { - $userId = $this->_checkUserId($userId); - $tokenSelect = $this->getTokenSelect(); - $tokenSelect->andReceptionCodes() - ->andRespondents() - ->andRespondentOrganizations() - ->andConsents(); - if ($cond) { - $tokenSelect->forWhere($cond); + $batch_id = 'source_synch' . ($sourceId ? '_' . $sourceId : ''); + $batch = $this->_loadClass('Batch_SynchronizeSourcesBatch', true, array($batch_id)); + + if ($updateTokens != $batch->getTokenUpdate()) { + $batch->reset(); } - //Only select surveys that are active in the source (so we can recalculate inactive in Gems) - $tokenSelect->andSurveys(); - $tokenSelect->forWhere('gsu_surveyor_active = 1'); + $batch->setTokenUpdate($updateTokens); - self::$verbose = true; - $changes = $this->processTokens($tokenSelect, $userId); + if (! $batch->isLoaded()) { + if ($sourceId) { + $sources = array($sourceId); + } else { + $select = $this->db->select(); + $select->from('gems__sources', array('gso_id_source')) + ->where('gso_active = 1'); + $sources = $this->db->fetchCol($select); + } - return $changes->getMessages($this->translate); + foreach ($sources as $source) { + $batch->addSource($source, $userId); + } + } + + return $batch; + } - /** * Recalculates all token dates, timing and results * and outputs text messages. Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 13:45:27 UTC (rev 495) @@ -202,6 +202,8 @@ $command['method'] = $method; $command['parameters'] = $params; + // MUtil_Echo::track($command); + return $command; } @@ -284,7 +286,7 @@ */ public function getCounter($name) { - MUtil_Echo::track($this->_session->counters); + // MUtil_Echo::track($this->_session->counters); if (isset($this->_session->counters[$name])) { return $this->_session->counters[$name]; } @@ -475,6 +477,30 @@ } /** + * Batch duration variable storage for the process + * + * @param string $name Name + * @return mixed The scalar value, if any + */ + protected function getVar($name) + { + if (isset($this->_session->vars[$name])) { + return $this->_session->vars[$name]; + } + } + + /** + * Batch duration variable storage for the process + * + * @param string $name Name + * @return boolean + */ + protected function hasVar($name) + { + return array_key_exists($name, $this->_session->vars); + } + + /** * Return true after commands all have been ran. * * @return boolean @@ -527,6 +553,7 @@ $this->_session->finished = false; $this->_session->messages = array(); $this->_session->processed = 0; + $this->_session->vars = array(); return $this; } @@ -744,6 +771,21 @@ } /** + * Batch duration variable storage for the process + * + * @param string $name Name + * @param mixed $value Scalar value + */ + protected function setVar($name, $value) + { + if (! MUtil_Ra::isScalar($value)) { + throw new MUtil_Batch_BatchException("Non scalar batch value named '$name'."); + } + + $this->_session->vars[$name] = $value; + } + + /** * Progress a single step on the command stack * * @return boolean @@ -758,12 +800,24 @@ call_user_func_array(array($this, $command['method']), $command['parameters']); } catch (Exception $e) { $this->addMessage('ERROR!!!'); - $this->addMessage('While calling:' . $command['method'] . '(', implode(',', MUtil_Ra::flatten($command['parameters'])), ')'); + $this->addMessage('While calling:' . $command['method'] . '(' . implode(',', MUtil_Ra::flatten($command['parameters'])) . ')'); $this->addMessage($e->getMessage()); + + MUtil_Echo::r($e); } return true; } else { return false; } } + + /** + * Batch duration variable storage for the process + * + * @param string $name Name + */ + protected function unsetVar($name) + { + unset($this->_session->vars[$name]); + } } Modified: trunk/library/classes/MUtil/Batch/BatchPull.js =================================================================== --- trunk/library/classes/MUtil/Batch/BatchPull.js 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/MUtil/Batch/BatchPull.js 2012-02-16 13:45:27 UTC (rev 495) @@ -34,6 +34,8 @@ error: function (request, status, error) { alert('Communication error: ' + status); + this.progressTarget.after('<p>' + request.responseText + '</p>'); + // console.log(request); }, progressTarget: null, 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:01:07
|
Revision: 514 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=514&view=rev Author: matijsdejong Date: 2012-02-23 15:00:56 +0000 (Thu, 23 Feb 2012) Log Message: ----------- MUtl_Html bugfixes / documentation RespondentUserDefinition.php bugfix: user_group not added SubMenuItem.php extra function isAllowed() and extra documentation Modified Paths: -------------- trunk/library/classes/Gems/Menu/SubMenuItem.php trunk/library/classes/Gems/Tracker/Token/TokenSelect.php trunk/library/classes/Gems/User/RespondentUserDefinition.php trunk/library/classes/MUtil/Html/Attribute.php trunk/library/classes/MUtil/Html/AttributeAbstract.php trunk/library/classes/MUtil/Html.php Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php =================================================================== --- trunk/library/classes/Gems/Menu/SubMenuItem.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2012-02-23 15:00:56 UTC (rev 514) @@ -725,11 +725,26 @@ } } + /** + * True when allowed + * + * @return boolean + */ + public function isAllowed() + { + return $this->get('allowed', true); + } + public function isTopLevel() { return ! $this->has('controller'); } + /** + * True when visible + * + * @return boolean + */ public function isVisible() { return $this->get('visible', true); Modified: trunk/library/classes/Gems/Tracker/Token/TokenSelect.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token/TokenSelect.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/Gems/Tracker/Token/TokenSelect.php 2012-02-23 15:00:56 UTC (rev 514) @@ -100,7 +100,7 @@ */ public function andReceptionCodes($fields = '*') { - $this->sql_select->join('gems__reception_codes', + $this->sql_select->join('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', $fields); Modified: trunk/library/classes/Gems/User/RespondentUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-23 15:00:56 UTC (rev 514) @@ -73,11 +73,13 @@ 'user_gender' => 'grs_gender', 'user_locale' => 'grs_iso_lang', )) - ->join('gems__organizations', 'gr2o_id_organization=gor_id_organization', array()) - ->join('gems__groups', 'gor_respondent_group=ggp_id_group', array( - 'user_role'=>'ggp_role', - 'user_allowed_ip_ranges' => 'ggp_allowed_ip_ranges', - )) + ->join('gems__organizations', 'gr2o_id_organization = gor_id_organization', array( + 'user_group' => 'gor_respondent_group', + )) + ->join('gems__groups', 'gor_respondent_group = ggp_id_group', array( + 'user_role' => 'ggp_role', + 'user_allowed_ip_ranges' => 'ggp_allowed_ip_ranges', + )) ->joinLeft('gems__user_passwords', 'gul_id_user = gup_id_user', array( 'user_password_reset' => 'gup_reset_required', )) Modified: trunk/library/classes/MUtil/Html/Attribute.php =================================================================== --- trunk/library/classes/MUtil/Html/Attribute.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/MUtil/Html/Attribute.php 2012-02-23 15:00:56 UTC (rev 514) @@ -1,41 +1,49 @@ <?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$ */ +/** + * A simple, basic one value attribute + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ + class MUtil_Html_Attribute extends MUtil_Html_AttributeAbstract { private $_value; @@ -58,7 +66,7 @@ public function get() { - return $this->value; + return $this->_value; } public function set($value) Modified: trunk/library/classes/MUtil/Html/AttributeAbstract.php =================================================================== --- trunk/library/classes/MUtil/Html/AttributeAbstract.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/MUtil/Html/AttributeAbstract.php 2012-02-23 15:00:56 UTC (rev 514) @@ -1,41 +1,52 @@ <?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$ */ +/** + * Basic class for all attributes, does the rendering and attribute name parts, + * but no value processing. + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @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.php =================================================================== --- trunk/library/classes/MUtil/Html.php 2012-02-23 12:27:01 UTC (rev 513) +++ trunk/library/classes/MUtil/Html.php 2012-02-23 15:00:56 UTC (rev 514) @@ -261,7 +261,7 @@ * * @param string $name Snippet name * @param MUtil_Ra::pairs $parameter_value_pairs Optional extra snippets - * @return + * @return MUtil_Snippets_SnippetInterface */ public static function snippet($name, $parameter_value_pairs = null) { @@ -273,7 +273,11 @@ $loader = self::getSnippetLoader(); - return $loader->getSnippet($name, $extraSourceParameters); + $snippet = $loader->getSnippet($name, $extraSourceParameters); + + if ($snippet->hasHtmlOutput()) { + return $snippet; + } } public static function url($arg_array = null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-03-01 15:21:58
|
Revision: 529 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=529&view=rev Author: matijsdejong Date: 2012-03-01 15:21:51 +0000 (Thu, 01 Mar 2012) Log Message: ----------- First round in simplifying ModelSnippetActionAbstract Plus bugfix in DatabaseModelAbstract.php for certain filter cases Modified Paths: -------------- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Default/MailLogAction.php trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -47,14 +47,16 @@ abstract class Gems_Controller_ModelSnippetActionAbstract extends MUtil_Controller_ModelSnippetActionAbstract { /** - * The parameters used for the autofilter action. + * Gems only parameters used for the autofilter action. Can be overruled + * by setting $this->autofilterParameters * * @var array Mixed key => value array for snippet initialization */ - protected $autofilterParameters = array( + private $_autofilterExtraParameters = array( 'browse' => true, 'containingId' => 'autofilter_target', 'keyboard' => true, + 'onEmpty' => 'getOnEmpty', ); /** @@ -118,6 +120,21 @@ public $util; /** + * The automatically filtered result + * + * @param $resetMvc When true only the filtered resulsts + */ + public function autofilterAction($resetMvc = true) + { + // Already done when this value is false + if ($resetMvc) { + $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters; + } + + return parent::autofilterAction($resetMvc); + } + + /** * Outputs the model to excel, applying all filters and searches needed * * When you want to change the output, there are two places to check: @@ -224,6 +241,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('Nothing found...'); + } + + /** * Returns the current html/head/title for this page. * * If the title is an array the seperator concatenates the parts. @@ -249,6 +276,16 @@ } /** + * Action for showing a browse page + */ + public function indexAction() + { + $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters; + + return parent::indexAction(); + } + + /** * Intializes the html component. * * @param boolean $reset Throws away any existing html output when true Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -53,18 +53,6 @@ public $project; /** - * The automatically filtered result - * - * @param $resetMvc When true only the filtered resulsts - */ - public function autofilterAction($resetMvc = true) - { - $this->autofilterParameters['onEmpty'] = $this->_('No automatic mail jobs found...'); - - parent::autofilterAction($resetMvc); - } - - /** * Action for showing a create new item page */ public function createAction() @@ -178,6 +166,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No automatic mail jobs found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/Gems/Default/MailLogAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -48,6 +48,21 @@ class Gems_Default_MailLogAction extends Gems_Controller_ModelSnippetActionAbstract { /** + * The parameters used for the autofilter action. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $autofilterParameters = array( + 'extraFilter' => 'getExtraFilter', + 'extraSort' => array('grco_created' => SORT_DESC), + ); + + /** * The snippets used for the autofilter action. * * @var mixed String or array of snippets name @@ -55,19 +70,6 @@ protected $autofilterSnippets = 'Mail_Log_MailLogBrowseSnippet'; /** - * The automatically filtered result - */ - public function autofilterAction($resetMvc = true) - { - $filter = array('grco_organization' => $this->escort->getCurrentOrganization()); - - $this->autofilterParameters['extraFilter'] = $filter; - $this->autofilterParameters['extraSort'] = array('grco_created' => SORT_DESC); - - return parent::autofilterAction($resetMvc); - } - - /** * 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 @@ -122,6 +124,26 @@ } /** + * Returns an extra filter for this action + * + * @return array + */ + protected function getExtraFilter() + { + return array('grco_organization' => $this->escort->getCurrentOrganization()); + } + + /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No mail activity found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -207,6 +207,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No organization found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -49,6 +49,52 @@ abstract class MUtil_Controller_ModelSnippetActionAbstract extends MUtil_Controller_Action { /** + * Default parameters for createAction, can be overruled by $this->createParameters + * or $this->createEditParameters values with the same key. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultCreateParameters = array( + 'createData' => true, + ); + + /** + * Default parameters for editAction, can be overruled by $this->editParameters + * or $this->createEditParameters values with the same key. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultEditParameters = array( + 'createData' => false, + ); + + /** + * Default parameters for all actions, unless overruled by values with the same key at + * the action level + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultParameters = array( + 'model' => 'getModel', + 'request' => 'getRequest', + ); + + /** * Created in createModel(). * * Always retrieve using $this->getModel(). @@ -60,6 +106,11 @@ /** * The parameters used for the autofilter action. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $autofilterParameters = array(); @@ -74,11 +125,30 @@ /** * The parameters used for the create and edit actions. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $createEditParameters = array(); /** + * The parameters used for the edit actions, overrules any values in + * $this->createEditParameters. + * + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $createParameters = array(); + + /** * The snippets used for the create and edit actions. * * @var mixed String or array of snippets name @@ -88,6 +158,11 @@ /** * The parameters used for the delete action. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $deleteParameters = array(); @@ -100,8 +175,26 @@ protected $deleteSnippets = 'ModelYesNoDeleteSnippet'; /** + * The parameters used for the edit actions, overrules any values in + * $this->createEditParameters. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $editParameters = array(); + + /** * The parameters used for the index action minus those in autofilter. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $indexParameters = array(); @@ -123,6 +216,11 @@ /** * The parameters used for the show action * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $showParameters = array(); @@ -165,6 +263,29 @@ } /** + * + * @param array $input + * @return array + */ + protected function _processParameters(array $input) + { + $output = array(); + + foreach ($input + $this->_defaultParameters as $key => $value) { + if (is_string($value) && method_exists($this, $value)) { + $value = $this->$value($key); + + if (is_integer($key) || ($value === null)) { + continue; + } + } + $output[$key] = $value; + } + + return $output; + } + + /** * Set the action key in request * * Use this when an action is a Ajax action for retrieving @@ -197,10 +318,9 @@ } if ($this->autofilterSnippets) { - $this->autofilterParameters['model'] = $this->getModel(); - $this->autofilterParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->autofilterParameters); - $this->addSnippets($this->autofilterSnippets, $this->autofilterParameters); + $this->addSnippets($this->autofilterSnippets, $params); } if ($resetMvc && MUtil_Echo::hasOutput()) { @@ -216,28 +336,13 @@ public function createAction() { if ($this->createEditSnippets) { - $this->createEditParameters['createData'] = true; - $this->createEditParameters['model'] = $this->getModel(); - $this->createEditParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->createParameters + $this->createEditParameters + $this->_defaultCreateParameters); - $this->addSnippets($this->createEditSnippets, $this->createEditParameters); + $this->addSnippets($this->createEditSnippets, $params); } } /** - * Action for showing a delete item page - */ - public function deleteAction() - { - if ($this->deleteSnippets) { - $this->deleteParameters['model'] = $this->getModel(); - $this->deleteParameters['request'] = $this->getRequest(); - - $this->addSnippets($this->deleteSnippets, $this->deleteParameters); - } - } - - /** * 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 @@ -251,16 +356,26 @@ abstract protected function createModel($detailed, $action); /** + * Action for showing a delete item page + */ + public function deleteAction() + { + if ($this->deleteSnippets) { + $params = $this->_processParameters($this->deleteParameters); + + $this->addSnippets($this->deleteSnippets, $params); + } + } + + /** * Action for showing a edit item page */ public function editAction() { if ($this->createEditSnippets) { - $this->createEditParameters['createData'] = false; - $this->createEditParameters['model'] = $this->getModel(); - $this->createEditParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->editParameters + $this->createEditParameters + $this->_defaultEditParameters); - $this->addSnippets($this->createEditSnippets, $this->createEditParameters); + $this->addSnippets($this->createEditSnippets, $params); } } @@ -293,27 +408,23 @@ return $this->_model; } - /** * Action for showing a browse page */ public function indexAction() { if ($this->indexStartSnippets || $this->indexStopSnippets) { - $this->indexParameters = $this->indexParameters + $this->autofilterParameters; + $params = $this->_processParameters($this->indexParameters + $this->autofilterParameters); - $this->indexParameters['model'] = $this->getModel(); - $this->indexParameters['request'] = $this->getRequest(); - if ($this->indexStartSnippets) { - $this->addSnippets($this->indexStartSnippets, $this->indexParameters); + $this->addSnippets($this->indexStartSnippets, $params); } } $this->autofilterAction(false); if ($this->indexStopSnippets) { - $this->addSnippets($this->indexStopSnippets, $this->indexParameters); + $this->addSnippets($this->indexStopSnippets, $params); } } @@ -323,10 +434,9 @@ public function showAction() { if ($this->showSnippets) { - $this->showParameters['model'] = $this->getModel(); - $this->showParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->showParameters); - $this->addSnippets($this->showSnippets, $this->showParameters); + $this->addSnippets($this->showSnippets, $params); } } } Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -722,7 +722,15 @@ $wheres[] = $sqlField . ' LIKE \'%' . $search . '%\''; } } - $filter[] = implode(' ' . Zend_Db_Select::SQL_OR . ' ', $wheres); + + if ($wheres) { + $filter[] = implode(' ' . Zend_Db_Select::SQL_OR . ' ', $wheres); + } else { + // When all fields are multiOption fields that do not result in a + // filter, then there is no existing filter and the result set + // should always be empty. + $filter[] = '1=0'; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |