Decode an timestamp attribute value for a widget value.

@param DecodePropertyValueForWidgetEvent $event The subscribed event.

@return void
322380
public function handleDecodePropertyValueForWidgetEvent(DecodePropertyValueForWidgetEvent $event)
    {
        $attribute = $this->getSupportedAttribute($event);
        if (!$attribute) {
            return;
        }

        $dispatcher = $event->getEnvironment()->getEventDispatcher();
        $value      = $event->getValue();

        if (\is_numeric($value)) {
            $dateEvent = new ParseDateEvent($value, $attribute->getDateTimeFormatString());
            $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);

            $event->setValue($dateEvent->getResult());
        }
    }
1243326
public function convertFieldValueFromForm($data)
    {
        if ($data instanceof DateTime) {
            return TimeValue::fromDateTime($data);
        }

        if (is_int($data)) {
            return new TimeValue($data);
        }

        return new TimeValue(null);
    }
1242949
public function onSaving($event, $payload)
    {
        list($model) = $payload;

        if (!$this->isEncodable($model)) {
            return;
        }

        foreach ($model->getDirtyEncodableAttributes() as $attribute) {

            // If the attribute has a value, encode the attribute
            if ($model->getAttribute($attribute)) {
                $model->encodeOnSave($attribute);
            }

            // Otherwise delete encoding references
            elseif ($encoding = $model->encoding($attribute)) {
                $encoding->delete();
            }
        }
    }
503805
public function valueChanged(ValueChangeEvent $event) {
    $object = $event->getObject();
    $name = $event->getValueName();
    $initialOid = $object->getProperty(self::PROPERTY_INITIAL_OID);
    if (isset($this->observedObjects[$initialOid])) {
      $newValue = $event->getNewValue();
      // make a criteria from newValue and make sure that all properties are set
      if (!($newValue instanceof Criteria)) {
        // LIKE fallback, if the value is not a Criteria instance
        $mapper = self::getMapper($object->getType());
        $pkNames = $mapper->getPkNames();
        if (!in_array($name, $pkNames)) {
          // use like condition on any attribute, if it's a string
          // other value changes will be ignored!
          if (is_string($newValue)) {
            $newValue = new Criteria($object->getType(), $name, 'LIKE', '%'.$newValue.'%');
          }
        }
        else {
          // don't search for pk names with LIKE
          $newValue = new Criteria($object->getType(), $name, '=', $newValue);
        }
      }
      else {
        // make sure that type and name are set even if the Criteria is constructed
        // via Criteria::forValue()
        $newValue->setType($object->getType());
        $newValue->setAttribute($name);
      }

      $oid = $object->getOID()->__toString();
      // store change in internal array to have it when constructing the query
      if (!isset($this->conditions[$oid])) {
        $this->conditions[$oid] = [];
      }
      $this->conditions[$oid][$name] = $newValue;
    }
  }
375404
public function evaluateAttributes($event)
    {
        if (in_array($event->name, $this->events)) {
            foreach ($this->attributes as $type => $attributes) {
                $method = 'get' . $type . 'value';
                if (method_exists($this, $method)) {
                    foreach ( (array) $attributes as $attribute) {
                        $this->owner->$attribute = $this->$method($this->owner->$attribute, $event->name);
                    }
                }
            }
        }
    }
857607
public function evaluateAttributes($event)
    {
        if (!empty($this->attributes[$event->name])) {
            $attributes = (array)$this->attributes[$event->name];
            if (strpos($event->name, 'after') !== false) {
                foreach ($attributes as $attribute) {
                    if (is_int($this->owner->$attribute)) {
                        $this->owner->$attribute = $this->owner->$attribute ? date($this->format, $this->owner->$attribute) : '';
                    }
                }
            } else if (strpos($event->name, 'before') !== false) {
                foreach ($attributes as $attribute) {
                    if (!is_numeric($this->owner->$attribute)) {
                        $date = \DateTime::createFromFormat($this->format, $this->owner->$attribute);
                        $this->owner->$attribute = $date ? $date->getTimestamp() : 0;
                    }
                }
            }
        }
    }
518964
public function fillExtraData(BuildWidgetEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if (($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute')
            || ($event->getProperty()->getName() !== 'translatedtabletext_cols')) {
            return;
        }

        $model         = $event->getModel();
        $metaModelName = $this->factory->translateIdToMetaModelName($event->getModel()->getProperty('pid'));
        $objMetaModel  = $this->factory->getMetaModel($metaModelName);
        $translator    = $event->getEnvironment()->getTranslator();

        // Check model and input for the cols and get the max value.
        $intModelCols = $model->getProperty('tabletext_quantity_cols');
        $intInputCols = $event->getEnvironment()->getInputProvider()->getValue('tabletext_quantity_cols');
        $intCols      = \max((int) $intModelCols, (int) $intInputCols);

        // For new models, we might not have a value.
        if (!$intCols) {
            return;
        }

        if (!($objMetaModel && $objMetaModel->isTranslated())) {
            return;
        }

        $attribute = $objMetaModel->getAttributeById($model->getProperty('id'));
        $arrValues = $attribute ? $attribute->get('name') : [];

        $languageEvent = new LoadLanguageFileEvent('languages');
        $this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $languageEvent);

        $arrLanguages = [];
        foreach ((array) $objMetaModel->getAvailableLanguages() as $strLangCode) {
            $arrLanguages[$strLangCode] = $translator->translate($strLangCode, 'LNG');
        }
        \asort($arrLanguages);

        // Ensure we have the values present.
        if (empty($arrValues)) {
            foreach ((array) $objMetaModel->getAvailableLanguages() as $strLangCode) {
                $arrValues[$strLangCode] = '';
            }
        }

        $arrRowClasses = [];
        foreach (\array_keys(\deserialize($arrValues)) as $strLangcode) {
            $arrRowClasses[] = ($strLangcode == $objMetaModel->getFallbackLanguage())
                ? 'fallback_language'
                : 'normal_language';
        }

        $data                                      = $event->getProperty()->getExtra();
        $data['minCount']                          = \count($arrLanguages);
        $data['maxCount']                          = \count($arrLanguages);
        $data['columnFields']['langcode']['label'] = $translator->translate(
            'name_langcode',
            'tl_metamodel_attribute'
        );

        $data['columnFields']['langcode']['options']            = $arrLanguages;
        $data['columnFields']['langcode']['eval']['rowClasses'] = $arrRowClasses;
        $data['columnFields']['rowLabels']['label']             = $translator->translate(
            'tabletext_rowLabels',
            'tl_metamodel_attribute'
        );

        $data['columnFields']['rowLabels']['eval']['minCount']                          = $intCols;
        $data['columnFields']['rowLabels']['eval']['maxCount']                          = $intCols;
        $data['columnFields']['rowLabels']['eval']['columnFields']['rowLabel']['label'] = $translator->translate(
            'tabletext_rowLabel',
            'tl_metamodel_attribute'
        );

        $data['columnFields']['rowLabels']['eval']['columnFields']['rowLabel']['eval']  = $arrRowClasses;
        $data['columnFields']['rowLabels']['eval']['columnFields']['rowStyle']['label'] = $translator->translate(
            'tabletext_rowStyle',
            'tl_metamodel_attribute'
        );

        $event->getProperty()->setExtra($data);
    }
685713
@UiHandler("m_dateModifiedStartDateBox")
    protected void onDateModifiedStartChange(ValueChangeEvent<Date> event) {

        if (event.getValue() != null) {
            m_tabHandler.setDateModifiedStart(event.getValue().getTime());
        } else {
            // if the field is empty take the min value
            m_tabHandler.setDateModifiedStart(-1L);
        }
    }
873391
protected function getValue($event)
    {
        if ($this->value === null && Yii::$app instanceof Application) {
            $ip = Yii::$app->request->userIP;
            if ($ip === null) {
                return $this->getDefaultValue($event);
            }
            return $ip;
        }
        return parent::getValue($event);
    }
1144327
public void assignTimestamp(XEvent event, long time) {
		XAttributeTimestamp attr = (XAttributeTimestamp) ATTR_TIMESTAMP.clone();
		attr.setValueMillis(time);
		event.getAttributes().put(KEY_TIMESTAMP, attr);
	}
172118
public function evaluateAttributes($event)
    {
        if (!empty($this->attributes[$event->name])) {
            $attributes = (array) $this->attributes[$event->name];
            foreach ($attributes as $attribute) {
                // ignore attribute names which are not string (e.g. when set by TimestampBehavior::updatedAtAttribute)
                if (is_string($attribute)) {
                    $value = $this->getValue($event, $attribute);
                    $this->owner->$attribute = $value;
                }
            }
        }
    }
241742
public function saveValues(EncodePropertyValueFromWidgetEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if (($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute')
            || ($event->getProperty() !== 'translatedtabletext_cols')) {
            return;
        }

        $metaModelName = $this->factory->translateIdToMetaModelName($event->getModel()->getProperty('pid'));
        $objMetaModel  = $this->factory->getMetaModel($metaModelName);
        $varValue      = $event->getValue();

        // Not translated, make it a plain string.
        if (!$objMetaModel->isTranslated()) {
            $event->setValue(\serialize($varValue));

            return;
        }

        $arrLangValues = \deserialize($varValue);
        $arrOutput     = [];

        foreach ($arrLangValues as $varSubValue) {
            $strLangCode = $varSubValue['langcode'];
            unset($varSubValue['langcode']);
            if (\count($varSubValue) > 1) {
                $arrOutput[$strLangCode] = $varSubValue;
            } else {
                $arrKeys = \array_keys($varSubValue);

                $arrOutput[$strLangCode] = $varSubValue[$arrKeys[0]];
            }
        }

        $event->setValue(\serialize($arrOutput));
    }
572409
public function setTimestampsOnNodeForPersist(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$this->supports($document)) {
            return;
        }

        $this->setTimestampsOnNode(
            $document,
            $event->getNode(),
            $event->getAccessor(),
            $this->documentInspector->getOriginalLocale($document),
            new \DateTime()
        );
    }
1052451
private static function renderDateTimeValueInstance($event, $value)
    {
        if (!($value instanceof \DateTime)) {
            return;
        }

        $dispatcher = $event->getEnvironment()->getEventDispatcher();

        $event->setRendered(
            self::parseDateTime($dispatcher, self::getConfig()->get('datimFormat'), $value->getTimestamp())
        );
    }
653344
public function convertFileSourceToUuid(EncodePropertyValueFromWidgetEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $propertiesDefinition = $event->getEnvironment()->getDataDefinition()->getPropertiesDefinition();
        $property             = $propertiesDefinition->getProperty($event->getProperty());


        if (!\array_key_exists('rte', $property->getExtra())
            || (0 !== \strpos($property->getExtra()['rte'], 'tiny'))
        ) {
            return;
        }

        $event->setValue(
            StringUtil::srcToInsertTag($event->getValue())
        );
    }
38437
public function col_time($event) {

        if (empty($this->download)) {
            $dateformat = get_string('strftimedatetime', 'core_langconfig');
        } else {
            $dateformat = get_string('strftimedatetimeshort', 'core_langconfig');
        }
        return userdate($event->timecreated, $dateformat);
    }
345086
protected function decodeIntervalSpec(): void
    {
        $this->di = new DateInterval($this->expression);
        $this->time = (new DateTime('@0'))
            ->add($this->di)
            ->getTimestamp();
    }