Analyzes a model for its translations and returns relevant information.

@param Model  $model
@param string $strategy
@return ModelInformation
501347
public function analyze(Model $model, $strategy = 'translatable')
    {
        $this->model = $model;

        $this->info = new ModelInformation([]);

        switch ($strategy) {

            case 'translatable':
                $this->analyzeForTranslatable();
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \UnexpectedValueException("Cannot handle translation strategy '{$strategy}");
        }

        return $this->info;
    }
75114
protected function isColumnOnModelTable(Model $model, $column)
    {
        $info = $this->getModelInformation($model);

        if ($info) {
            return (    array_key_exists($column, $info->attributes)
                    &&  ! $info->attributes[$column]->translated
                    );
        }

        // Determine based on model itself
        return ($model->getKeyName() == $column || $model->isFillable($column) || $model->isGuarded($column));
    }
4091
public function strategy(string $strategy, array $options = []): ListFilter
    {
        $this->main['strategy'] = $strategy;

        if (count($options)) {
            $this->main['options'] = $options;
        }

        return $this;
    }
93376
public function export($strategy)
    {
        // Check if the strategy is available and allowed to be used
        if ( ! $this->isExportStrategyAvailable($strategy)) {
            abort(403, "Not possible or allowed to perform export '{$strategy}'");
        }

        // Prepare the strategy instance
        $exporter = $this->getExportStrategyInstance($strategy);
        $filename = $this->getExportDownloadFilename($strategy, $exporter->extension());

        $this->checkListParents()
             ->checkActiveSort(false)
             ->checkScope(false)
             ->checkFilters()
             ->checkActivePage(false)
             ->applySort()
             ->applyScope($this->modelRepository);

        $query = $this->getModelRepository()->query();

        $this->applyFilter($query)
             ->applyListParentToQuery($query);

        $download = $exporter->download($query, $filename);

        if (false === $download) {
            // @codeCoverageIgnoreStart
            abort(500, "Failed to export model listing for strategy '{$strategy}'");
            // @codeCoverageIgnoreEnd
        }

        event( new Events\ModelListExportedInCms($this->modelInformation->modelClass(), $strategy) );

        return $download;
    }
854564
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
    {
        $wrapCase = $this->createWrapCase($caseSensitive);
        $valueParameter = $queryNameGenerator->generateParameterName($field);

        switch ($strategy) {
            case null:
            case self::STRATEGY_EXACT:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_PARTIAL:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_START:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_END:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_WORD_START:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            default:
                throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
        }
    }
262267
public void addStrategy(MappingStrategy strategy)
    {
        if (strategies == null)
        {
            strategies = new ArrayList<>();
        }
        strategies.add(strategy);
    }
548397
public function analysisHub(Model $model)
    {
        // Check memory and runtime.
        if ($this->pool->emergencyHandler->checkEmergencyBreak() === true) {
            return '';
        }

        $data = $model->getData();

        // String?
        if (is_string($data) === true) {
            return $this->processString->process($model);
        }

        // Integer?
        if (is_int($data) === true) {
            return $this->processInteger->process($model);
        }

        // Null?
        if ($data === null) {
            return $this->processNull->process($model);
        }

        // Handle the complex types.
        if (is_array($data) === true || is_object($data) === true) {
            // Up one nesting Level.
            $this->pool->emergencyHandler->upOneNestingLevel();
            // Handle the non simple types like array and object.
            $result = $this->handleNoneSimpleTypes($data, $model);
            // We are done here, down one nesting level.
            $this->pool->emergencyHandler->downOneNestingLevel();
            return $result;
        }

        // Boolean?
        if (is_bool($data) === true) {
            return $this->processBoolean->process($model);
        }

        // Float?
        if (is_float($data) === true) {
            return $this->processFloat->process($model);
        }

        // Resource?
        // The is_resource can not identify closed stream resource types.
        // And the get_resource_type() throws a warning, in case this is not a
        // resource.
        set_error_handler(function () {
            // Do nothing. We need to catch a possible warning.
        });
        if (get_resource_type($data) !== null) {
            restore_error_handler();
            return $this->processResource->process($model);
        }
        restore_error_handler();

        // Still here? Tell the dev that we can not analyse this one.
        return $this->processOther->process($model);
    }
1215324
public function generateSelectForModel(AbstractModel $model, $param)
    {
        $cacheData = $this->fetchCacheData($model);
        if (isset($cacheData[self::RELATION_INDEX])) {
            $this->checkRelations($cacheData[self::RELATION_INDEX]);
        }

        /**
         * select Strategy
         */
        $strategy = new MySQLSelectStrategy(
            $cacheData[self::TABLE_DATA_INDEX],
            array_keys($param),
            $param
        );

        $strategy->setTransformer($this->paramTransformer);

        return  [
            $strategy->generateSQLStatement(),
            $param,
            self::SELECT_QUERY
        ];
    }
615161
protected function determineModelReferenceSource(Model $model)
    {
        $source = $this->getReferenceSource($model);

        // If we have no source to fall back on at all, use the model key
        if ( ! $source) {
            $source = $model->getKeyName();
        }

        return $source;
    }
232114
public function analyze(ModelInformationInterface $information)
    {
        $this->info = $information;

        $this->performStep();

        return $this->info;
    }
682056
protected function performUpdate(Model $model)
    {
        $data = collect([$this->getIndexColumn($model) => $this->toVector($model)]);

        $query = $this->database
            ->table($model->searchableAs())
            ->where($model->getKeyName(), '=', $model->getKey());

        if (method_exists($model, 'searchableAdditionalArray')) {
            $data = $data->merge($model->searchableAdditionalArray() ?: []);
        }

        if (! $this->isExternalIndex($model) || $query->exists()) {
            return $query->update($data->all());
        }

        return $query->insert(
            $data->merge([
                $model->getKeyName() => $model->getKey(),
            ])->all()
        );
    }
1179656
public function created(Model $model)
    {
        $langs = app('languages')->langs();
        DB::beginTransaction();
        try {
            foreach ($langs as $lang) {
                $this->saveTranslatedMessage($model, $lang);
            }
        } catch (Exception $ex) {
            DB::rollback();
            throw $ex;
        }
        DB::commit();
        return true;
    }
1352133
public function getReferenceForModel(Model $model, $strategy = null, $source = null)
    {
        return $this->getReferenceValue($model, $strategy, $source);
    }
1136717
public function make($strategy, $key = null, ModelFilterDataInterface $info = null)
    {
        // A filter must have a resolvable strategy for displaying
        if ( ! ($strategyClass = $this->resolveStrategyClass($strategy))) {
            throw new RuntimeException(
                "Could not resolve filter strategy class for {$key}: '{$strategy}'"
            );
        }

        /** @var FilterStrategyInterface $instance */
        $instance = app($strategyClass);

        if (null !== $info) {
            $instance->setFilterInformation($info);
        }

        return $instance;
    }
1321498
protected function getCommand(StrategyInterface $strategy)
    {
        $command = $strategy->get();
        if ($command === null) {
            throw new Exception('Failed to locate a sensible command');
        }

        return $command;
    }
1258536
public function setStrategy($strategy)
    {
        foreach ($this->routes as $route)
            $route->setStrategy($strategy);
        return $this;
    }
1304899
protected function applyFilterStrategyToQuery($query, $target, $value, $strategy = null)
    {
        if (null === $strategy) {
            $strategy = config('cms-models.meta-references.filter-strategy');
        }

        $filter = $this->getFilterFactory()->make($strategy);

        $filter->apply($query, $target, $value);
    }