Enriches a single export column and saves the data.

@param ModelExportColumnDataInterface $column
@param string                       $key
@param array                        $columns     by reference, data array to build, updated with enriched data
16938
protected function enrichColumn($key, ModelExportColumnDataInterface $column, array &$columns)
    {
        // Check if we can enrich, if we must.
        if ( ! isset($this->info->attributes[ $key ])) {

            // if the column data is fully set, no need to enrich
            if ($this->isExportColumnDataComplete($column)) {
                $columns[ $key ] = $column;
                return;
            }

            throw new UnexpectedValueException(
                "Incomplete data for for export column key that does not match known model attribute or relation method. "
                . "Requires at least 'source' value."
            );
        }


        $attributeColumnInfo = $this->makeModelExportColumnDataForAttributeData($this->info->attributes[ $key ]);

        $attributeColumnInfo->merge($column);

        $columns[ $key ] = $attributeColumnInfo;
    }
1111303
public function setColumns( $columns ){
		if( !( is_array( $columns ) && count( $columns ) ) )
			throw new \InvalidArgumentException( 'Column array must not be empty' );
		$this->columns = $columns;
	}
1038054
protected function getTransfredFields(array $columns)
    {
        $collection = [];

        foreach ($columns as $column) {
            // While constructing the array for each field
            // there is no need to set translations for options
            // or even labels. This step is handled using the FieldTransformer
            $properties['name'] = $column->COLUMN_NAME;
            $properties['is-nullable'] = ($column->IS_NULLABLE == 'YES');
            $properties['data-value'] = $column->COLUMN_DEFAULT;
            $properties['data-type'] = $this->getDataType($column->DATA_TYPE, $column->COLUMN_TYPE);
            $properties['data-type-params'] = $this->getPrecision($column->CHARACTER_MAXIMUM_LENGTH, $column->DATA_TYPE, $column->COLUMN_TYPE);
            $properties['is-primary'] = in_array($column->COLUMN_KEY, ['PRIMARY KEY', 'PRI']);
            $properties['is-index'] = ($column->COLUMN_KEY == 'MUL');
            $properties['is-unique'] = ($column->COLUMN_KEY == 'UNI');
            $properties['is-auto-increment'] = ($column->EXTRA == 'AUTO_INCREMENT');
            $properties['comment'] = $column->COLUMN_COMMENT ?: null;
            $properties['options'] = $this->getHtmlOptions($column->DATA_TYPE, $column->COLUMN_TYPE);
            $properties['is-unsigned'] = (strpos($column->COLUMN_TYPE, 'unsigned') !== false);

            $constraint = $this->getForeignConstraint($column->COLUMN_NAME);

            $properties['foreign-constraint'] = !is_null($constraint) ? $constraint->toArray() : null;

            if (intval($column->CHARACTER_MAXIMUM_LENGTH) > 255
                || in_array($column->DATA_TYPE, $this->largeDataTypes)) {
                $properties['is-on-index'] = false;
            }

            $collection[] = $properties;
        }

        $localeGroup = Helpers::makeLocaleGroup($this->tableName);

        $fields = FieldTransformer::fromArray($collection, $localeGroup, $this->languages);

        // At this point we constructed the fields collection with the default html-type
        // We need to set the html-type using the config::getEloquentToHtmlMap() setting
        $this->setHtmlType($fields);

        return $fields;
    }
977460
public function column($key)
    {
        $result = array_column($this->all(), $key);

        if (empty($result)) {
            $this->each(function ($item) use (&$result, $key) {
                array_push($result, $item->{$key});
            });
        }

        return new static($result);
    }
1308316
public function keyContainsValue($column)
    {
        // must use array_key_exists() because the key could
        // exist but have a NULL value (that'd be valid).
        return (array_key_exists($column, $this->map) && ($this->map[$column]->getValue() !== null));
    }
375880
protected function saveRelationsAfterHasOne($key)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($this);
        $relation = $class::getRelations()[$key];
        $column = $class::getRelationLinkName($relation);

        /** @var \T4\Orm\Model $oldSubModel */
        $oldSubModel = $this->getRelationLazy($key);

        /** @var \T4\Orm\Model $newSubModel */
        $newSubModel = $this->{$key};

        if ( !empty($oldSubModel) && (empty($newSubModel) || $newSubModel->getPk() != $oldSubModel->getPk()) ) {
            $oldSubModel->{$column} = null;
            $oldSubModel->save();
        }

        if ( !empty($newSubModel) ) {
            $newSubModel->{$column} = $this->getPk();
            $newSubModel->save();
        }
    }
1310411
protected function assignFields($fields)
    {
        foreach ($fields as $field) {
            if (!$field instanceof FieldInterface) {
                throw new ModelException(sprintf('Field must be an instance of FieldInterface, got "%s"', $this->getType($field)));
            }

            $field->table($this->table);
            $this->fields[$field->name()] = $field;
        }
    }
1311580
protected function addTranslatedColumnSetter(Column $column)
    {
        $i18nTablePhpName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable()));
        $tablePhpName = $this->builder->getObjectClassName();
        $objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
        $comment = '';
        $functionStatement = '';
        if ($this->isDateType($column->getType())) {
            $objectBuilder->addTemporalMutatorComment($comment, $column);
            $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
        } else {
            $objectBuilder->addMutatorComment($comment, $column);
            $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
        }
        $comment = preg_replace('/^\t/m', '', $comment);
        $comment = str_replace('@return     $this|' . $i18nTablePhpName, '@return     $this|' . $tablePhpName, $comment);
        $functionStatement = preg_replace('/^\t/m', '', $functionStatement);
        preg_match_all('/\$[a-z]+/i', $functionStatement, $params);

        return $this->behavior->renderTemplate('objectTranslatedColumnSetter', [
            'comment'           => $comment,
            'functionStatement' => $functionStatement,
            'columnPhpName'     => $column->getPhpName(),
            'params'            => implode(', ', $params[0]),
        ]);
    }
635243
protected function transformModelToArray($columns)
    {
        $model = $this->getModel();

        $extract = [];

        $relationships = null;

        foreach ($columns as $label => $column) {

            $columnModel = $model;

            $modifier = "";
            $urlSuffix = false;

            $apiLabel = (is_numeric($label)) ? $column : $label;

            if (is_callable($column)) {
                $value = $column();
            } else {
                if (stripos($column, ":") !== false) {
                    $parts = explode(":", $column);
                    $column = $parts[0];

                    if (is_numeric($label)) {
                        $apiLabel = $column;
                    }

                    $modifier = strtolower($parts[1]);

                    if (sizeof($parts) > 2) {
                        $urlSuffix = $parts[2];
                    }
                }

                if (stripos($column, ".") !== false) {
                    $parts = explode(".", $column, 2);

                    $column = $parts[0];
                    $columnModel = $columnModel->$column;

                    $column = $parts[1];

                    if (is_numeric($label)) {
                        $apiLabel = $parts[1];
                    }
                }

                if ($columnModel) {
                    $value = $columnModel->$column;
                } else {
                    $value = "";
                }
            }

            if (is_object($value)) {
                // We can't pass objects back through the API! Let's get a JSON friendly structure instead.
                if (!($value instanceof Model) && !($value instanceof Collection)) {
                    // This seems strange however if we just used json_encode we'd be passing the encoded version
                    // back as a string. We decode to get the original structure back again.
                    $value = json_decode(json_encode($value));
                } else {
                    $navigationResource = false;
                    $navigationResourceIsCollection = false;

                    if ($value instanceof Model) {

                        $navigationResource = $this->getRestResourceForModel($value);

                        if ($navigationResource === false) {
                            throw new RestImplementationException(print_r($value, true));
                            continue;
                        }
                    }

                    if ($value instanceof Collection) {
                        $navigationResource = $this->getRestResourceForModelName(SolutionSchema::getModelNameFromClass($value->getModelClassName()));

                        if ($navigationResource === false) {
                            continue;
                        }

                        $navigationResourceIsCollection = true;
                        $navigationResource->setModelCollection($value);
                    }

                    if ($navigationResource) {
                        switch ($modifier) {
                            case "summary":
                                $value = $navigationResource->summary();
                                break;
                            case "link":
                                $link = $navigationResource->link();

                                if (!isset($link->href) || $navigationResourceIsCollection) {

                                    if (!$urlSuffix) {
                                        throw new RestImplementationException("No canonical URL for " . get_class($navigationResource) . " and no URL suffix supplied for property " . $apiLabel);
                                    }

                                    $ourHref = $this->getHref();

                                    // Override the href with this appendage instead.
                                    $link->href = $ourHref . $urlSuffix;
                                }

                                $value = $link;

                                break;
                            default:
                                $value = $navigationResource->get();
                                break;
                        }
                    }
                }
            }

            if ($value !== null || $this->includeNullItems) {
                $extract[$apiLabel] = $value;
            }
        }

        return $extract;
    }
760091
private function getExportParams($key = null)
    {
        if ($key && isset($this->exportParams[$key])) {
            return $this->exportParams[$key];
        }

        return $this->exportParams;
    }
1116470
public function addColumns(array $columns)
    {
        /*
         * Build a final collection of list column objects
         */
        foreach ($columns as $columnName => $config) {
            $this->allColumns[$columnName] = $this->makeListColumn($columnName, $config);
        }
    }
1023966
public function toggleImporter($key)
    {
        $importer = $this->getImporter($key);
        $importer->toggle();
        foreach ($importer->getSegments() as $segment) {
            if ($importer->isEnabled()) {
                $this->addSegment($segment);
            } else {
                $this->removeSegment($segment);
            }
        }
    }
715747
public function pluck($column, $key = null)
    {
        $results = $this->toBase()->pluck($column, $key);

        // If the model has a mutator for the requested column, we will spin through
        // the results and mutate the values so that the mutated version of these
        // columns are returned as you would expect from these Eloquent models.
        if (! $this->model->hasGetMutator($column) &&
            ! $this->model->hasCast($column) &&
            ! in_array($column, $this->model->getDates())) {
            return $results;
        }

        return $results->map(function ($value) use ($column) {
            return $this->model->newFromBuilder([$column => $value])->{$column};
        });
    }
225476
public static function value_to_key($data, $column)
	{
		/* init the return array */
		$return = array();

		/* itterate over all the elements */
		foreach ($data as $key => $val)
		{
			if (is_object($val))
			{
				$return[$val->$column] = $val;
			}
			else
			{
				$return[$val[$column]] = $val;
			}
		}

		/* return the array */
		return $return;
	}
1055573
protected function saveRelationsBeforeBelongsTo($key)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($this);
        $relation = $class::getRelations()[$key];
        $column = $class::getRelationLinkName($relation);

        if ($this->{$key} instanceof Model) {
            if ( $this->{$key}->isNew() ) {
                $this->{$key}->save();
            }
            $thatColumnName = $class::getBelongsToThatLinkColumnName($relation);
            $this->{$column} = $this->{$key}->{$thatColumnName};
        } else {
            $this->{$column} = null;
        }
    }
185109
public function selectFrom($table, string $column, string ...$columns)
    {
        $instance = $this->selectQueryInstance();

        $instance->selectQuery()->columnsFrom($table, $column, ...$columns);

        return $instance;
    }
369846
public function getColumn($column) {
		if ($this->columns->has($column)) {
			return $this->columns[$column];
		}

		throw new ColumnException('Column not found!');
	}