/** * Prepares a data provider * * @param DataProviderInterface|ActiveDataProvider $dataProvider the data provider to prepare * * @return array the prepared response */ public function prepareActiveDataProvider(DataProviderInterface $dataProvider) { $data = array_map(array($this, 'prepare'), $dataProvider->getData()); $pagination = $dataProvider->getPagination(); $model = $dataProvider->model; if ($model instanceof ModelInterface) { $containerName = $model->controllerID(); } else { $containerName = lcfirst(get_class($model)); } $prepared = array('total' => (int) $dataProvider->getTotalItemCount(), 'limit' => $pagination ? $pagination->getPageSize() : null, 'currentPage' => $pagination ? $pagination->getCurrentPage() + 1 : null, 'params' => $dataProvider->getParams(), '_embedded' => array($containerName => $data), '_links' => array()); $prepared['_links'] = $dataProvider->getLinks(); return $prepared; }
/** * @inheritDoc */ public function prepareActiveDataProvider(DataProviderInterface $dataProvider) { /* @var DataProviderInterface|ActiveDataProvider $dataProvider */ /* @var \CModel|\Restyii\Model\ModelInterface $model */ $out = array(); $model = $dataProvider->model; if ($model instanceof ModelInterface) { $out[] = "# " . $model->classLabel(true) . "\n"; $total = $dataProvider->getTotalItemCount(); $out[] = \Yii::t('resource', "n==0#There are no {collectionLabel}.|n==1#There is one {resourceLabel}.|n>1#There are {n} {collectionLabel}.", array($total, '{collectionLabel}' => $model->classLabel(true), '{resourceLabel}' => $model->classLabel())); } else { $out[] = "# " . get_class($model) . "\n"; } $out[] = "\n"; foreach ($dataProvider->getData() as $item) { $out[] = $this->prepare($item); } return implode("\n", $out); }
/** * @inheritDoc */ public function prepareActiveDataProvider(DataProviderInterface $dataProvider) { /* @var DataProviderInterface|ActiveDataProvider $dataProvider */ /* @var \CModel|\Restyii\Model\ModelInterface $model */ $model = $dataProvider->model; if ($model instanceof \Restyii\Model\ModelInterface) { $names = $model->getVisibleAttributeNames(); } else { $names = $model->attributeNames(); } $rows = array($names); foreach ($dataProvider->getData() as $item) { $row = array(); foreach ($names as $name) { $row[] = $item->{$name}; } $rows[] = $row; } return $rows; }