@param string|null $tableAlias
@param string|null $modelClass

@return array
514060
public function getModelColumns(string $tableAlias = null, string $modelClass = null): array
    {
        $modelClass = $modelClass ?? $this->getModelClass();
        $tableAlias = $tableAlias ?? $this->getAlias();

        $quotedColumns = [];

        $columnMapper    = $this->getColumnToDatabaseMapper();
        $selectedColumns = $this->getModelSchemas()->getAttributes($modelClass);
        foreach ($selectedColumns as $column) {
            $quotedColumns[] = call_user_func($columnMapper, $tableAlias, $column, $this);
        }

        $rawColumns = $this->getModelSchemas()->getRawAttributes($modelClass);
        foreach ($rawColumns as $columnOrCallable) {
            $quotedColumns[] = is_callable($columnOrCallable) === true ?
                call_user_func($columnOrCallable, $tableAlias, $this) : $columnOrCallable;
        }

        return $quotedColumns;
    }
95695
public function buildOrder($meta, $tableAlias=null)
    {
        // Careful! $meta might be null.
        $metaFields = $meta ? $meta->fields : null;
        
        $order = $this->order;
        if ($meta && $meta->defaultOrder && $order !== null) {
            $order = $meta->defaultOrder;
        }

        if ($order) {
            if (is_array($order)) {
                $oClauses = '';
                foreach ($order as $field=>$dir) {
                    if ($oClauses) {
                        $oClauses .= ', ';
                    }
                    if (!is_string($field)) {
                        $field = $dir; $dir = '';
                    }
                    
                    $name = (isset($metaFields[$field]) ? $metaFields[$field]['name'] : $field);
                    $qname = $name[0] == '`' ? $name : '`'.$name.'`';
                    $qname = ($tableAlias ? $tableAlias.'.' : '').$qname;
                    $oClauses .= $qname;

                    if ($dir) {
                        if ($dir === true) {
                            $dir = 'asc';
                        }
                        // strpos(strtolower($dir), 'desc') === 0;
                        if (isset($dir[3]) && ($dir[0] == 'd' || $dir[0] == 'D') && ($dir[1] == 'e' || $dir[1] == 'E') && ($dir[2] == 's' || $dir[2] == 'S') && ($dir[3] == 'c' || $dir[3] == 'C')) {
                            $oClauses .= ' desc';
                        }
                        elseif (!isset($dir[2]) || !(($dir[0] == 'a' || $dir[0] == 'A') && ($dir[1] == 's' || $dir[1] == 'S') && ($dir[2] == 'c' || $dir[2] == 'C'))) {
                            throw new \UnexpectedValueException("Order direction must be 'asc' or 'desc', found ".$dir);
                        }
                    }
                }
                $order = $oClauses;
            }
            else {
                if ($metaFields && strpos($order, '{') !== false) {
                    $order = static::replaceFields($meta, $order, $tableAlias);
                }
            }
        }
        
        return $order;
    }
365566
private function getDoctrineMetadata($entityClass)
    {
        if (!isset($this->doctrineMetadata[$entityClass])) {
            try {
                $this->doctrineMetadata[$entityClass] = $this->em->getClassMetadata($entityClass);
            } catch (MappingException $ex) {
                throw new FiltererException(sprintf('Unable to get Doctrine metadata for class "%s".', $entityClass));
            }
        }

        return $this->doctrineMetadata[$entityClass];
    }
597379
public function fetchAllObj(string $class = null): array
    {
        if ($class == null && $this->modelClass !== null) {
            return parent::fetchAllObj($this->modelClass);
        } else {
            return parent::fetchAllObj($class);
        }
    }
458849
public function getRouteNameForModelClass($modelClass, $prefix = false)
    {
        $modelSlug = static::MODEL_ROUTE_NAME_PREFIX
                   . $this->getRouteSlugForModelClass($modelClass);

        if ( ! $prefix) {
            return $modelSlug;
        }

        return config('cms-core.route.name-prefix')
             . config('cms-models.route.name-prefix')
             . $modelSlug;
    }
1298528
protected function getCountForModel($modelClass)
    {
        if ( ! is_a($modelClass, Model::class, true)) {
            throw new UnexpectedValueException("'{$modelClass}' is not an Eloquent model class.");
        }

        return $modelClass::withoutGlobalScopes()->count() ?: 0;
    }
548712
private function getNewObjectFlagMeta($entityClass)
    {
        $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);

        return isset($meta['newObjectFlag']) ? $meta['newObjectFlag'] : [];
    }
342271
public function getSQLTableAlias($tableName, $dqlAlias = '')
    {
        $tableName .= ($dqlAlias) ? '@[' . $dqlAlias . ']' : '';

        if ( ! isset($this->tableAliasMap[$tableName])) {
            $this->tableAliasMap[$tableName] = (preg_match('/[a-z]/i', $tableName[0]) ? strtolower($tableName[0]) : 't')
                . $this->tableAliasCounter++ . '_';
        }

        return $this->tableAliasMap[$tableName];
    }
578115
private function generateClassTableInheritanceJoins($class, $dqlAlias)
    {
        $sql = '';

        $baseTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);

        // INNER JOIN parent class tables
        $parentClass = $class;

        while (($parentClass = $parentClass->getParent()) !== null) {
            $tableName  = $parentClass->table->getQuotedQualifiedName($this->platform);
            $tableAlias = $this->getSQLTableAlias($parentClass->getTableName(), $dqlAlias);

            // If this is a joined association we must use left joins to preserve the correct result.
            $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER ';
            $sql .= 'JOIN ' . $tableName . ' ' . $tableAlias . ' ON ';

            $sqlParts = [];

            foreach ($class->getIdentifierColumns($this->em) as $column) {
                $quotedColumnName = $this->platform->quoteIdentifier($column->getColumnName());

                $sqlParts[] = $baseTableAlias . '.' . $quotedColumnName . ' = ' . $tableAlias . '.' . $quotedColumnName;
            }

            $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias);

            // Add filters on the root class
            if ($filterSql) {
                $sqlParts[] = $filterSql;
            }

            $sql .= implode(' AND ', $sqlParts);
        }

        // Ignore subclassing inclusion if partial objects is disallowed
        if ($this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
            return $sql;
        }

        // LEFT JOIN child class tables
        foreach ($class->getSubClasses() as $subClassName) {
            $subClass   = $this->em->getClassMetadata($subClassName);
            $tableName  = $subClass->table->getQuotedQualifiedName($this->platform);
            $tableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias);

            $sql .= ' LEFT JOIN ' . $tableName . ' ' . $tableAlias . ' ON ';

            $sqlParts = [];

            foreach ($subClass->getIdentifierColumns($this->em) as $column) {
                $quotedColumnName = $this->platform->quoteIdentifier($column->getColumnName());

                $sqlParts[] = $baseTableAlias . '.' . $quotedColumnName . ' = ' . $tableAlias . '.' . $quotedColumnName;
            }

            $sql .= implode(' AND ', $sqlParts);
        }

        return $sql;
    }
598060
public static  function createQuery($modelClass, $ignore=[])
    {
        $model = $modelClass::find();
        $wheres = ['and'];
        $filter_fields = self::getQueryParams($ignore);
        $condition_transform_functions = self::conditionTransformFunctions();

        foreach($filter_fields as $key => $value){
            if($value == '' || in_array($key,self::$exclude_field))
                continue;
            $field_key = $key;
            if(!strpos($key,'.')){
                $field_key =  $modelClass::tableName().'.'.$key ;
            }else{
                $relation_model = substr($field_key,0,strrpos($key,'.'));
                $model->joinWith($relation_model);
                if(strpos($relation_model,'.')){
                    $temp = substr($field_key,strrpos($field_key,'.'));
                    $field_key = substr($relation_model,strrpos($relation_model,'.')+1).$temp;
                    $field_key = str_replace($relation_model, $relation_model::tableName(), $field_key);
                } else {
                    // Build the relation's tale name
                    $baseModel = new $modelClass;
                    $relationModel = $baseModel->getRelation($relation_model);
                    $relationModel = new $relationModel->modelClass;
                    $field_key = str_replace($relation_model . '.', $relationModel->tableName() . '.', $field_key);
                }
            }

            $type = 'EQUAL';
            if(preg_match("/^[A-Z]+_/",$value, $matches) && array_key_exists(trim($matches[0],'_'),$condition_transform_functions)){
                $type = trim($matches[0],'_');
                $value = str_replace($matches[0],'',$value);
            }

            $wheres = ArrayHelper::merge($wheres, [$condition_transform_functions[$type]($field_key,$value)]);
        }

        if(count($wheres) > 1) {
            $model->andWhere($wheres);
        }

        return $model;
    }
767774
public function isAllowedModel($modelClass, $privilege = null)
    {
        return $this->isAllowed($this->modelResourceGenerator($modelClass), $privilege);
    }
1339817
public function deepClone($class = null)
    {
        $class = (is_null($class)) ? static::class : $class;
        /** @var $obj Query */
        $obj = new $class($this->model);
        $obj->aliasRefCount = $this->aliasRefCount;
        $obj->useDefaultCols = $this->useDefaultCols;
        $obj->tableAlias = $this->tableAlias;
        $obj->tableJoinsMap = $this->tableJoinsMap;
        $obj->tablesAliasList = $this->tablesAliasList;
        $obj->select = $this->select;
        $obj->groupBy = $this->groupBy;
        $obj->valueSelect = $this->valueSelect;
        $obj->selectRelected = $this->selectRelected;
        $obj->standardOrdering = $this->standardOrdering;
        $obj->annotations = $this->annotations;
        $obj->defaultOrdering = $this->defaultOrdering;
        $obj->orderBy = $this->orderBy;
        $obj->offset = $this->offset;
        $obj->limit = $this->limit;
        $obj->where = $this->where->deepClone();

        return $obj;
    }
506217
public function getRoutePathForModelClass($modelClass, $prefix = false)
    {
        $modelSlug = $this->getRouteSlugForModelClass($modelClass);

        if ( ! $prefix) {
            return $modelSlug;
        }

        return config('cms-core.route.prefix')
             . config('cms-models.route.prefix') . '/'
             . $modelSlug;
    }
433679
private function gatherColumns($class, Table $table)
    {
        $pkColumns = [];

        foreach ($class->getDeclaredPropertiesIterator() as $fieldName => $property) {
            if (! ($property instanceof FieldMetadata)) {
                continue;
            }

            if ($class->inheritanceType === InheritanceType::SINGLE_TABLE && $class->isInheritedProperty($fieldName)) {
                continue;
            }

            $this->gatherColumn($class, $property, $table);

            if ($property->isPrimaryKey()) {
                $pkColumns[] = $this->platform->quoteIdentifier($property->getColumnName());
            }
        }
    }
1098740
final function Table($alias = '', array $fieldAliases = array())
    {
        $sql = $this->SqlBuilder();
        return $sql->Table($this->TableName(), $this->FieldNames($fieldAliases), $alias);
    }
615782
protected function findModel($modelClass, $attributes = [])
    {
        $query = $this->getQueryBuilderFromModel($modelClass);
        foreach ($attributes as $key => $value) {
            $query->where($key, $value);
        }

        return $query->first();
    }
780959
public function getPrimaryKey($tableAlias = '')
    {
        $output = '';

        if (!empty($tableAlias)) {
            $output .= '`' . $tableAlias . '`.';
        }

        $output .= '`'.static::ID_COLUMN.'`';

        return $output;
    }