TODO

@param ModelResult $modelResult
@return $this
966019
public function join(ModelResult $modelResult)
    {
        foreach ($modelResult->models as $model) {
            $this->models[] = $model;
        }

        return $this;
    }
1366895
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UserCustomerRelationQuery) {
            return $criteria;
        }
        $query = new UserCustomerRelationQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
90269
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof SystemSettingsQuery) {
            return $criteria;
        }
        $query = new SystemSettingsQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
1164816
public function paginateHydrate($result, $modelClass = null)
    {
        // Get values
        $pagination = array_get($result, 'pagination', []);
        $items = array_get($result, 'items', []);
        $page = LengthAwarePaginator::resolveCurrentPage();

        // Set pagination
        $perPage = array_get($pagination, 'perPage', array_get($pagination, 'per_page', 15));
        $total = array_get($pagination, 'total', null);

        // Set options
        $options = is_array($result) ? array_except($result, [
            'pagination',
            'items',
            'next',
            'per_page',
            'last'
        ]) : [];

        return new LengthAwarePaginator($this->hydrate($items, $modelClass), $total, $perPage, $page,
            array_merge($options, [
                'path' => LengthAwarePaginator::resolveCurrentPath()
            ]));
    }
331322
public function setModels($modelParent, $modelChild)
    {
        $this->modelParent = $modelParent;
        $this->modelChild = $modelChild;

        return $this;
    }
580331
public function clone($modelitemId)
    {
        event(new BeforeClone($this));

        $this->beforeClone();

        $this->doClone();

        $this->afterClone();

        event(new AfterClone($this));
    }
1010159
public function add(ModelDocument $modelDocument) {
        if(isset($this->models[$modelDocument->getName()])){
            throw new RuntimeException(sprintf("The model document name '%s' is already added in module '%s'",$modelDocument->getName(),$this->id));
        }
        $this->models[$modelDocument->getName()] = $modelDocument;
        return $this;
    }
35422
public function parseResults(LoopResult $loopResult)
    {
        foreach ($loopResult->getResultDataCollection() as $filter) {
            $loopResultRow = new LoopResultRow($filter);


            $loopResultRow->set("ID", $filter->getId())
                ->set("IS_TRANSLATED", $filter->getVirtualColumn('IS_TRANSLATED'))
                ->set("LOCALE", $filter->locale)
                ->set("TITLE", $filter->getVirtualColumn('i18n_TITLE'))
                ->set("CODE", $filter->getCode())
                ->set("DESCRIPTION", $filter->getVirtualColumn('i18n_DESCRIPTION'))
                ->set("ACTIVATE", $filter->getActive())
                ->set("TYPE", $filter->getFiltertype());

            $loopResult->addRow($loopResultRow);
        }

        return $loopResult;
    }
1149559
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UserQuery) {
            return $criteria;
        }
        $query = new UserQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
456175
public function setResultContainerClass($resultClass)
    {
        $this->resultClass = $resultClass;

        /** @var ResultContainer $resultContainer */
        $resultContainer = new $resultClass($this->entityManager);

        // set the model class
        $this->setResultModelClass($resultContainer->getModelClass());

        return $this;
    }
1030690
public function afterFind(Model $model, $results, $primary=false) {
        $alias = $model->alias;

        foreach ($results as $i => $data) {
            if (empty($data[$alias])) {
                continue;
            }

            foreach ($data[$alias] as $field => $value) {
                if (empty($this->settings[$alias][$field]) || !empty($value)) {
                    continue;
                }

                $attachment = $this->_settingsCallback($model, $this->settings[$alias][$field]);

                if ($attachment['defaultPath']) {
                    $results[$i][$alias][$attachment['dbColumn']] = $attachment['defaultPath'];
                }

                if ($attachment['transforms']) {
                    foreach ($attachment['transforms'] as $transform) {
                        if ($transform['defaultPath']) {
                            $results[$i][$alias][$transform['dbColumn']] = $transform['defaultPath'];
                        }
                    }
                }
            }
        }

        return $results;
    }
912102
public function parseResults(LoopResult $loopResult)
    {
        /** @var ImportModel $type */
        foreach ($loopResult->getResultDataCollection() as $type) {
            $loopResultRow = new LoopResultRow($type);

            $url = URL::getInstance()->absoluteUrl(
                $this->getBaseUrl() . "/" . $type->getId()
            );

            try {
                $loopResultRow
                    ->set("HANDLE_CLASS", $type->getHandleClass())
                    ->set("ID", $type->getId())
                    ->set("TITLE", $type->getVirtualColumn("i18n_TITLE"))
                    ->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION"))
                    ->set("URL", $url)
                    ->set("POSITION", $type->getPosition())
                    ->set("CATEGORY_ID", $type->getByName($this->getCategoryName()))
                ;
            } catch (ClassNotFoundException $e) {
            } catch (\ErrorException $e) {
            }

            $this->addOutputFields($loopResultRow, $type);
            $loopResult->addRow($loopResultRow);
        }

        return $loopResult;
    }
1311802
public function setModel($modelClass) {
		$reflection = new ReflectionClass($modelClass);
		
		if (! $reflection->implementsInterface('ZExt\Model\ModelInterface')) {
			throw new Exception('Class of a model must implements "ModelInterface"');
		}
		
		$this->_modelClass = $modelClass;
		
		return $this;
	}
763521
public function setModelType($modelType)
    {
        if ($modelType < self::MODELTYPE_ENTITY || $modelType > self::MODELTYPE_VALUEOBJECT) {
            throw new \InvalidArgumentException('"' . $modelType . '" is an invalid model type.', 1212519195);
        }
        $this->modelType = $modelType;
    }
540784
public function parseResults(LoopResult $loopResult)
    {
        $moduleCode = $this->getModule();

        if (null === $module = ModuleQuery::create()->filterByCode($moduleCode, Criteria::LIKE)->findOne()) {
            throw new \InvalidArgumentException("Module with code '$moduleCode' does not exists.");
        }

        $configValue = ModuleConfigQuery::create()->getConfigValue(
            $module->getId(),
            $this->getVariable(),
            $this->getDefaultValue(),
            $this->getLocale()
        );

        $loopResultRow = new LoopResultRow();

        $loopResultRow
            ->set("VARIABLE", $this->getVariable())
            ->set("VALUE", $configValue)
        ;

        $loopResult->addRow($loopResultRow);

        return $loopResult;
    }
159415
public function setModelClass($model_class): Repository
	{
		if ( !is_subclass_of($model_class, Model::class)) {
			throw new InvalidArgumentException('Specified model class must be an instance of ' . Model::class);
		}

		$this->model_class = $model_class;

		/** @var \Illuminate\Database\Eloquent\Model|\Fuzz\MagicBox\Contracts\MagicBoxResource $instance */
		$instance = new $model_class;

		// @todo use set methods
		$this->setFillable($instance->getRepositoryFillable());
		$this->setIncludable($instance->getRepositoryIncludable());
		$this->setFilterable($instance->getRepositoryFilterable());

		$this->key_name = $instance->getKeyName();

		return $this;
	}
684419
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->class = get_class($model);

        return $this;
    }