@param ToModel $import
@param array   $attributes

@return Model[]|Collection
337650
public function toModels(ToModel $import, array $attributes): Collection
    {
        $model = $import->model($attributes);

        if (null !== $model) {
            return \is_array($model) ? new Collection($model) : new Collection([$model]);
        }

        return new Collection([]);
    }
1335779
protected function _newImport(ImportsTable $table, Import $import, int $count) : bool
    {
        $data = [
            'status' => $table::STATUS_IN_PROGRESS,
            'attempts' => 1,
            'attempted_date' => Time::now()
        ];

        $import = $table->patchEntity($import, $data);
        $table->save($import);

        $this->_run($import, $count);

        // mark import as completed
        $data = [
            'status' => $table::STATUS_COMPLETED
        ];

        $import = $table->patchEntity($import, $data);

        return (bool)$table->save($import);
    }
1060008
public static function create($attributes = [])
    {
        try {
            self::init();
            foreach ($attributes as $column => $value) {
                $columns[] = $column;
                $values[] = ':'.$column;
            }

            $sql = 'INSERT INTO ' . self::$modelTable . ' (' . implode(',', $columns) . ') VALUES (' . implode(',', $values) . ')';
            $stm = self::$connect->prepare($sql);
            $stm->execute($attributes);
            return self::find(self::$connect->lastInsertId());
        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }
328440
protected function processImport(AbstractImport $import, SerializerInterface $serializer)
    {
        $errors = [];

        $import->setData($serializer->unserialize($import->getFile()->openFile('r')));

        foreach ($import as $idx => $data) {
            $import->checkMandatoryColumns($data);

            $error = $import->importData($data);
            if ($error !== null) {
                $errors[] = $error;
            }
        }

        return $errors;
    }
145100
protected function handleAutoRelatedAttributes($attributes, $model)
    {
        collect($this->getDataKeys())
            ->filter(function ($key) {
                return strpos($key, ':') !== false;

            })->map(function ($key) {
                return array_merge([$key], explode(':', $key));

            })->each(function ($key) use (&$attributes, $model) {
                // For each one, we create a "relation:attribute" key
                // in the returned array
                $attributes[$key[0]] = $model->{$key[1]} ? ($model->{$key[1]}->{$key[2]} ?? null) : null;
            });

        return $attributes;
    }
361495
public function addColumn(array $attributes)
    {
        $query  = $this->getQuery();
        $orders = $query instanceof \Illuminate\Database\Eloquent\Builder ? $query->getQuery()->orders : null;
        if (!isset($this->attributes['order']) and ! is_null($query) and ! is_null($orders)) {
            foreach ($orders as $order) {
                if ($order['column'] != $attributes['name']) {
                    continue;
                }
                $this->attributes['order'] = [
                    $this->collection->count(), $order['direction']
                ];
            }
        }
        $path = uri();
        $this->dispatcher->fire('datatables:' . $path . ':column.' . $attributes['name'], [&$attributes]);
        $this->dispatcher->fire(new \Antares\Events\Datatables\Column($path, $attributes['name'], $attributes));
        $this->collection->push(new Column($attributes));
        $this->dispatcher->fire('datatables:' . $path . ':after.' . $attributes['name'], $this);
        $this->dispatcher->fire(new AfterColumn($path, $attributes['name'], $this));
        return $this;
    }
585186
protected function filterImportFiles(array $imports)
    {
        $config             = $this->config;
        $excludedComponents = $config->getExcludedComponents();
        $includedComponents = $config->getIncludedComponents();

        if (!empty($excludedComponents) && !empty($includedComponents)) {
            throw new Exception\RuntimeException(
                'You may not set both excluded and included components.'
            );
        }

        if (!empty($excludedComponents)) {
            $imports = $this->removeImportFiles($imports, $excludedComponents);
        } elseif (!empty($includedComponents)) {
            $imports = $this->addImportFiles($imports, $includedComponents);
        }

        $imports = $this->setupFontAwesome($imports);

        array_walk($imports, function (&$val) {
            $val = "@import \"$val\";";
        });

        return implode(PHP_EOL, $imports);
    }
1122430
public function _getAttributesArray($attributeSetId)
    {
        $result = [];
        $attributes = $this->attributeCollection->create()
            ->setAttributeSetFilter($attributeSetId)
            ->getItems();

        foreach ($attributes as $attribute) {
            $result[] = $attribute->getAttributeCode();
        }

        return $result;
    }
848274
public function withAttributes(array $attributes)
    {
        $clone = clone $this;

        foreach ($attributes as $name => $value) {
            $clone->dom->documentElement->setAttribute($name, $value);
        }

        return $clone;
    }
787794
public function fill(array $attributes)
    {
        $this->saving = true;

        $totallyGuarded = $this->totallyGuarded();

        foreach ($attributes as $key => $values) {
            if ($this->isKeyALocale($key)) {
                foreach ($values as $translationAttribute => $translationValue) {
                    if ($this->alwaysFillable() or $this->isFillable($translationAttribute)) {
                        $this->getTranslationOrNew($key)->$translationAttribute = $translationValue;
                    } elseif ($totallyGuarded) {
                        throw new MassAssignmentException($key);
                    }
                }
                unset($attributes[$key]);
            }
        }

        $result = parent::fill($attributes);

        $this->saving = false;

        return $result;
    }
537583
public function bindAttributes(string $modelClass, iterable $attributes): iterable
    {
        $dbPlatform = $this->getConnection()->getDatabasePlatform();
        $types      = $this->getModelSchemas()->getAttributeTypes($modelClass);

        foreach ($attributes as $column => $value) {
            assert(is_string($column) && $this->getModelSchemas()->hasAttributeType($this->getModelClass(), $column));

            $quotedColumn  = $this->quoteSingleIdentifier($column);
            $type          = $this->getDbalType($types[$column]);
            $pdoValue      = $type->convertToDatabaseValue($value, $dbPlatform);
            $parameterName = $this->createNamedParameter($pdoValue, $type->getBindingType());

            yield $quotedColumn => $parameterName;
        }
    }
560238
public function newModelInstance($attributes = [])
    {
        return $this->model->newInstance($attributes)->setConnection(
            $this->query->getConnection()
        );
    }
559807
public static function makeForModel($model, $attributes)
    {
        if (is_string($attributes)) {
            $attributes = ['name' => $attributes];
        }

        if ($model === '*') {
            return (new static)->forceFill($attributes + [
                'entity_type' => '*',
            ]);
        }

        if (is_string($model)) {
            $model = new $model;
        }

        return (new static)->forceFill($attributes + [
            'entity_type' => $model->getMorphClass(),
            'entity_id'   => $model->exists ? $model->getKey() : null,
        ]);
    }
477985
public function newFromBuilder($attributes = array(), $connection = null)
    {
        // We change the creation behavior here by replacing the newInstance call.
        // Instead we create the model directly here. This is to enable
        // single table inheritance.
        $modelName = $this->determineModelName((array)$attributes);

        // This part handles what essentially happens in the newInstance call.
        $model = new $modelName([]);
        $model->exists = true;

        // Rest is the same
        $model->setRawAttributes((array)$attributes, true);

        $model->setConnection($connection ?: $this->connection);

        return $model;
    }
310202
public function extract_import_contents(string $zipfilepath) : array {

        $importtempdir = make_request_directory('analyticsimport' . microtime(false));

        $zip = new \zip_packer();
        $filelist = $zip->extract_to_pathname($zipfilepath, $importtempdir);

        if (empty($filelist[self::CONFIG_FILE_NAME])) {
            // Missing required file.
            throw new \moodle_exception('errorimport', 'analytics');
        }

        $jsonmodeldata = file_get_contents($importtempdir . DIRECTORY_SEPARATOR . self::CONFIG_FILE_NAME);

        if (!$modeldata = json_decode($jsonmodeldata)) {
            throw new \moodle_exception('errorimport', 'analytics');
        }

        if (empty($modeldata->target) || empty($modeldata->timesplitting) || empty($modeldata->indicators)) {
            throw new \moodle_exception('errorimport', 'analytics');
        }

        $mlbackenddir = $importtempdir . DIRECTORY_SEPARATOR . 'mlbackend';
        if (!is_dir($mlbackenddir)) {
            $mlbackenddir = false;
        }

        return [$modeldata, $mlbackenddir];
    }
491708
public static function init(array $attributes) {
        $obj = new Attributes;
        foreach ($attributes as $attribute) {
            $obj->{$attribute->key} = $attribute;
        }
        return $obj;
    }
548854
protected function mapExportAttributes($attributes)
    {
        return collect($attributes->toArray())->map(function($value, $key) {
            return $this->mapExportAttribute($value, $key);
        })->toArray();
    }