/** * Returns a model that can be used to retrieve or save the data. * * @param boolean $detailed Create a model for the display of detailed item data or just a browse table * @param string $action The current action * @return \MUtil_Model_ModelAbstract */ public function getRoundModel($detailed, $action) { $model = $this->createRoundModel(); $translated = $this->util->getTranslated(); // Set the keys to the parameters in use. $model->setKeys(array(\MUtil_Model::REQUEST_ID => 'gro_id_track', \Gems_Model::ROUND_ID => 'gro_id_round')); if ($detailed) { $model->set('gro_id_track', 'label', $this->_('Track'), 'elementClass', 'exhibitor', 'multiOptions', $this->util->getTrackData()->getAllTracks); } $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveysAndDescriptions()); $model->set('gro_icon_file', 'label', $this->_('Icon')); $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10, 'validators[uni]', $model->createUniqueValidator(array('gro_id_order', 'gro_id_track'))); $model->set('gro_round_description', 'label', $this->_('Description'), 'size', '30'); //, 'minlength', 4, 'required', true); $list = $this->events->listRoundChangedEvents(); if (count($list) > 1) { $model->set('gro_changed_event', 'label', $this->_('After change'), 'multiOptions', $list); } $list = $this->events->listSurveyDisplayEvents(); if (count($list) > 1) { $model->set('gro_display_event', 'label', $this->_('Answer display'), 'multiOptions', $list); } $model->set('gro_active', 'label', $this->_('Active'), 'elementClass', 'checkbox', 'multiOptions', $translated->getYesNo()); $model->setIfExists('gro_code', 'label', $this->_('Round code'), 'description', $this->_('Optional code name to link the field to program code.'), 'size', 10); $model->addColumn("CASE WHEN gro_active = 1 THEN '' ELSE 'deleted' END", 'row_class'); $model->addColumn("CASE WHEN gro_organizations IS NULL THEN 0 ELSE 1 END", 'org_specific_round'); $model->addColumn('gro_organizations', 'organizations'); $model->set('organizations', 'label', $this->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'data-source', 'org_specific_round'); $tp = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', ')); $tp->apply($model, 'organizations'); switch ($action) { case 'create': $this->_ensureRounds(); if ($this->_rounds && ($round = end($this->_rounds))) { $model->set('gro_id_order', 'default', $round['gro_id_order'] + 10); } // Intentional fall through // break; // Intentional fall through // break; case 'edit': case 'show': $model->set('gro_icon_file', 'multiOptions', $translated->getEmptyDropdownArray() + $this->_getAvailableIcons()); $model->set('org_specific_round', 'label', $this->_('Organization specific round'), 'default', 0, 'multiOptions', $translated->getYesNo(), 'elementClass', 'radio'); break; default: $model->set('gro_icon_file', 'formatFunction', array('MUtil_Html_ImgElement', 'imgFile')); break; } return $model; }