Get all records.

@param type  $fields
@param mixed $model

@return type
185226
public function all($model, $fields = null)
    {
        $table = $this->getPrefix($model);
        $order = '';

        if (isset($fields['order'])) {
            $order = 'ORDER BY '.$fields['order'];
            unset($fields['order']);
        }

        //
        $sql = "SELECT * FROM `{$table}` {$order}";

        //
        $results = $this->getResults($sql);

        //
        return $results;
    }
852679
protected function getFieldsFromModels($models)
    {
        if (!$models->first()) {
            // No models, we can't add any columns.
            return [];
        }

        $model = $models->first();

        // These are the Laravel basic timestamp fields which we don't want to display, by default
        $timestamp_fields = ['created_at', 'updated_at', 'deleted_at'];
        // Grab the basic fields from the first model
        $fields = array_keys($model->toArray());
        // Remove the timestamp fields
        $fields = array_diff($fields, $timestamp_fields);
        if ($model->isSortable) {
            // Add the fields from the model's sortable array
            $fields = array_unique(array_merge($fields, $model->getSortable()));
        }

        return $fields;
    }
978494
public function map($results, $model)
    {
        if ($results['hits']['total'] === 0) {
            return Collection::make();
        }

        $keys = collect($results['hits']['hits'])
            ->pluck('_id')->values()->all();

        $models = $model->whereIn(
            $model->getKeyName(), $keys
        )->get()->keyBy($model->getKeyName());

        return collect($results['hits']['hits'])->map(function ($hit) use ($model, $models) {
            return $models[$hit['_id']];
        });
    }
789107
public function select($fields = '*')
    {
        $query = new Query\SelectQuery();

        if ($this->pdo) {
            $query->setPDO($this->pdo);
        }

        return $query->select($fields);
    }
267113
public function getIndexGridColumns($model, $fields)
    {
        $id = Yii::$app->request->getQueryParam('id');
        $relationName = Yii::$app->request->getQueryParam('relation');
        $multiple = Yii::$app->request->getQueryParam('multiple', 'true') === 'true';
        foreach ($fields as $key => $field) {
            if (((is_array($field) || (!is_string($field) && is_callable($field))) && $key === $relationName)
                || $field === $relationName
            ) {
                unset($fields[$key]);
            }
        }
        return array_merge([
            [
                'class'         => 'yii\grid\CheckboxColumn',
                'multiple'      => $multiple,
                'headerOptions' => ['class' => 'column-serial'],
                'checkboxOptions' => function ($model, $key, $index, $column) use ($id, $relationName) {
                    /** @var \yii\db\ActiveRecord $model */
                    $options = [
                        'value' => is_array($key)
                            ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
                            : $key,
                    ];
                    if (empty($relationName) || $model->$relationName === null || trim($id) === '') {
                        return $options;
                    }
                    $relation = $model->getRelation($relationName);
                    if ($relation->multiple) {
                        /** @var \yii\db\ActiveRecord $relationClass */
                        $relationClass = $relation->modelClass;
                        if (Action::importKey($relationClass::primaryKey(), $id)
                            === $model->getAttributes(array_keys($relation->link))
                        ) {
                            $options['checked']  = true;
                            $options['disabled'] = true;
                        }
                    } elseif (Action::exportKey($relation->one()->getPrimaryKey()) === $id) {
                        $options['checked']  = true;
                        $options['disabled'] = true;
                    }
                    return $options;
                },
            ],
            [
                'class'         => 'yii\grid\SerialColumn',
                'headerOptions' => ['class' => 'column-serial'],
            ],
        ], self::getGridColumns($model, $fields));
    }
1098298
public function process(PaginationInterface $pagination, array $fields)
    {
        $data = array();
        $identifier = array();
        /** @var \SymfonyId\AdminBundle\Model\ModelInterface $record */
        foreach ($pagination as $key => $record) {
            $temp = array();
            $identifier[$key] = $record->getId();

            foreach ($fields as $k => $property) {
                $field = $property;
                $numberFormat = array();
                if (is_array($property)) {
                    $field = $property['field'];
                    $numberFormat = $property['format'];
                }

                $result = MethodInvoker::invokeGet($record, $field);
                if (null !== $result) {
                    if (!empty($numberFormat)) {
                        $result = number_format($result, $numberFormat['decimal'], $numberFormat['decimal_point'], $numberFormat['thousand_separator']);
                    }
                } else {
                    $result = '';
                }

                array_push($temp, $result);
            }

            $data[$key] = $temp;
        }

        $records = new Records();
        $records->setData($data);
        $records->setIdentifier($identifier);

        return $records;
    }
1123434
public function search($model)
    {
        $method = 'search';

        $condition = $this->condition ?: [[]];

        $params = $this->buildParams('limit', 'offset');

        $result = $this->call($model, $method, $condition, $params);

        //Reset params for future queries.
        $this->resetParams('limit', 'offset', 'condition');

        return $this->makeResponse($result);
    }
478265
public function getIndexGridColumns($model, $fields)
    {
        /** @var ActiveController $controller */
        $controller = $this->controller;
        $actionColumn = new ActionColumn();
        $actionColumn->buttonOptions['class'] = 'operation-button';
        $extraColumns = [
            [
                'class'         => \yii\grid\ActionColumn::className(),
                'headerOptions' => ['class' => 'column-action'],
                'controller'    => Yii::$app->crudModelsMap[$model::className()],
                'template'      => '{update} {delete} {toggle}', // {view} removed because representing column is linked
                'buttons' => [
                    'view'   => function ($url, $model, $key) use ($controller, $actionColumn) {
                        if (!$controller->hasAccess('read', $model)) {
                            return null;
                        }

                        return $actionColumn->buttons['view']($url, $model, $key);
                    },
                    'update' => function ($url, $model, $key) use ($controller, $actionColumn) {
                        if (!$controller->hasAccess('update', $model)) {
                            return null;
                        }

                        return $actionColumn->buttons['update']($url, $model, $key);
                    },
                    'delete' => function ($url, $model, $key) use ($controller, $actionColumn) {
                        if (!$controller->hasAccess('delete', $model)) {
                            return null;
                        }

                        return $actionColumn->buttons['delete']($url, $model, $key);
                    },
                    'toggle' => function ($url, $model, $key) use ($controller, $actionColumn) {
                        /** @var \yii\db\ActiveRecord $model */
                        if ($model->getBehavior('toggable') === null || !$controller->hasAccess('delete', $model)) {
                            return null;
                        }

                        $enabled = $model->isEnabled();
                        $icon    = '<span class="glyphicon glyphicon-'.($enabled ? 'ban' : 'reply').'"></span>';
                        $options = array_merge([
                            'title'       => $enabled ? Yii::t('app', 'Disable') : Yii::t('app', 'Enable'),
                            'aria-label'  => $enabled ? Yii::t('app', 'Disable') : Yii::t('app', 'Enable'),
                            'data-pjax'   => '0',
                        ], $enabled ? [
                            'data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?'),
                        ] : [], $actionColumn->buttonOptions);
                        return \yii\helpers\Html::a($icon, $url, $options);
                    },
                ],
            ],
        ];
        if ($this->useSerialColumn) {
            $extraColumns[] = [
                'class'         => \yii\grid\SerialColumn::className(),
                'headerOptions' => ['class' => 'column-serial'],
            ];
        }
        if ($this->useCheckboxColumn) {
            //$classParts = explode('\\', $this->modelClass);
            $extraColumns[] = [
                'class'         => \yii\grid\CheckboxColumn::className(),
                'headerOptions' => ['class' => 'column-checkbox'],
                'multiple'      => true,
                //'name'          => end($classParts).'[]',
            ];
        }

        return array_merge($extraColumns, static::getGridColumns($model, $fields));
    }
868459
public function fetchAllOf(string $field): array
    {
        $array = [];
        foreach ($this->fetchAllGenerator() as $record) {
            $array[] = $record[$field] ?? null;
        }

        return $array;
    }
21552
public function seeRecord($model, $attributes = [])
    {
        $record = $this->findRecord($model, $attributes);
        if (!$record) {
            $this->fail("Couldn't find $model with " . json_encode($attributes));
        }
        $this->debugSection($model, json_encode($record));
    }
1196607
private function buildQuery(Model $model = null)
    {
        $query = $this->model->collections();

        $query = $query->whereCollectionName($this->collectionName);

        if ($model) {
            $query = $query->where('item_id', $model->id)
                           ->where('item_type', get_class($model));
        }

        if (!$model && $this->itemType) {
            $query = $query->where('item_type', '=', $this->itemType);
        }

        return $query;
    }
1180071
public function fetchAllOfGenerator(string $field): Generator
    {
        foreach ($this->fetchAllGenerator() as $index => $record) {
            yield $index => $record[$field] ?? null;
        }
    }
1246422
public function setFields($fields)
    {
        if ($fields instanceof RecordFields) {
            $this->fields = $fields;
        } else {
            if (is_array($fields)) {
                $fields       = new RecordFields($fields);
                $this->fields = $fields;
            }
        }
        return $this;
    }
639435
public function getField($field)
    {
        if (isset($this->allFields[$field])) {
            return $this->allFields[$field];
        }

        return null;
    }
770287
public function filterFields(Model $model, $filter = array()) {
        if (empty($filter) || $filter === '*') {
            return $model->fields;
        }

        $fields = array();

        foreach ($filter as $field) {
            list($table, $field) = pluginSplit($field);

            $fields[$field] = $model->fields[$field];
        }

        return $fields;
    }
1095390
public function unique($model, $field) {
        $this->check_role = 'unique';
        /* @var $model Record */
        $model = new $model;
        $result = empty($model::find([$field => $this->value]));
        $this->checkResult($result);
        return $this;
    }
472325
private function getFieldsConfiguration($model, $fields = [])
    {
        $configuration = $properties = [];
        $ro = new \ReflectionObject($model);
        if (empty($fields)) {
            $properties = $ro->getProperties();
        } else {
            foreach (array_keys($fields) as $field) {
                // setting the configuration to null guarantees the order of elements in there
                // to match the order specified in $fields
                $configuration[$field] = null;
                if (! $ro->hasProperty($field)) {
                    continue; // most prob a class-level field, order will be maintained due to trick above
                }
                $properties[] = $ro->getProperty($field);
            }
        }
        $fieldConfigurations = [];
        // first are coming properties
        foreach ($properties as $property) {
            $propertyName = $property->getName();
            $propertyIsListed = array_key_exists($propertyName, $fields);
            if (!empty($fields) && !$propertyIsListed) {
                continue; // list of fields was specified and current one is not there
            }
            $fieldConfiguration = $this->annotationReader->getPropertyAnnotation($property, Field::class);
            if ($fieldConfiguration === null && !$propertyIsListed) {
                continue;
            }
            $fieldConfigurations[$propertyName] = $fieldConfiguration;
        }
        // later are coming class-level fields. We need to iterate through all annotations as there's no method
        // to get *all* occurrences of chosen annotation.
        foreach ($this->annotationReader->getClassAnnotations($ro) as $annotation) {
            if (! $annotation instanceof Field) {
                continue;
            }
            $propertyName = $annotation->value;
            if (!empty($fields) && !array_key_exists($propertyName, $fields)) {
                continue; // list of fields was specified and current one is not there
            }
            $fieldConfigurations[$propertyName] = $annotation;
        }
        foreach ($fieldConfigurations as $propertyName => $fieldConfiguration) {
            $configuration[$propertyName] = (array)$fieldConfiguration;
            if (isset($fields[$propertyName])) {
                $configuration[$propertyName] = array_replace_recursive($configuration[$propertyName], $fields[$propertyName]);
            }
            if ($configuration[$propertyName]['type'] === EmbedType::class) {
                if (! $ro->hasProperty($propertyName) || ($value = $ro->getProperty($propertyName)->getValue($model)) === null) {
                    $value = $this->instantiator->instantiate($configuration[$propertyName]['class']);
                }
                $configuration[$propertyName]['data_class'] = $configuration[$propertyName]['class'];
                $configuration[$propertyName]['model'] = $value;
            }
            // this variable comes from Doctrine\Common\Annotations\Annotation
            unset($configuration[$propertyName]['value']);
        }
        return $configuration;
    }