Gets the database results for the current model.

@param string $modelName

@return array of rows
433567
public function results($modelName)
    {
        $dataTable = app('admin_datatable');

        //get the sort options and filters
        $page        = $this->request->input('page', 1);
        $sortOptions = $this->request->input('sortOptions', array());
        $filters     = $this->request->input('filters', array());

        //return the rows
        return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions));
    }
691873
public function getColumns($tableName)
    {
        if (!isset($this->cache[$tableName])) {
            $columns = $this->entityManager->getConnection()->getSchemaManager()->listTableColumns($tableName);
            if ('leads' === $tableName) {
                if (!$this->extendedFieldAliases) {
                    // Hacked this query into here to avoid a recursive dependency in 2.15.0
                    $fq = $this->entityManager->getConnection()->createQueryBuilder();
                    $fq->select('f.alias')
                        ->from(MAUTIC_TABLE_PREFIX.'lead_fields', 'f')
                        ->where(
                            $fq->expr()->orX(
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedField')),
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedFieldSecure'))
                            )
                        );
                    foreach ($fq->execute()->fetchAll() as $result) {
                        $this->extendedFieldAliases[$result['alias']] = 'extendedField - This is never used as an actual column object';
                    }
                }
                if ($this->extendedFieldAliases) {
                    $columns = array_merge($columns, $this->extendedFieldAliases);
                }
            }
            $this->cache[$tableName] = $columns ?: [];
        }

        return $this->cache[$tableName];
    }
927648
public function customModelAction($modelName)
	{
		$config = app('itemconfig');
		$actionFactory = app('admin_action_factory');
		$actionName = $this->request->input('action_name', false);
		$dataTable = app('admin_datatable');

		//get the sort options and filters
		$page = $this->request->input('page', 1);
		$sortOptions = $this->request->input('sortOptions', array());
		$filters = $this->request->input('filters', array());

		//get the prepared query options
		$prepared = $dataTable->prepareQuery(app('db'), $page, $sortOptions, $filters);

		//get the action and perform the custom action
		$action = $actionFactory->getByName($actionName, true);
		$result = $action->perform($prepared['query']);

		//if the result is a string, return that as an error.
		if (is_string($result))
		{
			return response()->json(array('success' => false, 'error' => $result));
		}
		//if it's falsy, return the standard error message
		else if (!$result)
		{
			$messages = $action->getOption('messages');

			return response()->json(array('success' => false, 'error' => $messages['error']));
		}
		else
		{
			$response = array('success' => true);

			//if it's a download response, flash the response to the session and return the download link
			if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse'))
			{
				$file = $result->getFile()->getRealPath();
				$headers = $result->headers->all();
				$this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));

				$response['download'] = route('admin_file_download');
			}
			//if it's a redirect, put the url into the redirect key so that javascript can transfer the user
			else if (is_a($result, '\Illuminate\Http\RedirectResponse'))
			{
				$response['redirect'] = $result->getTargetUrl();
			}

			return response()->json($response);
		}
	}
583497
public function Get($TableName = '') {
		if($TableName)
			$this->Table($TableName);

		$Columns = $this->Database->SQL()->FetchTableSchema($this->_TableName);
		$this->_Columns = $Columns;

		return $this;
	}
770145
public function fetchRow(QueryBuilder $builder, string $modelClass): ?array
    {
        $model = null;

        $statement = $builder->execute();
        $statement->setFetchMode(PDOConnection::FETCH_ASSOC);

        if (($attributes = $statement->fetch()) !== false) {
            if ($this->isFetchTyped() === true) {
                $platform  = $builder->getConnection()->getDatabasePlatform();
                $typeNames = $this->getModelSchemas()->getAttributeTypes($modelClass);
                $model     = $this->readRowFromAssoc($attributes, $typeNames, $platform);
            } else {
                $model = $attributes;
            }
        }

        $this->clearFetchParameters();

        return $model;
    }
1353348
protected function getIndexes($tableName)
    {
        $indexes = [];
        $rows = $this->fetchAll(sprintf('SHOW INDEXES FROM %s', $this->quoteTableName($tableName)));
        foreach ($rows as $row) {
            if (!isset($indexes[$row['Key_name']])) {
                $indexes[$row['Key_name']] = ['columns' => []];
            }
            $indexes[$row['Key_name']]['columns'][] = strtolower($row['Column_name']);
        }

        return $indexes;
    }
65079
protected function getForeignKeys(string $tableName): ?array
    {
        $sql = sprintf("SELECT
                cols.TABLE_NAME,
                cols.COLUMN_NAME,
                cRefs.CONSTRAINT_NAME,
                refs.REFERENCED_TABLE_NAME,
                refs.REFERENCED_COLUMN_NAME,
                cRefs.UPDATE_RULE,
                cRefs.DELETE_RULE
            FROM INFORMATION_SCHEMA.COLUMNS AS cols
            LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS refs
                ON refs.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.REFERENCED_TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.TABLE_NAME=cols.TABLE_NAME
                AND refs.COLUMN_NAME=cols.COLUMN_NAME
            LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS cons
                ON cons.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND cons.TABLE_NAME=cols.TABLE_NAME
                AND cons.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS cRefs
                ON cRefs.CONSTRAINT_SCHEMA=cols.TABLE_SCHEMA
                AND cRefs.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            WHERE
                cols.TABLE_NAME = %s
                AND cols.TABLE_SCHEMA = DATABASE()
                AND refs.REFERENCED_TABLE_NAME IS NOT NULL
                AND cons.CONSTRAINT_TYPE = 'FOREIGN KEY'
            ;", $this->quote($tableName));

        $rows = $this->queryFetchAll($sql);

        if (empty($rows)) {
            return null;
        }

        $result = [];
        foreach ($rows as $row) {
            $result[$row['CONSTRAINT_NAME']] = $row;
        }

        return $result;
    }
35765
public function joinSlug($modelName, $tableName)
    {
        if ($this->_aliasIsJoined === false) {
            $subSql = 'SELECT ' . SeoSlug::tableName() . '.*
    	FROM ' . SeoSlug::tableName() . '
      	JOIN (
			SELECT ' . SeoSlug::tableName() . '.model_id, MAX(id) AS max_id
           	FROM ' . SeoSlug::tableName() . '
           	WHERE ' . SeoSlug::tableName() . '.model = ' . Yii::$app->db->quoteValue($modelName) . '
            GROUP BY ' . SeoSlug::tableName() . '.model_id
		) as sel ON ' . SeoSlug::tableName() . '.model_id = sel.model_id AND ' . SeoSlug::tableName() . '.id = sel.max_id';
            $sql = '(' . $subSql . ') as ' . SeoSlug::tableName() . '';
            $this->leftJoin($sql, $tableName . '.id = ' . SeoSlug::tableName() . '.model_id');
            $this->_aliasIsJoined = true;
        }
        return $this;
    }
1298009
public function getTableColumns($tableName) {
        if (!$this->tableColumns){
            if (App::get()->cacheExists('mpf:PDOConnection:tableColumns')){
                $this->tableColumns = App::get()->cacheValue('mpf:PDOConnection:tableColumns');
            }
        }
        if (!isset($this->tableColumns[$tableName])) {
            $this->tableColumns[$tableName] = $this->queryAssoc("SHOW COLUMNS FROM `$tableName`");
            App::get()->cacheSet('mpf:PDOConnection:tableColumns', $this->tableColumns);
        }
        return $this->tableColumns[$tableName];
    }
104153
public function getTableColumns($tableName)
    {
        $sql = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = :database AND TABLE_NAME = :tableName;";
        $columns = $this->raw($sql, [':database' => $this->getDatabaseName(), ':tableName' => $tableName], 'fetchAll');
        $return_array = [];
        foreach ($columns as $c) {
            $return_array[] = $c->COLUMN_NAME;
        }
        return $return_array;
    }
772348
protected function _getColumns($tableName)
    {

        $params = [
            ':schemaName' => $this->_adapter->getSchemaName(),
            ':tableName' => $tableName
        ];
        return $this->_adapter->query($this->_getColumnsSql, $params);
    }
900185
public function getModelClass(string $modelName): ?string
    {
        if (isset($this->models[$modelName])) {
            return $this->models[$modelName];
        }

        return null;
    }
364589
public function getIndexes($tableName)
    {
        $sql = sprintf('SHOW INDEX FROM %s', $this->ident($tableName));
        $rows = $this->pdo->query($sql)->fetchAll();
        $result = [];
        foreach ($rows as $row) {
            if (isset($row['Cardinality'])) {
                unset($row['Cardinality']);
            }
            $name = $row['Key_name'];
            $seq = $row['Seq_in_index'];
            $result[$name][$seq] = $row;
        }

        return $result;
    }
1216136
public function getModelJoinByTableName($tableName) {
        foreach ($this->joins as $join) {
            if ($join instanceof ModelJoin && $join->getTableMap()->getName() == $tableName) {
                return $join;
            }
        }

        return null;
    }
349925
public function getColumnNames(string $tableName): array
    {
        $result = [];
        foreach ($this->getColumns($tableName) as $value) {
            $field = $value['column_name'];
            $result[$field] = $field;
        }

        return $result;
    }
37418
public function getColumns(string $tableName): array
    {
        $sql = 'SELECT
            column_name,
            column_default,
            is_nullable,
            data_type,
            character_maximum_length,
            character_octet_length,
            numeric_precision,
            numeric_scale,
            character_set_name,
            collation_name,
            column_type,
            column_key,
            extra,
            `privileges`,
            column_comment
            FROM information_schema.columns
            WHERE table_schema = %s
            AND table_name = %s;';

        [$dbName, $tableName] = $this->parseTableName($tableName);
        $sql = sprintf($sql, $dbName, $tableName);

        $result = $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);

        return $result ?: [];
    }
768587
public function getModelPersister($modelName)
    {
        if (!isset($this->persisters[$modelName])) {
            $class = $this->manager->getClassMetadata($modelName);

            $this->persisters[$modelName] = new ModelPersister($this->manager, $this, $class);
        }

        return $this->persisters[$modelName];
    }