Exemple #1
0
 public function testOptions()
 {
     $model = $this->model;
     $form = new Zend_Form();
     //Unchanged when not in the fixedOptions
     $options = array('description' => 'dd-mm-yyyy');
     $original = $options;
     MUtil_Model_Bridge_FormBridge::applyFixedOptions('input', $options);
     $this->assertEquals($original, $options);
     //Overruled and extended when in the fixedOptions
     $options = $original;
     MUtil_Model_Bridge_FormBridge::applyFixedOptions('date', $options);
     $expected = $this->options['date'];
     $this->assertEquals($expected, $options);
 }
 /**
  * Generate two date selectors and - depending on the number of $dates passed -
  * either a hidden element containing the field name or an radio button or
  * dropdown selector for the type of date to use.
  *
  * @param mixed $dates A string fieldName to use or an array of fieldName => Label
  * @param string $defaultDate Optional element, otherwise first is used.
  * @param int $switchToSelect The number of dates where this function should switch to select display
  */
 protected function getPeriodSelectors($dates, $defaultDate = null, $switchToSelect = 4)
 {
     $elements = array();
     if (is_array($dates) && 1 === count($dates)) {
         $fromLabel = reset($dates);
         $dates = key($dates);
     } else {
         $fromLabel = $this->_('From');
     }
     if (is_string($dates)) {
         $element = $this->form->createElement('hidden', 'dateused');
         $element->setValue($dates);
     } else {
         if (count($dates) >= $switchToSelect) {
             $element = $this->form->createElement('select', 'dateused', array('label' => $this->_('For date'), 'multiOptions' => $dates));
             $fromLabel = '';
         } else {
             $element = $this->form->createElement('radio', 'dateused', array('label' => $this->_('For date'), 'multiOptions' => $dates));
             $element->setSeparator(' ');
             $fromLabel = html_entity_decode(' » ', ENT_QUOTES, 'UTF-8');
         }
         $fromLabel .= $this->_('from');
         if (null === $defaultDate || !isset($dates[$defaultDate])) {
             // Set value to first key
             reset($dates);
             $defaultDate = key($dates);
         }
         $element->setValue($defaultDate);
     }
     $elements['dateused'] = $element;
     $type = 'date';
     if ($this->dateFormat) {
         $options['dateFormat'] = $this->dateFormat;
         list($dateFormat, $separator, $timeFormat) = \MUtil_Date_Format::splitDateTimeFormat($options['dateFormat']);
         if ($timeFormat) {
             if ($dateFormat) {
                 $type = 'datetime';
             } else {
                 $type = 'time';
             }
         }
     }
     $options['label'] = $fromLabel;
     \MUtil_Model_Bridge_FormBridge::applyFixedOptions($type, $options);
     $elements['datefrom'] = new \Gems_JQuery_Form_Element_DatePicker('datefrom', $options);
     $options['label'] = ' ' . $this->_('until');
     $elements['dateuntil'] = new \Gems_JQuery_Form_Element_DatePicker('dateuntil', $options);
     return $elements;
 }
 /**
  * Get form elements for the specific Export
  * @param  \Gems_Form $form existing form type
  * @param  array data existing options set in the form
  * @return array of form elements
  */
 public function getFormElements(\Gems_Form $form, &$data)
 {
     $form->activateJQuery();
     $dbLookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $noRound = array(self::NoRound => $this->_('No round description'));
     $empty = $translated->getEmptyDropdownArray();
     $dateOptions = array();
     \MUtil_Model_Bridge_FormBridge::applyFixedOptions('date', $dateOptions);
     $organizations = $this->currentUser->getRespondentOrganizations();
     $tracks = $empty + $this->util->getTrackData()->getAllTracks();
     $rounds = $empty + $noRound + $dbLookup->getRoundsForExport(isset($data['tid']) ? $data['tid'] : null);
     $surveys = $dbLookup->getSurveysForExport(isset($data['tid']) ? $data['tid'] : null, isset($data['rounds']) ? $data['rounds'] : null);
     $yesNo = $translated->getYesNo();
     $elements = array();
     $element = $form->createElement('textarea', 'ids');
     $element->setLabel($this->_('Respondent id\'s'))->setAttrib('cols', 60)->setAttrib('rows', 4)->setDescription($this->_('Not respondent nr, but respondent id as exported here.'));
     $elements[] = $element;
     $element = $form->createElement('select', 'tid');
     $element->setLabel($this->_('Tracks'))->setMultiOptions($tracks);
     $elements[] = $element;
     if (isset($data['tid']) && $data['tid']) {
         $element = $form->createElement('radio', 'tid_fields');
         $element->setLabel($this->_('Export fields'))->setMultiOptions($yesNo);
         $elements[] = $element;
         if (!array_key_exists('tid_fields', $data)) {
             $data['tid_fields'] = 1;
         }
     }
     $element = $form->createElement('select', 'rounds');
     $element->setLabel($this->_('Round description'))->setMultiOptions($rounds);
     $elements[] = $element;
     $element = $form->createElement('multiselect', 'sid');
     $element->setLabel($this->_('Survey'))->setMultiOptions($surveys)->setDescription($this->_('Use CTRL or Shift to select more'));
     $elements[] = $element;
     $element = $form->createElement('multiCheckbox', 'oid');
     $element->setLabel($this->_('Organization'))->setMultiOptions($organizations);
     $elements[] = $element;
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     }
     $element->setLabel($this->_('Toggle'));
     $elements[] = $element;
     $element = $form->createElement('datePicker', 'valid_from', $dateOptions);
     $element->setLabel($this->_('Valid from'));
     $elements[] = $element;
     $element = $form->createElement('datePicker', 'valid_until', $dateOptions);
     $element->setLabel($this->_('Valid until'));
     $elements[] = $element;
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     }
     $element = $form->createElement('checkbox', 'column_identifiers');
     $element->setLabel($this->_('Column Identifiers'));
     $element->setDescription($this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description'));
     $elements[] = $element;
     //unset($data['records']);
     if (!empty($data['sid'])) {
         $filters = $this->getFilters($data);
         foreach ($filters as $key => $filter) {
             unset($data['records_' . $key]);
             $model = $this->getModel($filter, $data);
             $survey = $this->loader->getTracker()->getSurvey(intval($filter['gto_id_survey']));
             $recordCount = $model->loadPaginator($filter)->getTotalItemCount();
             $element = $form->createElement('exhibitor', 'records_' . $key);
             $element->setValue($survey->getName() . ': ' . sprintf($this->_('%s records found.'), $recordCount));
             //$element->setValue($survey->getName());
             $elements[] = $element;
         }
     }
     if ($this->project->hasResponseDatabase()) {
         $this->addResponseDatabaseForm($form, $data, $elements);
     }
     return $elements;
 }
 /**
  * Generate two date selectors and - depending on the number of $dates passed -
  * either a hidden element containing the field name or an radio button or
  * dropdown selector for the type of date to use.
  *
  * @param array $elements Search element array to which the element are added.
  * @param mixed $dates A string fieldName to use or an array of fieldName => Label
  * @param string $defaultDate Optional element, otherwise first is used.
  * @param int $switchToSelect The number of dates where this function should switch to select display
  */
 protected function _addPeriodSelectors(array &$elements, $dates, $defaultDate = null, $switchToSelect = 4)
 {
     if (is_array($dates) && 1 === count($dates)) {
         $fromLabel = reset($dates);
         $dates = key($dates);
     } else {
         $fromLabel = $this->_('From');
     }
     if (is_string($dates)) {
         $element = new \Zend_Form_Element_Hidden(self::PERIOD_DATE_USED);
         $element->setValue($dates);
     } else {
         if (count($dates) >= $switchToSelect) {
             $element = $this->_createSelectElement(self::PERIOD_DATE_USED, $dates);
             $element->setLabel($this->_('For date'));
             $fromLabel = '';
         } else {
             $element = $this->_createRadioElement(self::PERIOD_DATE_USED, $dates);
             $element->setSeparator(' ');
             $fromLabel = html_entity_decode(' » ', ENT_QUOTES, 'UTF-8');
         }
         $fromLabel .= $this->_('from');
         if (null === $defaultDate || !isset($dates[$defaultDate])) {
             // Set value to first key
             reset($dates);
             $defaultDate = key($dates);
         }
         $element->setValue($defaultDate);
     }
     $elements[self::PERIOD_DATE_USED] = $element;
     $type = 'date';
     if ($this->dateFormat) {
         $options['dateFormat'] = $this->dateFormat;
         list($dateFormat, $separator, $timeFormat) = \MUtil_Date_Format::splitDateTimeFormat($options['dateFormat']);
         if ($timeFormat) {
             if ($dateFormat) {
                 $type = 'datetime';
             } else {
                 $type = 'time';
             }
         }
     }
     $options['label'] = $fromLabel;
     \MUtil_Model_Bridge_FormBridge::applyFixedOptions($type, $options);
     $elements['datefrom'] = new \Gems_JQuery_Form_Element_DatePicker('datefrom', $options);
     $options['label'] = ' ' . $this->_('until');
     $elements['dateuntil'] = new \Gems_JQuery_Form_Element_DatePicker('dateuntil', $options);
 }