/**
  * Overrule this function for any activities you want to take place
  * after the form has successfully been validated, but before any
  * buttons are processed.
  *
  * @param int $step The current step
  */
 protected function afterFormValidationFor($step)
 {
     parent::afterFormValidationFor($step);
     if ($this->trackEngine) {
         if (4 == $step) {
             $import = $this->loadImportData();
             $model = $this->getModel();
             $saves = array();
             $import['deactivateRounds'] = array();
             foreach ($model->getCol('roundId') as $name => $roundId) {
                 $round = $this->trackEngine->getRound($roundId);
                 if (isset($this->formData[$name]) && $this->formData[$name] && $round instanceof Round) {
                     switch ($this->formData[$name]) {
                         case self::ROUND_DEACTIVATE:
                             $import['deactivateRounds'][$roundId] = $round->getFullDescription();
                             break;
                         case self::ROUND_LEAVE:
                             if (isset($import['roundOrderToLine'][$round->getRoundOrder()])) {
                                 $lineNr = $import['roundOrderToLine'][$round->getRoundOrder()];
                                 unset($import['rounds'][$lineNr]);
                             }
                             $import['roundOrders'][$round->getRoundOrder()] = $roundId;
                             break;
                         default:
                             if (isset($import['roundOrderToLine'][$this->formData[$name]])) {
                                 $lineNr = $import['roundOrderToLine'][$this->formData[$name]];
                                 $import['rounds'][$lineNr]['gro_id_round'] = $roundId;
                             }
                             $import['roundOrders'][$this->formData[$name]] = $roundId;
                             break;
                     }
                 }
             }
         }
     } elseif (3 == $step) {
         $import = $this->loadImportData();
         $model = $this->getModel();
         $saves = array();
         foreach ($model->getCol('exportCode') as $name => $exportCode) {
             if (isset($this->formData[$name]) && $this->formData[$name]) {
                 $saves[] = array('gsu_id_survey' => $this->formData[$name], 'gsu_export_code' => $exportCode);
                 $import['surveyCodes'][$exportCode] = $this->formData[$name];
             }
         }
         if ($saves) {
             $sModel = new \MUtil_Model_TableModel('gems__surveys');
             \Gems_Model::setChangeFieldsByPrefix($sModel, 'gus', $this->currentUser->getUserId());
             $sModel->saveAll($saves);
             $count = $sModel->getChanged();
             if ($count == 0) {
                 $this->addMessage($this->_('No export code changed'));
             } else {
                 $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('surveys'));
                 $this->addMessage(sprintf($this->plural('%d export code changed', '%d export codes changed', $count), $count));
             }
         }
     }
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if (!$this->exportModel instanceof \MUtil_Model_ModelAbstract) {
         $yesNo = $this->util->getTranslated()->getYesNo();
         $model = new \MUtil_Model_SessionModel('export_for_' . $this->request->getControllerName());
         $model->set('orgs', 'label', $this->_('Organization export'), 'default', 1, 'description', $this->_('Export the organizations for which the track is active'), 'multiOptions', $yesNo, 'required', true, 'elementClass', 'Checkbox');
         $model->set('fields', 'label', $this->_('Field export'));
         $fields = $this->trackEngine->getFieldNames();
         if ($fields) {
             $model->set('fields', 'default', array_keys($fields), 'description', $this->_('Check the fields to export'), 'elementClass', 'MultiCheckbox', 'multiOptions', $fields);
         } else {
             $model->set('fields', 'elementClass', 'Exhibitor', 'value', $this->_('No fields to export'));
         }
         $rounds = $this->trackEngine->getRoundDescriptions();
         $model->set('rounds', 'label', $this->_('Round export'));
         if ($rounds) {
             $defaultRounds = array();
             foreach ($rounds as $roundId => &$roundDescription) {
                 $round = $this->trackEngine->getRound($roundId);
                 if ($round && $round->isActive()) {
                     $defaultRounds[] = $roundId;
                 } else {
                     $roundDescription = sprintf($this->_('%s (inactive)'), $roundDescription);
                 }
                 $survey = $round->getSurvey();
                 if ($survey) {
                     $model->set('survey__' . $survey->getSurveyId(), 'label', $survey->getName(), 'default', $survey->getExportCode(), 'description', $this->_('A unique code indentifying this survey during track import'), 'maxlength', 64, 'required', true, 'size', 20, 'surveyId', $survey->getSurveyId());
                 }
             }
             $model->set('rounds', 'default', $defaultRounds, 'description', $this->_('Check the rounds to export'), 'elementClass', 'MultiCheckbox', 'multiOptions', $rounds);
         } else {
             $model->set('rounds', 'elementClass', 'Exhibitor', 'value', $this->_('No rounds to export'));
         }
         $this->exportModel = $model;
     }
     return $this->exportModel;
 }