Example #1
0
 /**
  * Get the GMT Date time - tz offset applied in render() if needed
  *
  * @param   array $data          Form data date will be GMT if store as local OFF, otherwise as local time
  * @param   int   $repeatCounter When repeating joined groups we need to know what part of the array to access
  * @param   array $opts          Options
  *
  * @return  string    value  Date as GMT time
  */
 public function getValue($data, $repeatCounter = 0, $opts = array())
 {
     $params = $this->getParams();
     $alwaysToday = $params->get('date_alwaystoday', false);
     $defaultToday = $params->get('date_defaulttotoday', false);
     $formModel = $this->getFormModel();
     $value = parent::getValue($data, $repeatCounter, $opts);
     $db = FabrikWorker::getDbo();
     if (is_array($value)) {
         // Submission posted as array but date & time in date key. Can be keyed to 0 if parent class casts string to array.
         $value = FArrayHelper::getValue($value, 'date', FArrayHelper::getValue($value, 0));
     }
     // in some corner cases, date will be db name quoted, like in CSV export after an advanced search!
     $value = trim($value, "'");
     //if ($input->get('task') == 'form.process' || ($app->isAdmin() && $input->get('task') == 'process'))
     if (FabrikWorker::inFormProcess()) {
         // Don't mess with posted value - can cause double offsets - instead do in _indStoareDBFormat();
         return $value;
     }
     // Element could be a date element (in which case no time stored) - check for both datetime and date null dates.
     $nullDate = $db->getNullDate();
     $shortNullDate = explode(' ', $nullDate);
     $shortNullDate = FArrayHelper::getValue($shortNullDate, 0);
     $isNullDate = $nullDate == $value || $shortNullDate == $value;
     if (!(($formModel->isNewRecord() || $this->newGroup) && $defaultToday) && $value == '') {
         if (($value == '' || $isNullDate) && !$alwaysToday) {
             return $value;
         }
         if ($alwaysToday && $formModel->isEditable()) {
             $value = '';
         }
     }
     // Don't offset if null date.
     if ($isNullDate) {
         return $value;
     }
     $timeZone = new DateTimeZone($this->config->get('offset'));
     $date = JFactory::getDate($value, $timeZone);
     // Querystring value passed into new record
     if ($formModel->isNewRecord() && $value !== '') {
         // OK for : Default to current  = no Local time = yes
         if (!$defaultToday) {
             $date = new DateTime($date, $timeZone);
             return $date->format('Y-m-d H:i:s');
         }
         // Ok for : Default to current = yes, Local time = yes OR no
         $date = new DateTime($date, $timeZone);
         $date->setTimeZone(new DateTimeZone('UTC'));
         return $date->format('Y-m-d H:i:s');
     }
     // If value = '' don't offset it (not sure what the logic is but testing seems to indicate this to be true)
     $local = $formModel->hasErrors() || $value == '' || $params->get('date_store_as_local', 0) == 1 ? false : true;
     $value = $date->toSQL($local);
     return $value;
 }