@param array  $data
@param string $current_value

@return string
@throws \ManaPHP\Exception\MissingFieldException
429181
protected function _render_radio($data, $current_value)
    {
        if (isset($data['name'])) {
            $name = $data['name'];
        } else {
            throw new MissingFieldException('name');
        }

        if (isset($data['values'])) {
            $values = $data['values'];
        } else {
            throw new MissingFieldException('values');
        }

        $r = PHP_EOL;
        /** @noinspection ForeachSourceInspection */
        foreach ($values as $value => $label) {
            /** @noinspection TypeUnsafeComparisonInspection */
            $checked = ($current_value === '' && $value === '') || ($current_value !== '' && $value == $current_value);
            $r .= '  <label><input type="radio"'
                . " name=\"$name\" value=\"$value\" "
                . ($checked ? 'checked="checked"' : '')
                . '/><span>' . htmlspecialchars($label) . '</span></label>' . PHP_EOL;

        }

        return $r;
    }
884761
private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context)
    {
        if (null === $types = $this->getTypes($currentClass, $attribute)) {
            return $data;
        }

        $expectedTypes = [];
        foreach ($types as $type) {
            if (null === $data && $type->isNullable()) {
                return;
            }

            if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) {
                $builtinType = Type::BUILTIN_TYPE_OBJECT;
                $class = $collectionValueType->getClassName().'[]';

                // Fix a collection that contains the only one element
                // This is special to xml format only
                if ('xml' === $format && !\is_int(key($data))) {
                    $data = [$data];
                }

                if (null !== $collectionKeyType = $type->getCollectionKeyType()) {
                    $context['key_type'] = $collectionKeyType;
                }
            } else {
                $builtinType = $type->getBuiltinType();
                $class = $type->getClassName();
            }

            $expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;

            if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
                if (!$this->serializer instanceof DenormalizerInterface) {
                    throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer', $attribute, $class));
                }

                $childContext = $this->createChildContext($context, $attribute, $format);
                if ($this->serializer->supportsDenormalization($data, $class, $format, $childContext)) {
                    return $this->serializer->denormalize($data, $class, $format, $childContext);
                }
            }

            // JSON only has a Number type corresponding to both int and float PHP types.
            // PHP's json_encode, JavaScript's JSON.stringify, Go's json.Marshal as well as most other JSON encoders convert
            // floating-point numbers like 12.0 to 12 (the decimal part is dropped when possible).
            // PHP's json_decode automatically converts Numbers without a decimal part to integers.
            // To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when
            // a float is expected.
            if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && false !== strpos($format, JsonEncoder::FORMAT)) {
                return (float) $data;
            }

            if (('is_'.$builtinType)($data)) {
                return $data;
            }
        }

        if ($context[self::DISABLE_TYPE_ENFORCEMENT] ?? $this->defaultContext[self::DISABLE_TYPE_ENFORCEMENT] ?? false) {
            return $data;
        }

        throw new NotNormalizableValueException(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), \gettype($data)));
    }
430704
protected function prepare_submitted_data( $fields, array $data, $clear_missing ) {
		$submitted = [];

		foreach ( $fields as $field ) {
			if ( $this->maybe_skip_field( $field ) ) {
				continue;
			}

			$value = array_key_exists( $field->get_id(), $data )
				? $data[ $field->get_id() ]
				: null;

			// Treat false as NULL to support binding false to checkboxes.
			// Don't convert NULL to a string here in order to determine later
			// whether an empty value has been submitted or whether no value has
			// been submitted at all. This is important for processing checkboxes
			// and radio buttons with empty values.
			if ( false === $value ) {
				$value = null;
			} elseif ( is_scalar( $value ) ) {
				$value = (string) $value;
			}

			// Perform the sanitization to get sanitized value.
			$sanitized = $field->get_sanitization_value( $value );

			if ( $field->is_group() ) {
				$submitted[ $field->get_id() ] = $this->get_group_values( $field, $sanitized );
			} else {
				$submitted[ $field->get_id() ] = $sanitized;
			}
		}

		// Clear "null" input data.
		if ( $clear_missing ) {
			$submitted = array_filter( $submitted, function ( $value ) {
				return ! is_null( $value );
			} );
		}

		return $submitted;
	}
390307
public function checkbox ($current_rule = [], $label_list = [], $value = '1') {
		$is_array = is_array($label_list) && !empty($label_list);
		return array_merge([
		'null_skip'	=> true,
			['require', 'raise_exception' => true],
			['not_string_empty', 'is_last' => true],
		],
		$is_array ? [
			['key', $label_list, 'is_array' => true, 'array_keys' => true, 'raise_exception' => true],
			['==', $value, 'is_array' => $is_array, 'raise_exception' => true],
		] : [
			['==', $value, 'is_array' => $is_array, 'raise_exception' => true],
		], $is_array ? $this->adjustOption($current_rule, 'is_array', $is_array) : $current_rule);
	}
1307662
protected function UFUpdate(array $data)
    {
        $return = [];
        global $USER_FIELD_MANAGER;
        if (empty($data['FIELD_NAME'])) {
            throw new Exception('You must set group FIELD_NAME');
        }
        if (empty($data['ENTITY_ID'])) {
            throw new Exception('You must set group ENTITY_ID');
        }
        if ($id = $this->UFGetIdByCode($data['ENTITY_ID'], $data['FIELD_NAME'])) {
            $ib = new CUserTypeEntity();
            $id = $ib->Update($id, $data);
            if ($id) {
                $return[] = "Update {$data['FIELD_NAME']} user field";
                if (
                    !empty($data['LIST'])
                    && ($arType = $USER_FIELD_MANAGER->GetUserType($data['USER_TYPE_ID']))
                    && $arType['BASE_TYPE'] == 'enum'
                ) {
                    $obEnum = new CUserFieldEnum();
                    $res = $obEnum->SetEnumValues($id, $data['LIST']);
                    $return[] = "Update {$data['FIELD_NAME']} user field list";
                }
            } else {
                throw new Exception("Can't update {$data['FIELD_NAME']} user field");
            }
        } else {
            throw new Exception("Can't find {$data['FIELD_NAME']} user field");
        }

        return $return;
    }
1223559
public function update(array $data)
    {
        // validate email address
        if (!empty($data['email_address']) &&
                !filter_var($data['email_address'], FILTER_VALIDATE_EMAIL)) {
            throw new Exception(
                'Invalid value for field email_address'
            );
        }
        $project_id = empty($data['project_id']) ? 0 : $data['project_id'];
        $permissions = empty($data['permissions']) ? null :
                                                (array) $data['permissions'];
        unset($data['project_id'], $data['permissions']);
        $save = false;
        if (!empty($data)) {
            $save = parent::update($data);
        }
        // add permission to project
        if ($project_id) {
            $permission = \TeamWorkPm\Factory::build('project/people');
            try {
                $add = $permission->add($project_id, $data['id']);
            } catch (Exception $e) {
                $add = $e->getMessage() == 'User is already on project';
            }
            $save = $save && $add;
            if ($add && $permissions) {
                $permissions['person_id']  = $data['id'];
                $permissions['project_id'] = $project_id;
                $save = $permission->update($permissions);
            }
        }
        return $save;
    }
18085
public function setFormValues($data = null)
    {
        if ($data === null) {
            $data = $this->getSaveData();
        }

        /*
         * Fill the model as if it were to be saved
         */
        $this->prepareModelsToSave($this->model, $data);

        /*
         * Data set differs from model
         */
        if ($this->data !== $this->model) {
            $this->data = (object) array_merge((array) $this->data, (array) $data);
        }

        /*
         * Set field values from data source
         */
        foreach ($this->allFields as $field) {
            $field->value = $this->getFieldValue($field);
        }

        return $data;
    }
566505
protected function prepareCurrentRow(): void
    {
        $this->currentRow = array_shift($this->bufferedRow);
        if (\is_array($this->currentRow)) {
            $datas = [];
            foreach ($this->currentRow as $key => $value) {
                if ($this->hasHeaders) {
                    $datas[$this->columns[$key]] = html_entity_decode($value);
                } else {
                    $datas[$key] = html_entity_decode($value);
                }
            }
            $this->currentRow = $datas;
        }
    }
857341
protected function getFieldValue($field_name, array $results, $delimiter = '.')
    {
        // Progress the results if the field name is using a delimiter.
        foreach (explode($delimiter, $field_name) as $name) {
            if (isset($results[$name])) {
                $results = $results[$name];
            }
        }

        return !empty($results) ? $results : null;
    }
272228
public function createUpdateQuery(array $field_data)
    {
        return $this->getQueryFactory()
                    ->createUpdateQuery($this->tableName, $field_data[self::BASE]['id'], $field_data[self::MODIFIED]);
    }
968652
public static function updateOrNull($data = null)
    {
        static $request;
        if (!$request) {
            $request = Di::getDefault()->getShared('request');
        }

        if (!$request->isPost() && !$request->isPut() && !$request->isPatch()) {
            return null;
        }

        $model = new static;

        $pkName = $model->getPrimaryKey();

        $_request = $request->get();

        $instance = static::get(isset($data[$pkName]) ? $data[$pkName] : $request->getId($pkName));

        if ($data === null || !isset($data[0])) {
            foreach ($model->getSafeFields() as $field) {
                if (isset($_request[$field])) {
                    $instance->$field = $_request[$field];
                }
            }
        }

        if ($data) {
            foreach ($data as $k => $v) {
                if (is_int($k)) {
                    $field = $v;
                    if (!isset($_request[$field])) {
                        throw new MissingFieldException($field);
                    }
                    $instance->$field = $_request[$field];
                } else {
                    $instance->$k = $v;
                }
            }
        }

        return $instance->update();
    }
271177
protected function setImage(array $data, $field_value_id = null)
    {
        if (!empty($data['images']) && !empty($field_value_id)) {
            $this->file->delete(array('entity' => 'field_value', 'entity_id' => $field_value_id));
        }

        return $this->setImages($data, $this->file, 'field_value');
    }
683440
public function calculateFieldInfo($currentValue, array $fieldData)
    {
        if (! $currentValue) {
            return $currentValue;
        }

        $agenda      = $this->loader->getAgenda();
        $appointment = $agenda->getAppointment($currentValue);

        if ($appointment && $appointment->isActive()) {
            $time = $appointment->getAdmissionTime();

            if ($time) {
                return $time->toString($this->appointmentTimeFormat);
            }
        }

        return null;
    }
1235484
static public function formatValue($field, $field_value=null)
    {
        $methods = [];
        if (isset($field['data_format']) && $field['data_format']) {
            $methods[] = $field['data_format'];
        }
        $methods[] = $field['field_name'];
        if (isset($field['base_type']) && $field['base_type']) {
            $methods[] = $field['base_type'];
        }
        $methods[] = $field['data_type'];
        
        foreach ($methods as $m) {
            if (method_exists(get_called_class(), $m)) {
                return static::$m($field_value);
            }
        }
        
        $data_type = strtolower($field['data_type']);
        if (preg_match('/int/', $data_type)) {
            $field_value = intval($field_value);
        } else {
            $field_value = static::output($field_value);
        }
        
        return $field_value;
    }
549870
public function resolve(array $data): FieldGeneratorInterface
    {
        $generator = NULL;
        foreach ($this->fieldValueGenerators as $fieldValueGenerator) {
            $generator = GeneralUtility::makeInstance($fieldValueGenerator);
            if (!$generator instanceof FieldGeneratorInterface) {
                throw new Exception(
                    'Field value generator ' . $fieldValueGenerator . ' must implement FieldGeneratorInterface',
                    1457693564
                );
            }
            if ($generator->match($data)) {
                break;
            } else {
                $generator = null;
            }
        }
        if (is_null($generator)) {
            throw new GeneratorNotFoundException(
                'No generator found',
                1457873493
            );
        }
        return $generator;
    }
1273476
public function __fromArray(array $data): void
    {
        $hasArrayAccess = $this instanceof \ArrayAccess;
        foreach ($data as $name => $value) {
            $currentValue = null;
            $currentValueIsSet = false;
            $isReadOnly = false;
            if (isset($this->internalDataObjectData['p' . $name])) {
                $propertyData = $this->internalDataObjectData['p' . $name];
                $valueIsSet = false;
                if (isset($propertyData[6])) { // type
                    $type = $propertyData[6];
                    $isNullable = $type[0] === '?';
                    if ($isNullable) {
                        $type = substr($type, 1);
                    }
                } else {
                    $type = null;
                    $isNullable = true;
                }
                if (isset($propertyData[5])) { // readonly
                    $currentValue = $this->$name;
                    $currentValueIsSet = true;
                    $isReadOnly = true;
                } elseif (isset($propertyData[1])) { // init
                    $currentValue = $this->$name;
                    $currentValueIsSet = true;
                } elseif ($type !== null && $type !== 'array' && $type !== 'float' && $type !== 'int' && $type !== 'string') {
                    if ($value !== null) {
                        if (class_exists($type)) {
                            if (is_callable([$type, 'fromArray'])) {
                                if (is_array($value)) {
                                    $value = call_user_func([$type, 'fromArray'], $value);
                                    $valueIsSet = true;
                                } else {
                                    throw new \Exception('Cannot assing value of type ' . gettype($value) . ' to an object!');
                                }
                            } else {
                                $currentValue = new $type();
                                $currentValueIsSet = true;
                            }
                        } else {
                            throw new \Exception('Cannot find class named ' . $type . ' for property ' . $name . '!');
                        }
                    } else {
                        if ($isNullable) {
                            $value = null;
                            $valueIsSet = true;
                        } else {
                            throw new \Exception('The property ' . $name . ' value cannot be null!');
                        }
                    }
                }
                if (!$currentValueIsSet && isset($propertyData[0])) { // default init
                    $currentValue = $this->$name;
                }
                if (!$valueIsSet && is_object($currentValue)) {
                    if (method_exists($currentValue, '__fromArray')) {
                        $currentValue->__fromArray($value);
                    } elseif ($type === 'DateTime') {
                        $currentValue->setTimestamp(strtotime($value));
                    } else {
                        if (is_array($value)) {
                            $_hasArrayAccess = $currentValue instanceof \ArrayAccess;
                            foreach ($value as $_name => $_value) {
                                if ($_hasArrayAccess) {
                                    $currentValue[$_name] = $_value;
                                } else {
                                    $currentValue->$_name = $_value;
                                }
                            }
                        } else {
                            throw new \Exception('Cannot assing value of type ' . gettype($value) . ' to an object!');
                        }
                    }
                    $value = $currentValue;
                }
            }
            if (!$isReadOnly) {
                if ($hasArrayAccess) {
                    $this[$name] = $value;
                } else {
                    $this->$name = $value;
                }
            }
        }
    }
348755
protected function _value($data)
    {
        $field = $this->config('name');
        $value = $data[$field];
        if (empty($value) && $this->_defaultDefined()) {
            $value = $this->config('default');
        }

        return $value;
    }