Returns value from model for given element.

@param \Illuminate\Database\Eloquent\Model $model
@param NamedFormElement $el

@return mixed|null
8838
protected function getElementValue(Model $model, NamedFormElement $el)
    {
        $attribute = $el->getModelAttributeKey();
        if (strpos($attribute, '->') === false) {
            return $model->getAttribute($attribute);
        }

        // Parse json attributes
        $casts = collect($model->getCasts());
        $jsonParts = collect(explode('->', $attribute));
        $cast = $casts->get($jsonParts->first(), false);

        if (! in_array($cast, ['json', 'array'])) {
            return;
        }

        $jsonAttr = $model->{$jsonParts->first()};

        return array_get($jsonAttr, $jsonParts->slice(1)->implode('.'));
    }
1184899
public FormElementController getElement(String name) {
        for (FormSectionController section : getSections()) {
            FormElementController element = section.getElement(name);
            if (element != null) {
                return element;
            }
        }
        return null;
    }
1026838
public static function fromASN1(UnspecifiedType $el): self
    {
        if (!$el->isTagged()) {
            throw new \UnexpectedValueException("v1Form issuer not supported.");
        }
        $tagged = $el->asTagged();
        switch ($tagged->tag()) {
            case 0:
                return V2Form::fromV2ASN1(
                    $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
        }
        throw new \UnexpectedValueException("Unsupported issuer type.");
    }
780267
public function getModel($table, $name, $value)
    {
        //get the row
        $result = $this->getRow($table, $name, $value);

        if (is_null($result)) {
            return null;
        }

        return $this->model()->setTable($table)->set($result);
    }
887390
public function getReservation($name)
    {
        if (array_key_exists($name, $this->reservations)) {
            return $this->reservations[$name];
        }

        throw new InvalidElementException("Element '{$name}' does not exist");
    }
1199157
public function getJointParent($model, $includeSelf = false)
    {
        if ( is_numeric($model) ) {
            $model = call_user_func("$this->ownerClassName::findOne", $model);
        }
        if ( $this->owner->{$this->parentIdField} == $model->{$this->parentIdField} ) {
            return $this->getParent();
        }
        $ownerParents = $this->owner->getParents($includeSelf)->all();
        $modelParents = $model->getParents($includeSelf)->all();
        $jointParent = false;
        foreach ( $ownerParents as $idx => $parent ) {
            if ( isset($modelParents[$idx]) && $parent->{$this->primaryKey} == $modelParents[$idx]->{$this->primaryKey} ) {
                $jointParent = $parent;
            } else {
                break;
            }
        }
        return $jointParent;
    }
21124
public function getElements($element_name, $modificator_name = null, $modificator_value = null)
	{
		$locator = $this->_locator->getElementLocator(
			$element_name,
			$this->getName(),
			$modificator_name,
			$modificator_value
		);

		return $this->findAll('se', $locator);
	}
356379
public function setModel(\atk4\data\Model $model)
    {
        parent::setModel($model);
        $this->field = $this->field ? $this->field : $this->model->title_field;
        if ($this->autoSave && $this->model->loaded()) {
            if ($this->cb->triggered()) {
                $value = $_POST['value'] ? $_POST['value'] : null;
                $this->cb->set(function () use ($value) {
                    try {
                        $this->model[$this->field] = $this->app->ui_persistence->typecastLoadField($this->model->getElement($this->field), $value);
                        $this->model->save();

                        return $this->jsSuccess('Update successfully');
                    } catch (ValidationException $e) {
                        $this->app->terminate(json_encode([
                              'success'            => true,
                              'hasValidationError' => true,
                              'atkjs'              => $this->jsError(call_user_func($this->formatErrorMsg, $e, $value))->jsRender(),
                          ]));
                    }
                });
            }
        }

        return $this->model;
    }
1359453
public static String getAttrVal(final Element el, final String name)
      throws SAXException {
    Attr at = el.getAttributeNode(name);
    if (at == null) {
      return null;
    }

    return at.getValue();
  }
396267
protected function _inferRelation($model, $name)
    {
        if (in_array($name . '_id', $model->getFields(), true)) {
            $referenceName = $this->_inferClassName($model, $name);
            return $referenceName ? [$referenceName, Relation::TYPE_HAS_ONE] : false;
        }

        if (preg_match('#^(.+[a-z\d])Of([A-Z].*)$#', $name, $match)) {
            if (!$singular = $this->_pluralToSingular($match[1])) {
                return false;
            }

            if (!$referenceName = $this->_inferClassName($model, $singular)) {
                return false;
            }

            $valueField = lcfirst($match[2]) . '_id';
            if (in_array($valueField, $model->getForeignKeys(), true)) {
                /** @var \ManaPHP\Model $reference */
                $reference = new $referenceName;
                return [$referenceName, Relation::TYPE_HAS_MANY_TO_MANY, $reference->getPrimaryKey(), $valueField];
            } else {
                return false;
            }
        }

        if ($singular = $this->_pluralToSingular($name)) {
            if (!$referenceName = $this->_inferClassName($model, $singular)) {
                return false;
            }

            /** @var \ManaPHP\Model $reference */
            $reference = new $referenceName;

            $keys = $model->getForeignKeys();
            if (count($keys) === 2) {
                $foreignKey = $singular . '_id';
                if (in_array($foreignKey, $keys, true)) {
                    $keys = array_flip($keys);
                    unset($keys[$foreignKey]);
                    return [$referenceName, Relation::TYPE_HAS_MANY_TO_MANY, $reference->getPrimaryKey(), key($keys)];
                }
            }
            if (in_array($model->getPrimaryKey(), $reference->getFields(), true)) {
                return [$referenceName, Relation::TYPE_HAS_MANY];
            } else {
                $r1Name = substr($referenceName, strrpos($referenceName, '\\') + 1);

                $modelName = get_class($model);
                $pos = strrpos($modelName, '\\');
                $baseName = substr($modelName, 0, $pos + 1);
                $r2Name = substr($modelName, $pos + 1);

                $tryViaName = $baseName . $r1Name . $r2Name;
                if (class_exists($tryViaName)) {
                    return [$referenceName, Relation::TYPE_HAS_MANY_VIA, $tryViaName, $model->getPrimaryKey()];
                } else {
                    $tryViaName = $baseName . $r2Name . $r1Name;
                    if (!class_exists($tryViaName)) {
                        throw new RuntimeException(['infer `:relation` relation failed', 'relation' => $name]);
                    }

                    return [$referenceName, Relation::TYPE_HAS_MANY_VIA, $tryViaName, $model->getPrimaryKey()];
                }
            }
        }

        return false;
    }
1366477
public function getValue($model, $data)
    {
        /** @type Model $model */
        $model = $this->add($this->getModel());
        $id = $data[$this->foreignName];

        try {

            $this->hook('beforeForeignLoad', array($model, $id));

            $model->load($id);
            $titleField = $model->getTitleField();

            return $model->get($titleField) ?: 'Ref#'.$id;
        } catch (BaseException $e) {
            // record is no longer there it seems
            return null;
        }
    }
764562
public function getQuery($model, $name, $data)
    {
        $relation = $this->get($model, $name);
        /** @var \ManaPHP\Model $referenceModel */
        $referenceModel = $relation->referenceModel;
        $query = $referenceModel::query();

        if ($data === null) {
            null;
        } elseif (is_string($data)) {
            $query->select($data);
        } elseif (is_array($data)) {
            if ($data) {
                if (isset($data[count($data) - 1])) {
                    $query->select(count($data) > 1 ? $data : $data[0]);
                } elseif (isset($data[0])) {
                    $query->select($data[0]);
                    unset($data[0]);
                    $query->where($data);
                } else {
                    $query->where($data);
                }
            }
        } elseif (is_callable($data)) {
            $query = $data($query);
        } else {
            throw new InvalidValueException(['`:with` with is invalid', 'with' => $name]);
        }

        return $query;
    }
371917
protected function insertModelBeforeElement(Model &$model, Model &$element)
    {
        if ($element->isNew())
            throw new Exception('Target model should be saved before insert');

        $element->refreshTreeColumns();

        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $this->expandTreeBeforeElement($element, $model->getTreeWidth());

        if (!$model->isNew()) {

            $model->refreshTreeColumns();
            $diff = $element->__lft - $model->__lft;
            $lvldiff = $element->__lvl - $model->__lvl;

            $query = (new Query())
                ->update()
                ->table($tableName)
                ->values([
                    '__lft' => '__lft + :diff',
                    '__rgt' => '__rgt + :diff',
                    '__lvl' => '__lvl + :lvldiff',
                    '__prt' => 'CASE WHEN __id=:id THEN :parentid ELSE __prt END',
                ])
                ->where('__lft>=:lft AND __rgt<=:rgt')
                ->params([':id' => $model->getPk(), 'parentid'=>$element->__prt, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':diff' => $diff, ':lvldiff' => $lvldiff]);
            $connection->execute($query);

            $this->removeFromTreeByElement($model);

        } else {
            // TODO: этот вариант тоже рассмотреть
            throw new Exception('Save this model before move');
        }

        // TODO: рассчитывать
        $model->refreshTreeColumns();
        $element->refreshTreeColumns();

    }
360467
protected function dispatchEventWithModel($name, Model $model)
    {
        $this->pool->eventService->dispatch(
            static::$eventPrefix . '::' . $name,
            $this,
            $model
        );

        return $model;
    }
528823
public function retrieve(Model $model, $source)
    {
        $this->model = $model;

        if ($this->isTranslated()) {

            $keys      = [];
            $localeKey = config('translatable.locale_key', 'locale');

            foreach ($model->translations as $translation) {
                /** @var Relation $relation */
                $relation = $translation->{$source}();

                $keys[ $translation->{$localeKey} ] = $this->getValueFromRelationQuery($relation);
            }

            return $keys;
        }

        $relation = $this->resolveModelSource($model, $source);

        if ( ! ($relation instanceof Relation)) {
            throw new UnexpectedValueException(
                "{$source} did not resolve to a relation for " . get_class($this) . " on " . get_class($model)
            );
        }

        try {
            return $this->getValueFromRelationQuery($relation);

        } catch (\Exception $e) {

            throw new RuntimeException(
                "Exception retrieving relation values for source '{$source}' "
                . "for form field key '{$this->formFieldData->key}'",
                0,
                $e
            );
        }
    }
789003
protected function getModelValueAttribute($model, $name)
    {
        $transformedName = $this->transformKey($name);
        if (is_string($model)) {
            return $model;
        } elseif (is_object($model)) {
            return object_get($model, $transformedName);
        } elseif (is_array($model)) {
            return Arr::get($model, $transformedName);
        }
    }
62358
def get_element_by_name(self, el_name, el_idx=0):
        
        el_list = self.get_element_list_by_name(el_name)
        try:
            return el_list[el_idx]
        except IndexError:
            raise SimpleXMLWrapperException(
                'Element not found. element_name="{}" requested_idx={} '
                'available_elements={}'.format(el_name, el_idx, len(el_list))
            )