/** * Determines the value for the element in the form view * * @param array $data Form data * @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 */ public function getValue($data, $repeatCounter = 0, $opts = array()) { $v = parent::getValue($data, $repeatCounter, $opts); // $$$ rob see http://fabrikar.com/forums/showthread.php?t=25965 if (is_array($v) && count($v) == 1) { $v = $v[0]; } return $v; }
/** * Determines the value for the element in the form view * * @param array $data Form data * @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 */ public function getValue($data, $repeatCounter = 0, $opts = array()) { $value = parent::getValue($data, $repeatCounter, $opts); $value = FabrikWorker::JSONtoData($value); if (is_string($value)) { // New record or failed validation $value = trim($value); $value = $value === '' ? array() : explode(',', $value); } return $value; }
/** * 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; }
/** * 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(); $input = JFactory::getApplication()->input; 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 = JArrayHelper::getValue($value, 'date', JArrayHelper::getValue($value, 0)); } if ($input->get('task') == 'form.process') { // Don't mess with posted value - can cause double offsets - instead do in _indStoareDBFormat(); return $value; } if (!($formModel->isNewRecord() && $defaultToday) && $value == '') { if (($value == '' || $db->getNullDate() == $value) && !$alwaysToday) { return $value; } if ($alwaysToday && $formModel->isEditable()) { $value = ''; } } // Don't offset if null date. if ($value === $db->getNullDate()) { return $value; } $timeZone = new DateTimeZone(JFactory::getConfig()->get('offset')); $date = JFactory::getDate($value, $timeZone); // 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; }