protected function setUp()
 {
     parent::setup();
     // Now set some defaults
     $dateFormOptions['dateFormat'] = 'dd-MM-yyyy';
     $datetimeFormOptions['dateFormat'] = 'dd-MM-yyyy HH:mm';
     $timeFormOptions['dateFormat'] = 'HH:mm';
     MUtil_Model_Bridge_FormBridge::setFixedOptions(array('date' => $dateFormOptions, 'datetime' => $datetimeFormOptions, 'time' => $timeFormOptions));
 }
 /**
  * Get the date format used for the appointment date
  *
  * @return array
  */
 public function getDateFormat()
 {
     $model = $this->getModel();
     $format = $model->get('gap_admission_time', 'dateFormat');
     if (!$format) {
         $format = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
     }
     return $format;
 }
Пример #3
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);
 }
 /**
  * Sets the labels, format functions, etc...
  *
  * @param boolean $detailed True when shopwing detailed information
  * @param boolean $edit When true use edit settings
  * @return \Gems_Tracker_Model_TrackModel
  */
 public function applyFormatting($detailed = false, $edit = false)
 {
     $translated = $this->util->getTranslated();
     $translator = $this->getTranslateAdapter();
     if ($edit) {
         $dateFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
     } else {
         $dateFormat = $translated->dateFormatString;
     }
     $this->resetOrder();
     $this->set('gtr_track_name', 'label', $translator->_('Name'));
     $this->set('gtr_track_class', 'label', $translator->_('Track Engine'), 'multiOptions', $this->tracker->getTrackEngineList($detailed));
     $this->set('gtr_survey_rounds', 'label', $translator->_('Surveys'));
     $this->set('gtr_active', 'label', $translator->_('Active'), 'multiOptions', $translated->getYesNo());
     $this->set('gtr_date_start', 'label', $translator->_('From'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDate);
     $this->set('gtr_date_until', 'label', $translator->_('Use until'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDateForever);
     $this->setIfExists('gtr_code', 'label', $translator->_('Track code'), 'size', 10, 'description', $translator->_('Optional code name to link the track to program code.'));
     if ($detailed) {
         $events = $this->loader->getEvents();
         $caList = $events->listTrackCalculationEvents();
         if (count($caList) > 1) {
             $this->setIfExists('gtr_calculation_event', 'label', $translator->_('Before (re)calculation'), 'multiOptions', $caList);
         }
         $coList = $events->listTrackCompletionEvents();
         if (count($coList) > 1) {
             $this->setIfExists('gtr_completed_event', 'label', $translator->_('After completion'), 'multiOptions', $coList);
         }
         $bfuList = $events->listTrackBeforeFieldUpdateEvents();
         if (count($bfuList) > 1) {
             $this->setIfExists('gtr_beforefieldupdate_event', 'label', $translator->_('Before field update'), 'multiOptions', $bfuList);
         }
         $fuList = $events->listTrackFieldUpdateEvents();
         if (count($fuList) > 1) {
             $this->setIfExists('gtr_fieldupdate_event', 'label', $translator->_('After field update'), 'multiOptions', $fuList);
         }
         $this->setIfExists('gtr_organizations', 'label', $translator->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizationsWithRespondents(), 'required', true);
         $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $translator->_(', '));
         $ct->apply($this, 'gtr_organizations');
     }
     if ($edit) {
         $this->set('toggleOrg', 'elementClass', 'ToggleCheckboxes', 'selectorName', 'gtr_organizations');
         $this->set('gtr_track_name', 'minlength', 4, 'size', 30, 'validators[unique]', $this->createUniqueValidator('gtr_track_name'));
     }
     return $this;
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     // \Zend_Application: loads the autoloader
     require_once 'Zend/Application.php';
     // Create application, bootstrap, and run
     $application = new \Zend_Application(APPLICATION_ENV, GEMS_ROOT_DIR . '/configs/application.example.ini');
     $this->bootstrap = $application;
     include_once GEMS_TEST_DIR . '/library/Gems/Cookies.php';
     // Dirty fix for cookie problem during tests
     parent::setUp();
     $this->bootstrap->bootstrap('db');
     $this->bootstrap->getBootstrap()->getContainer()->db = $this->db;
     $this->bootstrap->bootstrap();
     \Zend_Registry::set('db', $this->db);
     \Zend_Db_Table::setDefaultAdapter($this->db);
     $this->loader = $this->bootstrap->getBootstrap()->getResource('loader');
     $this->tracker = $this->loader->getTracker();
     // Now set some defaults
     $dateFormOptions['dateFormat'] = 'dd-MM-yyyy';
     $datetimeFormOptions['dateFormat'] = 'dd-MM-yyyy HH:mm';
     $timeFormOptions['dateFormat'] = 'HH:mm';
     \MUtil_Model_Bridge_FormBridge::setFixedOptions(array('date' => $dateFormOptions, 'datetime' => $datetimeFormOptions, 'time' => $timeFormOptions));
 }
 /**
  * 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)
 {
     $keys = $this->getKeys();
     // This is the only key to save on, no matter
     // the keys used to initiate the model.
     $this->setKeys($this->_getKeysFor('gems__respondent2track'));
     // Change the end date until the end of the day
     if (isset($newValues['gr2t_end_date']) && $newValues['gr2t_end_date']) {
         $displayFormat = $this->get('gr2t_end_date', 'dateFormat');
         if (!$displayFormat) {
             $displayFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         }
         // Of course do not do so when we got a time format
         if (!\MUtil_Date_Format::getTimeFormat($displayFormat)) {
             $newValues['gr2t_end_date'] = new \MUtil_Date($newValues['gr2t_end_date'], $displayFormat);
             $newValues['gr2t_end_date']->setTimeToDayEnd();
         }
     }
     $newValues = parent::save($newValues, $filter);
     $this->setKeys($keys);
     return $newValues;
 }
Пример #7
0
 /**
  * A ModelAbstract->setOnSave() function that tracks the change
  *
  * @see \MUtil_Model_ModelAbstract
  *
  * @param mixed $value The value being saved
  * @param boolean $isNew True when a new item is being saved
  * @param string $name The name of the current field
  * @param array $context Optional, the other values being saved
  * @return string Of the values concatenated
  */
 public function saveValue($value, $isNew = false, $name = null, array $context = array())
 {
     // \MUtil_Echo::track($value, $this->_changedValue);
     // Once the value is set (and e.g. stored in the database) do not overwrite it
     if ($this->_changedValue == $value) {
         return $value;
     }
     $compare = $this->_model->get($name, __CLASS__);
     if (!(is_array($compare) && 2 === count($compare))) {
         // Actually a valid setting, do nothring
         return $value;
     }
     list($trackedField, $oldValueField) = $compare;
     if (!isset($context[$trackedField], $context[$oldValueField])) {
         return $value;
     }
     if (!($context[$trackedField] && $context[$oldValueField])) {
         return $context[$trackedField] || $context[$oldValueField] ? $this->_changedValue : $this->_unchangedValue;
     }
     $storageFormat = $this->_model->get($trackedField, 'storageFormat');
     if (!$storageFormat) {
         return $context[$trackedField] == $context[$oldValueField] ? $this->_unchangedValue : $this->_changedValue;
     }
     if ($context[$oldValueField] instanceof \Zend_Date) {
         $oldValue = $context[$oldValueField];
     } else {
         $oldValue = new \MUtil_Date($context[$oldValueField], $storageFormat);
     }
     if ($context[$trackedField] instanceof \Zend_Date) {
         $currentValue = $context[$trackedField];
     } elseif (\Zend_Date::isDate($context[$trackedField], $storageFormat)) {
         $currentValue = new \MUtil_Date($context[$trackedField], $storageFormat);
     } else {
         if ($this->_model->has($trackedField, 'dateFormat')) {
             $secondFormat = $this->_model->get($trackedField, 'dateFormat');
         } else {
             $secondFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         }
         if (!\Zend_Date::isDate($context[$trackedField], $secondFormat)) {
             // Cannot compare, do nothing
             return $value;
         }
         $currentValue = new \MUtil_Date($context[$trackedField], $secondFormat);
     }
     // \MUtil_Echo::track($trackedField, $oldValueField, $oldValue->toString(), $currentValue->toString(), $oldValue->getTimestamp() === $currentValue->getTimestamp());
     return $oldValue->getTimestamp() === $currentValue->getTimestamp() ? $this->_unchangedValue : $this->_changedValue;
 }
 /**
  * Function to allow the creation of search defaults in code
  *
  * @see getSearchFilter()
  *
  * @return array
  */
 public function getSearchDefaults()
 {
     if (!$this->defaultSearchData) {
         $inFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         $now = new \MUtil_Date();
         $today = $now->toString($inFormat);
         $this->defaultSearchData = array('datefrom' => $today, 'dateused' => '_gto_valid_from gto_valid_until', 'dateuntil' => $today, 'main_filter' => 'all');
     }
     return parent::getSearchDefaults();
 }
 /**
  * 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;
 }
 public function afterRegistry()
 {
     parent::afterRegistry();
     // Load the display dateformat
     $dateOptions = \MUtil_Model_Bridge_FormBridge::getFixedOptions('date');
     $this->_dateFormat = $dateOptions['dateFormat'];
     $this->creator = \Gems_Html::init();
 }
 /**
  * Helper function to generate a period query string
  *
  * @param array $filter A filter array or $request->getParams()
  * @param \Zend_Db_Adapter_Abstract $db
  * @param $inFormat Optional format to use for date when reading
  * @param $outFormat Optional format to use for date in query
  * @return string
  */
 public static function getPeriodFilter(array &$filter, \Zend_Db_Adapter_Abstract $db, $inFormat = null, $outFormat = null)
 {
     $from = array_key_exists('datefrom', $filter) ? $filter['datefrom'] : null;
     $until = array_key_exists('dateuntil', $filter) ? $filter['dateuntil'] : null;
     $period = array_key_exists(self::PERIOD_DATE_USED, $filter) ? $filter[self::PERIOD_DATE_USED] : null;
     unset($filter[self::PERIOD_DATE_USED], $filter['datefrom'], $filter['dateuntil']);
     if (!$period) {
         return;
     }
     if (null === $outFormat) {
         $outFormat = 'yyyy-MM-dd';
     }
     if (null === $inFormat) {
         $inFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
     }
     if ($from && \Zend_Date::isDate($from, $inFormat)) {
         $datefrom = $db->quote(\MUtil_Date::format($from, $outFormat, $inFormat));
     } else {
         $datefrom = null;
     }
     if ($until && \Zend_Date::isDate($until, $inFormat)) {
         $dateuntil = $db->quote(\MUtil_Date::format($until, $outFormat, $inFormat));
     } else {
         $dateuntil = null;
     }
     if (!($datefrom || $dateuntil)) {
         return;
     }
     switch ($period[0]) {
         case '_':
             // overlaps
             $periods = explode(' ', substr($period, 1));
             if ($datefrom && $dateuntil) {
                 return sprintf('(%1$s <= %4$s OR (%1$s IS NULL AND %2$s IS NOT NULL)) AND
                             (%2$s >= %3$s OR %2$s IS NULL)', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $datefrom, $dateuntil);
             }
             if ($datefrom) {
                 return sprintf('%2$s >= %3$s OR (%2$s IS NULL AND %1$s IS NOT NULL)', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $datefrom);
             }
             if ($dateuntil) {
                 return sprintf('%1$s <= %3$s OR (%1$s IS NULL AND %2$s IS NOT NULL)', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $dateuntil);
             }
             return;
         case '-':
             // within
             $periods = explode(' ', substr($period, 1));
             if ($datefrom && $dateuntil) {
                 return sprintf('%1$s >= %3$s AND %2$s <= %4$s', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $datefrom, $dateuntil);
             }
             if ($datefrom) {
                 return sprintf('%1$s >= %3$s AND (%2$s IS NULL OR %2$s >= %3$s)', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $datefrom);
             }
             if ($dateuntil) {
                 return sprintf('%2$s <= %3$s AND (%1$s IS NULL OR %1$s <= %3$s)', $db->quoteIdentifier($periods[0]), $db->quoteIdentifier($periods[1]), $dateuntil);
             }
             return;
         default:
             if ($datefrom && $dateuntil) {
                 return sprintf('%s BETWEEN %s AND %s', $db->quoteIdentifier($period), $datefrom, $dateuntil);
             }
             if ($datefrom) {
                 return sprintf('%s >= %s', $db->quoteIdentifier($period), $datefrom);
             }
             if ($dateuntil) {
                 return sprintf('%s <= %s', $db->quoteIdentifier($period), $dateuntil);
             }
             return;
     }
 }
Пример #12
0
 /**
  * Hook 9: During action controller initialization.
  *
  * This hook is called in the constructor of the controller. Nothing is done and
  * $controller->init has not been called, so this is a good moment to change settings
  * that should influence $controller->init().
  *
  * Previous hook: preDispatch()
  * Actions since: $dispatcher->dispatch(); $controller->__construct()
  * Actions after: $controller->init(); ob_start(); $controller->dispatch()
  * Next hook: controllerBeforeAction()
  *
  * @param \Zend_Controller_Action $actionController
  * @return void
  */
 public function controllerInit(\Zend_Controller_Action $actionController = null)
 {
     $this->_copyVariables($actionController ? $actionController : $this->controllerAfterAction);
     $this->prepareController();
     $imgUrl = $this->getUtil()->getImageUri('datepicker.png');
     $jstUrl = $this->basepath->getBasePath() . '/gems/js';
     // Now set some defaults
     $dateFormOptions['dateFormat'] = 'dd-MM-yyyy';
     $dateFormOptions['description'] = $this->_('dd-mm-yyyy');
     $dateFormOptions['size'] = 10;
     if ($this->useBootstrap == true) {
         // Do not use a buttonImage, since we will use bootstrap add-on
         $basicOptions = array();
     } else {
         $basicOptions = array('buttonImage' => $imgUrl, 'showOn' => 'button');
     }
     $dateFormOptions['jQueryParams'] = $basicOptions + array('changeMonth' => true, 'changeYear' => true, 'duration' => 'fast');
     $datetimeFormOptions['dateFormat'] = 'dd-MM-yyyy HH:mm';
     $datetimeFormOptions['description'] = $this->_('dd-mm-yyyy hh:mm');
     $datetimeFormOptions['size'] = 16;
     $datetimeFormOptions['jQueryParams'] = $basicOptions + array('changeMonth' => true, 'changeYear' => true, 'duration' => 'fast', 'stepMinute' => 5, 'size' => 8, 'timeJsUrl' => $jstUrl);
     $timeFormOptions['dateFormat'] = 'HH:mm';
     $timeFormOptions['description'] = $this->_('hh:mm');
     $timeFormOptions['jQueryParams'] = $basicOptions + array('duration' => 'fast', 'stepMinute' => 5, 'size' => 8, 'timeJsUrl' => $jstUrl);
     \MUtil_Model_Bridge_FormBridge::setFixedOptions(array('date' => $dateFormOptions, 'datetime' => $datetimeFormOptions, 'time' => $timeFormOptions));
 }
Пример #13
0
 /**
  * A ModelAbstract->setOnLoad() function that takes care of transforming a
  * dateformat read from the database to a \Zend_Date format
  *
  * If empty or \Zend_Db_Expression (after save) it will return just the value
  * currently there are no checks for a valid date format.
  *
  * @see \MUtil_Model_ModelAbstract
  *
  * @param mixed $value The value being saved
  * @param boolean $isNew True when a new item is being saved
  * @param string $name The name of the current field
  * @param array $context Optional, the other values being saved
  * @param boolean $isPost True when passing on post data
  * @return \MUtil_Date|\Zend_Db_Expr|null
  */
 public function formatLoadDate($value, $isNew = false, $name = null, array $context = array(), $isPost = false)
 {
     static $formats;
     // If not empty or zend_db_expression and not already a zend date, we
     // transform to a \Zend_Date using the stored formats
     if (null === $value || $value instanceof \Zend_Date || $value instanceof \Zend_Db_Expr) {
         return $value;
     }
     if (!isset($formats[$name][$isPost])) {
         // Stored the used formats (as they are usually used often within a model)
         if ($isPost) {
             // Add possible custom format
             $formats[$name][$isPost][] = $this->_getKeyValue($name, 'dateFormat');
             // Add default format as a fallback
             $type = \MUtil_Date_Format::getDateTimeType($this->_getKeyValue($name, 'dateFormat'));
             $formats[$name][$isPost][] = \MUtil_Model_Bridge_FormBridge::getFixedOption($type, 'dateFormat');
         }
         $formats[$name][$isPost][] = $this->_getKeyValue($name, 'storageFormat');
     }
     return \MUtil_Date::ifDate($value, $formats[$name][$isPost]);
 }
 public function afterRegistry()
 {
     parent::afterRegistry();
     // Load the display dateformat
     $dateOptions = \MUtil_Model_Bridge_FormBridge::getFixedOptions('date');
     $this->_dateFormat = $dateOptions['dateFormat'];
     $this->creator = \Gems_Html::init();
     // find the menu items only once for more efficiency
     $this->_trackAnswer = $this->findMenuItem('track', 'answer');
     $this->_trackEdit = $this->findMenuItem('track', 'edit-track');
     $this->_trackDelete = $this->findMenuItem('track', 'delete-track');
     $this->_surveyAnswer = $this->findMenuItem('survey', 'answer');
     $this->_takeSurvey = $this->findMenuItem('ask', 'take');
 }
Пример #15
0
 /**
  * Returns an array of elements for check fields during password reset and/or
  * 'label name' => 'required value' pairs. vor asking extra questions before allowing
  * a password change.
  *
  * Default is asking for the username but you can e.g. ask for someones birthday.
  *
  * @return array Of 'label name' => 'required values' or \Zend_Form_Element elements
  */
 protected function loadResetPasswordCheckFields()
 {
     // CHECK ON SOMEONES BIRTHDAY
     // Birthdays are usually not defined for staff but the do exist for respondents
     if ($value = $this->_getVar('user_birthday')) {
         $label = $this->_('Your birthday');
         $birthdayElem = new \Gems_JQuery_Form_Element_DatePicker('birthday');
         $birthdayElem->setLabel($label)->setOptions(\MUtil_Model_Bridge_FormBridge::getFixedOptions('date'))->setStorageFormat(\Zend_Date::ISO_8601);
         if ($format = $birthdayElem->getDateFormat()) {
             $valueFormatted = \MUtil_Date::format($value, $format, $birthdayElem->getStorageFormat());
         } else {
             $valueFormatted = $value;
         }
         $validator = new \Zend_Validate_Identical($valueFormatted);
         $validator->setMessage(sprintf($this->_('%s is not correct.'), $label), \Zend_Validate_Identical::NOT_SAME);
         $birthdayElem->addValidator($validator);
         return array($birthdayElem);
     }
     // */
     return array($this->_('Username') => $this->getLoginName());
 }
 /**
  * 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;
 }
 /**
  * Get the date display format (zend style)
  *
  * @return string
  */
 protected function getDateFormat()
 {
     return \MUtil_Model_Bridge_FormBridge::getFixedOption('datetime', 'dateFormat');
 }
Пример #18
0
 /**
  * Converting the field value when saving to a respondent track
  *
  * @param array $currentValue The current value
  * @param array $fieldData The other values loaded so far
  * @return mixed the new value
  */
 public function onFieldDataSave($currentValue, array $fieldData)
 {
     if (null === $currentValue || $currentValue instanceof \Zend_Db_Expr || \MUtil_String::startsWith($currentValue, 'current_', true)) {
         return $currentValue;
     }
     $saveFormat = $this->getStorageFormat();
     if ($currentValue instanceof \Zend_Date) {
         return $currentValue->toString($saveFormat);
     } else {
         $displayFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         $returnDate = \MUtil_Date::format($currentValue, $saveFormat, $displayFormat);
         if (is_null($returnDate)) {
             if (\Zend_Date::isDate($currentValue, $saveFormat)) {
                 return $currentValue;
             }
         }
         return $returnDate;
     }
     return (string) $currentValue;
 }