/** * Constructor. * @param BaseDataProvider $dataProvider the data provider to iterate over * @param integer $pageSize pageSize to use for iteration. This is the number of objects loaded into memory at the same time. */ public function __construct(BaseDataProvider $dataProvider, $pageSize = null) { $this->_dataProvider = $dataProvider; $this->_totalItemCount = $dataProvider->getTotalCount(); if (($pagination = $this->_dataProvider->getPagination()) === false) { $this->_dataProvider->setPagination($pagination = new Pagination()); } if ($pageSize !== null) { $pagination->pageSize = $pageSize; } }
/** * @inheritdoc */ public function init() { parent::init(); if (!$this->kurs instanceof Kurs) { throw new InvalidConfigException(); } }
public function init() { parent::init(); $meta = $this->data['_meta']; $this->totalCount = $meta['totalCount']; $this->pagination = ['totalCount' => $meta['totalCount'], 'pageSize' => $meta['perPage']]; }
public function setSort($value) { parent::setSort($value); if (($sort = $this->getSort()) !== false && empty($sort->attributes)) { /** @var Model $model */ $model = new $this->modelClass(); if ($model instanceof Model) { foreach ($model->attributes() as $attribute) { $sort->attributes[$attribute] = ['asc' => [$attribute => SORT_ASC], 'desc' => [$attribute => SORT_DESC], 'label' => $model->getAttributeLabel($attribute)]; } } } }
/** * @inheritdoc */ public function setSort($value) { parent::setSort($value); if (($sort = $this->getSort()) !== false && $this->query instanceof ActiveQueryInterface) { /* @var $model Model */ $model = new $this->query->modelClass(); if (empty($sort->attributes)) { foreach ($model->attributes() as $attribute) { $sort->attributes[$attribute] = ['asc' => [$attribute => SORT_ASC], 'desc' => [$attribute => SORT_DESC], 'label' => $model->getAttributeLabel($attribute)]; } } else { foreach ($sort->attributes as $attribute => $config) { if (!isset($config['label'])) { $sort->attributes[$attribute]['label'] = $model->getAttributeLabel($attribute); } } } } }
/** * @param string $id The id of the widget * @param \yii\data\BaseDataProvider $dataProvider The dataprovider for the widget * @param \Closure $filter The filter to manipulate the data. * @return array The data required to create the list and pagination. */ protected static function getData($id, $dataProvider, $filter) { $data = ['id' => $id]; $data['count'] = $dataProvider->getCount(); if (($pagination = $dataProvider->getPagination()) !== false) { $data['totalCount'] = $dataProvider->getTotalCount(); $data['begin'] = $pagination->getPage() * $pagination->pageSize + 1; $data['end'] = $data['begin'] + $data['count'] - 1; if ($data['begin'] > $data['end']) { $data['begin'] = $data['end']; } $data['page'] = $pagination->getPage() + 1; $data['pageCount'] = $pagination->pageCount; } else { $data['totalCount'] = $dataProvider->getTotalCount(); $data['pageCount'] = 1; $data['page'] = 1; $data['begin'] = $data['page'] = $data['pageCount'] = 1; $data['end'] = $data['totalCount'] = $data['count']; } $pagination = $dataProvider->getPagination(); if ($pagination !== false) { $data['pageParam'] = $pagination->pageParam; $data['pageSizeParam'] = $pagination->pageSizeParam; $data['pageSizeLimit'] = $pagination->pageSizeLimit; $data['pageLinks'] = $pagination->getLinks(); $currentPage = $pagination->getPage(); $pageCount = $pagination->getPageCount(); $maxButtonCount = 10; $beginPage = max(0, $currentPage - (int) ($maxButtonCount / 2)); if (($endPage = $beginPage + $maxButtonCount - 1) >= $pageCount) { $endPage = $pageCount - 1; $beginPage = max(0, $endPage - $maxButtonCount + 1); } for ($i = $beginPage; $i <= $endPage; $i++) { $data['pages'][] = ['pageNo' => $i + 1, 'pageUrl' => $pagination->createUrl($i)]; } } $sort = $dataProvider->getSort(); if (!($sort === false || empty($sort->attributes) || $dataProvider->getCount() <= 0)) { $attributes = array_keys($sort->attributes); $data['sort'] = []; foreach ($attributes as $name) { $data['sort'][] = ['name' => $name, 'link' => $sort->createUrl($name)]; } } $models = $dataProvider->getModels(); if ($models) { $data['labels'] = $models[0]->attributeLabels(); } $controller = Yii::$app->controller->id; foreach ($models as $key => $model) { $data['items'][$key] = $filter ? $filter($model) : $model->attributes; $data['items'][$key]['actions'] = ['viewUrl' => BaseUrl::toRoute(["{$controller}/view", 'id' => $model->primaryKey]), 'viewTitle' => Yii::t('app', 'View'), 'updateUrl' => BaseUrl::toRoute(["{$controller}/update", 'id' => $model->primaryKey]), 'updateTitle' => Yii::t('app', 'Update'), 'deleteUrl' => BaseUrl::toRoute(["{$controller}/delete", 'id' => $model->primaryKey]), 'deleteTitle' => Yii::t('app', 'Delete')]; } return $data; }
/** * @inheritdoc * @throws InvalidConfigException */ public function init() { parent::init(); $dp = static::slash(BaseDataProvider::className()); if (empty($this->dataProvider) || !$this->dataProvider instanceof BaseDataProvider) { throw new InvalidConfigException("The 'dataProvider' property must be set and must be an instance of '{$dp}'."); } $kvGrid = static::slash(GridView::classname()); if (empty($this->gridClass)) { $this->gridClass = $kvGrid; } elseif ($this->gridClass !== $kvGrid && !is_subclass_of($this->gridClass, $kvGrid)) { throw new InvalidConfigException("The 'gridClass' must be a class which extends from '{$kvGrid}'."); } $this->initOptions(); $this->registerAssets(); }
/** * Initializes the DB connection component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); if ($this->sql === null) { throw new InvalidConfigException('The "sql" property must be set.'); } }
/** * @inheritdoc */ public function init() { parent::init(); // open file //$this->fileObject = new SplFileObject($this->filename); }
/** * Sets the pagination for this data provider. * @param array|Pagination|boolean $value The pagination to be used by this data provider. * This can be one of the following: * * - a configuration array for creating the pagination object. The "class" element defaults * to 'UrbanIndo\Yii2\DynamoDb\Pagination' * - an instance of [[Pagination]] or its subclass * - false, if pagination needs to be disabled. * * @throws InvalidParamException When the value is not Pagination instance. * @return void */ public function setPagination($value) { if (is_array($value)) { $config = ['class' => Pagination::className()]; if ($this->id !== null) { $config['pageSizeParam'] = $this->id . '-per-page'; } parent::setPagination(Yii::createObject(array_merge($config, $value))); } elseif ($value instanceof Pagination || $value === false) { parent::setPagination($value); } else { throw new InvalidParamException('Only Pagination instance, configuration array or false is allowed.'); } }
/** * Initializes the DB connection component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); if (is_string($this->db)) { $this->db = Yii::$app->getComponent($this->db); } if (!$this->db instanceof Connection) { throw new InvalidConfigException('The "db" property must be a valid DB Connection application component.'); } if ($this->sql === null) { throw new InvalidConfigException('The "sql" property must be set.'); } }