From: <gem...@li...> - 2012-02-06 12:39:32
|
Revision: 451 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=451&view=rev Author: matijsdejong Date: 2012-02-06 12:39:20 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Extended HtmlElement with getFirst() and getLast() for ease of manipulation. VerticalTableBridge.php no longer adds an empty row to the end of the table EditTrackEnigineSnippet now has a parent object for ease of inheritance Added documentation Modified Paths: -------------- branches/1.5.x/library/classes/Gems/Default/TrackAction.php branches/1.5.x/library/classes/Gems/Default/TrackActionAbstract.php branches/1.5.x/library/classes/Gems/Default/TrackMaintenanceAction.php branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php branches/1.5.x/library/classes/MUtil/Html/HtmlElement.php branches/1.5.x/library/classes/MUtil/Html/TBodyElement.php branches/1.5.x/library/classes/MUtil/Lazy.php branches/1.5.x/library/classes/MUtil/Model/FormBridge.php branches/1.5.x/library/classes/MUtil/Model/VerticalTableBridge.php branches/1.5.x/library/snippets/EditTrackEngineSnippet.php Added Paths: ----------- branches/1.5.x/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php Modified: branches/1.5.x/library/classes/Gems/Default/TrackAction.php =================================================================== --- branches/1.5.x/library/classes/Gems/Default/TrackAction.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/Gems/Default/TrackAction.php 2012-02-06 12:39:20 UTC (rev 451) @@ -71,8 +71,9 @@ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { $bridge->gr2t_id_respondent_track; //For show and edit button - $bridge->tr()->appendAttrib('class', $bridge->row_class); + $bridge->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class); + // Add edit button if allowed, otherwise show, again if allowed if ($menuItem = $this->findAllowedMenuItem('show-track')) { $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); @@ -461,6 +462,9 @@ } } + /** + * Show information on a single track assigned to a respondent + */ public function showTrackAction() { $request = $this->getRequest(); Modified: branches/1.5.x/library/classes/Gems/Default/TrackActionAbstract.php =================================================================== --- branches/1.5.x/library/classes/Gems/Default/TrackActionAbstract.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/Gems/Default/TrackActionAbstract.php 2012-02-06 12:39:20 UTC (rev 451) @@ -203,6 +203,7 @@ { $model = $this->loader->getTracker()->getRespondentTrackModel(); + $model->resetOrder(); $model->set('gtr_track_name', 'label', $this->_('Track')); $model->set('gr2t_track_info', 'label', $this->_('Description'), 'description', $this->_('Enter the particulars concerning the assignment to this respondent.')); Modified: branches/1.5.x/library/classes/Gems/Default/TrackMaintenanceAction.php =================================================================== --- branches/1.5.x/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-02-06 12:39:20 UTC (rev 451) @@ -61,13 +61,16 @@ */ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { - if ($this->getRequest()->getActionName() == 'index') { + $request = $this->getRequest(); + + if ($request->getActionName() == 'index') { if ($menuItem = $this->findAllowedMenuItem('show')) { $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); } - if ($menuItem = $this->findAllowedMenuItem('edit')) { - $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); - } + + $menuItem = $this->findAllowedMenuItem('edit'); + } else { + $menuItem = null; } foreach($model->getItemsOrdered() as $name) { @@ -75,6 +78,10 @@ $bridge->addSortable($name, $label); } } + + if ($menuItem) { + $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); + } } /** Modified: branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php =================================================================== --- branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-06 12:39:20 UTC (rev 451) @@ -110,6 +110,8 @@ $this->set('gtr_active', 'label', $this->translate->_('Active'), 'multiOptions', $translated->getYesNo()); $this->set('gtr_date_start', 'label', $this->translate->_('From'), 'dateFormat', $translated->dateFormatString, 'formatFunction', $translated->formatDate); $this->set('gtr_date_until', 'label', $this->translate->_('Use until'), 'dateFormat', $translated->dateFormatString, 'formatFunction', $translated->formatDateForever); + + return $this; } /** Added: branches/1.5.x/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php =================================================================== --- branches/1.5.x/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php (rev 0) +++ branches/1.5.x/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php 2012-02-06 12:39:20 UTC (rev 451) @@ -0,0 +1,304 @@ +<?php + +/** + * Copyright (c) 2012, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage Tracker + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: EditTrackEngineSnippetGeneric.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Basic snippet for editing track engines instances + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Tracker_Snippets_EditTrackEngineSnippetGeneric extends Gems_Snippets_ModelFormSnippetAbstract +{ + /** + * + * @var string Field for storing the old track class + */ + protected $_oldClassName = 'old__gtr_track_class'; + + /** + * + * @var Zend_Db_Adapter_Abstract + */ + protected $db; + + /** + * Required + * + * @var Gems_Loader + */ + protected $loader; + + /** + * Optional, required when creating or $trackId should be set + * + * @var Gems_Tracker_Engine_TrackEngineInterface + */ + protected $trackEngine; + + /** + * Optional, required when creating or $engine should be set + * + * @var int Track Id + */ + protected $trackId; + + /** + * @var Gems_Util + */ + protected $util; + + /** + * Adds elements from the model to the bridge that creates the form. + * + * Overrule this function to add different elements to the browse table, without + * having to recode the core table building code. + * + * @param MUtil_Model_FormBridge $bridge + * @param MUtil_Model_ModelAbstract $model + */ + protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model) + { + if (! $this->createData) { + $bridge->addHidden('gtr_id_track'); + } + $bridge->addText('gtr_track_name', 'size', 30, 'minlength', 4, 'validator', $model->createUniqueValidator('gtr_track_name')); + + // gtr_track_class + if ($this->trackEngine) { + $options = $model->get('gtr_track_class', 'multiOptions'); + $alternatives = $this->trackEngine->getConversionTargets($options); + if (count($alternatives) > 1) { + $options = $alternatives; + + $bridge->addHidden($this->_oldClassName); + + if (! isset($this->formData[$this->_oldClassName])) { + $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class']; + } + + $classEdit = true; + } else { + $classEdit = false; + } + } else { + $tracker = $this->loader->getTracker(); + $options = $tracker->getTrackEngineList(true, true); + $classEdit = true; + } + $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false); + if ($classEdit) { + $bridge->addRadio( 'gtr_track_class'); + } else { + $bridge->addExhibitor('gtr_track_class'); + } + + $bridge->addDate('gtr_date_start'); + $bridge->addDate('gtr_date_until'); + if (! $this->createData) { + $bridge->addCheckbox('gtr_active'); + } + $bridge->addMultiCheckbox('gtr_organizations', 'label', $this->_('Organizations'), 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'required', true); + } + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required are missing. + */ + public function checkRegistryRequestsAnswers() + { + return $this->db && $this->loader && parent::checkRegistryRequestsAnswers(); + } + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + $model = $this->loader->getTracker()->getTrackModel(); + $model->applyFormatting(true); + + return $model; + } + + /** + * + * @return Gems_Menu_MenuList + * / + protected function getMenuList() + { + $links = $this->menu->getMenuList(); + $links->addParameterSources($this->request, $this->menu->getParameterSource()); + + $links->addByController('track', 'show-track', $this->_('Show track')) + ->addByController('track', 'index', $this->_('Show tracks')) + ->addByController('respondent', 'show', $this->_('Show respondent')); + + return $links; + } // */ + + /** + * Helper function to allow generalized statements about the items in the model to used specific item names. + * + * @param int $count + * @return $string + */ + public function getTopic($count = 1) + { + return $this->plural('track', 'tracks', $count); + } + + /** + * + * @return string The header title to display + */ + protected function getTitle() + { + if ($this->createData) { + return $this->_('Add new track'); + } else { + return parent::getTitle(); + } + } + + /** + * The place to check if the data set in the snippet is valid + * to generate the snippet. + * + * When invalid data should result in an error, you can throw it + * here but you can also perform the check in the + * checkRegistryRequestsAnswers() function from the + * {@see MUtil_Registry_TargetInterface}. + * + * @return boolean + */ + public function hasHtmlOutput() + { + if ($this->trackEngine && (! $this->trackId)) { + $this->trackId = $this->trackEngine->getTrackId(); + } + + if ($this->trackId) { + // We are updating + $this->createData = false; + + // Try to get $this->trackEngine filled + if (! $this->trackEngine) { + // Set the engine used + $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId); + } + + } else { + // We are inserting + $this->createData = true; + $this->saveLabel = $this->_($this->_('Add new track')); + } + + return parent::hasHtmlOutput(); + } + + /** + * Hook that loads the form data from $_POST or the model + * + * Or from whatever other source you specify here. + */ + protected function loadFormData() + { + parent::loadFormData(); + + // feature request #200 + if (isset($this->formData['gtr_organizations']) && (! is_array($this->formData['gtr_organizations']))) { + $this->formData['gtr_organizations'] = explode('|', trim($this->formData['gtr_organizations'], '|')); + } + } + + /** + * Hook containing the actual save code. + * + * Call's afterSave() for user interaction. + * + * @see afterSave() + */ + protected function saveData() + { + // feature request #200 + if (isset($this->formData['gtr_organizations']) && is_array($this->formData['gtr_organizations'])) { + $this->formData['gtr_organizations'] = '|' . implode('|', $this->formData['gtr_organizations']) . '|'; + } + if ($this->trackEngine) { + $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount(); + } else { + $this->formData['gtr_survey_rounds'] = 0; + } + + parent::saveData(); + + // Check for creation + if ($this->createData) { + if (isset($this->formData['gtr_id_track'])) { + $this->trackId = $this->formData['gtr_id_track']; + } + } elseif ($this->trackEngine && + isset($this->formData[$this->_oldClassName], $this->formData['gtr_track_class']) && + $this->formData[$this->_oldClassName] != $this->formData['gtr_track_class']) { + + // Track conversion + $this->trackEngine->convertTo($this->formData['gtr_track_class']); + } + } + + /** + * Set what to do when the form is 'finished'. + * + * @return EditTrackEngineSnippet (continuation pattern) + */ + protected function setAfterSaveRoute() + { + // Default is just go to the index + if ($this->routeAction && ($this->request->getActionName() !== $this->routeAction)) { + $this->afterSaveRouteUrl = array($this->request->getActionKey() => $this->routeAction, MUtil_Model::REQUEST_ID => $this->trackId); + } + + return $this; + } +} Modified: branches/1.5.x/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Html/HtmlElement.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/MUtil/Html/HtmlElement.php 2012-02-06 12:39:20 UTC (rev 451) @@ -646,6 +646,18 @@ } } + /** + * Make sure a default child tag element exists. + */ + protected function _ensureDefaultTag() + { + if ($this->_defaultChildTag && (! $this->_content)) { + $value = MUtil_Html::create($this->_defaultChildTag); + $this->_lastChild = $value; + $this->_content[] = $value; + } + } + private function _notAllowedChild($element) { if ($this->_allowedChildTags) { @@ -858,11 +870,43 @@ return $this->_defaultChildTag; } + /** + * Get the first child element. + * + * @param boolean $create A default child tag is created if the element does not exist and has a default child tag + * @return MUtil_Html_HtmlElement or another MUtil_Html_HtmlInterface element + */ + public function getFirst($create = false) + { + if ($create && (! $this->_content)) { + $this->_ensureDefaultTag(); + } + if ($this->_content) { + return reset($this->_content); + } + } + public function getIterator() { return new ArrayIterator($this->_content); } + /** + * Get the last child element. + * + * @param boolean $create A default child tag is created if the element does not exist + * @return MUtil_Html_HtmlElement or another MUtil_Html_HtmlInterface element + */ + public function getLast($create = false) + { + if ($create && (! $this->_content)) { + $this->_ensureDefaultTag(); + } + if ($this->_content) { + return end($this->_content); + } + } + public function getOnEmpty() { if (! $this->_onEmptyContent) { Modified: branches/1.5.x/library/classes/MUtil/Html/TBodyElement.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Html/TBodyElement.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/MUtil/Html/TBodyElement.php 2012-02-06 12:39:20 UTC (rev 451) @@ -89,6 +89,18 @@ } /** + * Make sure a default child tag element exists. + * + * Overruled because of the extra actions in $this->tr() + */ + protected function _ensureDefaultTag() + { + if ($this->_defaultChildTag && (! $this->_content)) { + $this->tr(); + } + } + + /** * 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; @@ -241,28 +253,7 @@ return $this; } - public function tr($arg_array = null) - { - $args = func_get_args(); - // Set default child tag first and het because otherwise - // the children are created first and the default child tag - // is set afterwards. - if (! array_key_exists('DefaultChildTag', $args)) { - array_unshift($args, array('DefaultChildTag' => $this->getDefaultRowChildTag())); - } - - $tr = MUtil_Html::createArray('tr', $args); - - $this[] = $tr; - - if ((! isset($tr->class)) && ($class = $this->getDefaultRowClass())) { - $tr->class = $class; - } - - return $tr; - } - /** * Static helper function for creation, used by @see MUtil_Html_Creator. * @@ -298,4 +289,32 @@ $args = func_get_args(); return new self(__FUNCTION__, array('DefaultRowChildTag' => 'th'), $args); } + + /** + * Add a row with a class and the correct type of default child tag to this element + * + * @param mixed $arg_array MUtil::args() values + * @return MUtil_Html_TrElement + */ + public function tr($arg_array = null) + { + $args = func_get_args(); + + // Set default child tag first and het because otherwise + // the children are created first and the default child tag + // is set afterwards. + if (! array_key_exists('DefaultChildTag', $args)) { + array_unshift($args, array('DefaultChildTag' => $this->getDefaultRowChildTag())); + } + + $tr = MUtil_Html::createArray('tr', $args); + + $this[] = $tr; + + if ((! isset($tr->class)) && ($class = $this->getDefaultRowClass())) { + $tr->class = $class; + } + + return $tr; + } } \ No newline at end of file Modified: branches/1.5.x/library/classes/MUtil/Lazy.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Lazy.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/MUtil/Lazy.php 2012-02-06 12:39:20 UTC (rev 451) @@ -100,11 +100,27 @@ return $result; } + /** + * Lazy if statement + * + * @param mixed $if The value tested during raise + * @param mixed $then The value after raise when $if is true + * @param mixed $else The value after raise when $if is false + * @return MUtil_Lazy_Call + */ public static function iff($if, $then, $else = null) { return new MUtil_Lazy_Call(array($if, 'if'), array($then, $else)); } + /** + * Lazy if statement + * + * @param mixed $if The value tested during raise + * @param mixed $then The value after raise when $if is true + * @param mixed $else The value after raise when $if is false + * @return MUtil_Lazy_Call + */ public static function iif($if, $then, $else = null) { return new MUtil_Lazy_Call(array($if, 'if'), array($then, $else)); Modified: branches/1.5.x/library/classes/MUtil/Model/FormBridge.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Model/FormBridge.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/MUtil/Model/FormBridge.php 2012-02-06 12:39:20 UTC (rev 451) @@ -172,7 +172,7 @@ { $args = func_get_args(); $allowedOptionsKeys = MUtil_Ra::args($args, 2); - + $allowedOptions = array(); foreach ($allowedOptionsKeys as $allowedOptionsKey) { if (is_array($allowedOptionsKey)) { @@ -202,7 +202,7 @@ // Remove options already filled. Using simple array addition // might trigger a lot of lazy calculations that are not needed. - //First strip the options that are not allowed + //First strip the options that are not allowed if (MUtil_Model::$verbose) { $strippedKeys = array_keys(array_diff_key($options, array_flip($allowedOptions))); if (!empty($strippedKeys)) { @@ -283,6 +283,13 @@ return $this->_addToForm($name, $element); } + /** + * Add a ZendX date picker to the form + * + * @param string $name Name of element + * @param mixed $arrayOrKey1 MUtil_Ra::pairs() name => value array + * @return ZendX_JQuery_Form_Element_ColorPicker + */ public function addDate($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null) { $options = func_get_args(); Modified: branches/1.5.x/library/classes/MUtil/Model/VerticalTableBridge.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Model/VerticalTableBridge.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/classes/MUtil/Model/VerticalTableBridge.php 2012-02-06 12:39:20 UTC (rev 451) @@ -215,10 +215,6 @@ $this->table->td(); $this->currentColumn++; } - - // Reset row - $this->table->tr(); - $this->currentColumn = 0; } } Modified: branches/1.5.x/library/snippets/EditTrackEngineSnippet.php =================================================================== --- branches/1.5.x/library/snippets/EditTrackEngineSnippet.php 2012-02-06 10:32:06 UTC (rev 450) +++ branches/1.5.x/library/snippets/EditTrackEngineSnippet.php 2012-02-06 12:39:20 UTC (rev 451) @@ -36,7 +36,7 @@ */ /** - * Snippet for editing track engines instances + * Default snippet for editing track engines instances * * @package Gems * @subpackage Snippets @@ -44,261 +44,6 @@ * @license New BSD License * @since Class available since version 1.4 */ -class EditTrackEngineSnippet extends Gems_Snippets_ModelFormSnippetAbstract +class EditTrackEngineSnippet extends Gems_Tracker_Snippets_EditTrackEngineSnippetGeneric { - /** - * - * @var string Field for storing the old track class - */ - protected $_oldClassName = 'old__gtr_track_class'; - - /** - * - * @var Zend_Db_Adapter_Abstract - */ - protected $db; - - /** - * Required - * - * @var Gems_Loader - */ - protected $loader; - - /** - * Optional, required when creating or $trackId should be set - * - * @var Gems_Tracker_Engine_TrackEngineInterface - */ - protected $trackEngine; - - /** - * Optional, required when creating or $engine should be set - * - * @var int Track Id - */ - protected $trackId; - - /** - * @var Gems_Util - */ - protected $util; - - /** - * Adds elements from the model to the bridge that creates the form. - * - * Overrule this function to add different elements to the browse table, without - * having to recode the core table building code. - * - * @param MUtil_Model_FormBridge $bridge - * @param MUtil_Model_ModelAbstract $model - */ - protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model) - { - if (! $this->createData) { - $bridge->addHidden('gtr_id_track'); - } - $bridge->addText('gtr_track_name', 'size', 30, 'minlength', 4, 'validator', $model->createUniqueValidator('gtr_track_name')); - - // gtr_track_class - if ($this->trackEngine) { - $options = $model->get('gtr_track_class', 'multiOptions'); - $alternatives = $this->trackEngine->getConversionTargets($options); - if (count($alternatives) > 1) { - $options = $alternatives; - - $bridge->addHidden($this->_oldClassName); - - if (! isset($this->formData[$this->_oldClassName])) { - $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class']; - } - - $classEdit = true; - } else { - $classEdit = false; - } - } else { - $tracker = $this->loader->getTracker(); - $options = $tracker->getTrackEngineList(true, true); - $classEdit = true; - } - $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false); - if ($classEdit) { - $bridge->addRadio( 'gtr_track_class'); - } else { - $bridge->addExhibitor('gtr_track_class'); - } - - $bridge->addDate('gtr_date_start'); - $bridge->addDate('gtr_date_until'); - if (! $this->createData) { - $bridge->addCheckbox('gtr_active'); - } - $bridge->addMultiCheckbox('gtr_organizations', 'label', $this->_('Organizations'), 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'required', true); - } - - /** - * Should be called after answering the request to allow the Target - * to check if all required registry values have been set correctly. - * - * @return boolean False if required are missing. - */ - public function checkRegistryRequestsAnswers() - { - return $this->db && $this->loader && parent::checkRegistryRequestsAnswers(); - } - - /** - * Creates the model - * - * @return MUtil_Model_ModelAbstract - */ - protected function createModel() - { - $model = $this->loader->getTracker()->getTrackModel(); - $model->applyFormatting(true); - - return $model; - } - - /** - * - * @return Gems_Menu_MenuList - * / - protected function getMenuList() - { - $links = $this->menu->getMenuList(); - $links->addParameterSources($this->request, $this->menu->getParameterSource()); - - $links->addByController('track', 'show-track', $this->_('Show track')) - ->addByController('track', 'index', $this->_('Show tracks')) - ->addByController('respondent', 'show', $this->_('Show respondent')); - - return $links; - } // */ - - /** - * Helper function to allow generalized statements about the items in the model to used specific item names. - * - * @param int $count - * @return $string - */ - public function getTopic($count = 1) - { - return $this->plural('track', 'tracks', $count); - } - - /** - * - * @return string The header title to display - */ - protected function getTitle() - { - if ($this->createData) { - return $this->_('Add new track'); - } else { - return parent::getTitle(); - } - } - - /** - * The place to check if the data set in the snippet is valid - * to generate the snippet. - * - * When invalid data should result in an error, you can throw it - * here but you can also perform the check in the - * checkRegistryRequestsAnswers() function from the - * {@see MUtil_Registry_TargetInterface}. - * - * @return boolean - */ - public function hasHtmlOutput() - { - if ($this->trackEngine && (! $this->trackId)) { - $this->trackId = $this->trackEngine->getTrackId(); - } - - if ($this->trackId) { - // We are updating - $this->createData = false; - - // Try to get $this->trackEngine filled - if (! $this->trackEngine) { - // Set the engine used - $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId); - } - - } else { - // We are inserting - $this->createData = true; - $this->saveLabel = $this->_($this->_('Add new track')); - } - - return parent::hasHtmlOutput(); - } - - /** - * Hook that loads the form data from $_POST or the model - * - * Or from whatever other source you specify here. - */ - protected function loadFormData() - { - parent::loadFormData(); - - // feature request #200 - if (isset($this->formData['gtr_organizations']) && (! is_array($this->formData['gtr_organizations']))) { - $this->formData['gtr_organizations'] = explode('|', trim($this->formData['gtr_organizations'], '|')); - } - } - - /** - * Hook containing the actual save code. - * - * Call's afterSave() for user interaction. - * - * @see afterSave() - */ - protected function saveData() - { - // feature request #200 - if (isset($this->formData['gtr_organizations']) && is_array($this->formData['gtr_organizations'])) { - $this->formData['gtr_organizations'] = '|' . implode('|', $this->formData['gtr_organizations']) . '|'; - } - if ($this->trackEngine) { - $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount(); - } else { - $this->formData['gtr_survey_rounds'] = 0; - } - - parent::saveData(); - - // Check for creation - if ($this->createData) { - if (isset($this->formData['gtr_id_track'])) { - $this->trackId = $this->formData['gtr_id_track']; - } - } elseif ($this->trackEngine && - isset($this->formData[$this->_oldClassName], $this->formData['gtr_track_class']) && - $this->formData[$this->_oldClassName] != $this->formData['gtr_track_class']) { - - // Track conversion - $this->trackEngine->convertTo($this->formData['gtr_track_class']); - } - } - - /** - * Set what to do when the form is 'finished'. - * - * @return EditTrackEngineSnippet (continuation pattern) - */ - protected function setAfterSaveRoute() - { - // Default is just go to the index - if ($this->routeAction && ($this->request->getActionName() !== $this->routeAction)) { - $this->afterSaveRouteUrl = array($this->request->getActionKey() => $this->routeAction, MUtil_Model::REQUEST_ID => $this->trackId); - } - - return $this; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |