is_date_only = $is_date_only; $this ->setDefault(self::DEFAULT_VALUE) ->setSaveType(ZBX_WIDGET_FIELD_TYPE_STR) ->setMaxLength(255); } public function setFlags(int $flags): self { parent::setFlags($flags); $validation_rules = $this->getValidationRules(); $validation_rules['flags'] = $validation_rules['flags'] ?? 0x00; if (($flags & self::FLAG_NOT_EMPTY) !== 0) { $validation_rules['flags'] |= API_NOT_EMPTY; } else { $validation_rules['flags'] &= 0xFF ^ API_NOT_EMPTY; } $this->setValidationRules($validation_rules); return $this; } public function validate(bool $strict = false): array { if ($errors = parent::validate($strict)) { return $errors; } $label = $this->full_name ?? $this->label ?? $this->name; $value = $this->value ?? $this->default; if ($value === '' && ($this->getFlags() & self::FLAG_NOT_EMPTY) === 0) { $this->setValue(''); return []; } $absolute_time_parser = new CAbsoluteTimeParser(); if ($absolute_time_parser->parse($value) == CParser::PARSE_SUCCESS) { $has_errors = false; if ($this->is_date_only) { $has_errors = $absolute_time_parser->getDateTime(true)->format('H:i:s') !== '00:00:00'; } if (!$has_errors) { $this->setValue($value); return []; } } $relative_time_parser = new CRelativeTimeParser(); if ($relative_time_parser->parse($value) == CParser::PARSE_SUCCESS) { $has_errors = false; if ($this->is_date_only) { foreach ($relative_time_parser->getTokens() as $token) { if ($token['suffix'] === 'h' || $token['suffix'] === 'm' || $token['suffix'] === 's') { $has_errors = true; break; } } } if (!$has_errors) { $this->setValue($value); return []; } } $this->setValue($this->default); return [ _s('Invalid parameter "%1$s": %2$s.', $label, $this->is_date_only ? _('a date is expected') : _('a time is expected') ) ]; } }