Data providers are components that sort and paginate data, and provide them to widgets such as GridView, ListView. For more details and usage information on DataProviderInterface, see the guide article on data providers.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
コード例 #1
0
ファイル: Serializer.php プロジェクト: dextercool/yii2-easyui
 /**
  * Serializes a data provider.
  * @param DataProviderInterface $dataProvider
  * @return array the array representation of the data provider.
  */
 protected function serializeDataProvider($dataProvider)
 {
     $models = $this->serializeModels($dataProvider->getModels());
     if ($dataProvider->getPagination() === false) {
         return $models;
     } else {
         return ['total' => $dataProvider->getTotalCount(), 'rows' => $models];
     }
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     /* @var $formatter Formatter */
     $formatter = Yii::$app->formatter;
     $prepodavatel = $formatter->asFizLico($this->zanyatie->prepodavatel_rel);
     $date = $formatter->asDate($this->zanyatie->data);
     $interval = $formatter->asZanyatieTimeInterval($this->zanyatie->nomer, Formatter::ZANYATIE_TIME_INTERVAL_FORMAT_FROM_TO);
     return Html::tag('p', "{$date} {$interval} преподаватель {$prepodavatel} занят в:") . "\n" . $this->renderKursy($this->dataProvider->getModels());
 }
コード例 #3
0
ファイル: Serializer.php プロジェクト: yuexiaoyun/lulucms
 /**
  * Serializes a data provider.
  * @param DataProviderInterface $dataProvider
  * @return array the array representation of the data provider.
  */
 protected function serializeDataProvider($dataProvider)
 {
     $models = $this->serializeModels($dataProvider->getModels());
     if (($pagination = $dataProvider->getPagination()) !== false) {
         $this->addPaginationHeaders($pagination);
     }
     if ($this->request->getIsHead()) {
         return null;
     } elseif ($this->collectionEnvelope === null) {
         return $models;
     } else {
         $result = [$this->collectionEnvelope => $models];
         if ($pagination !== false) {
             return array_merge($result, $this->serializePagination($pagination));
         } else {
             return $result;
         }
     }
 }
コード例 #4
0
 /**
  * Get items from data provider.
  *
  * @return array
  */
 protected function getItems()
 {
     return $this->dataProvider->getModels();
 }
コード例 #5
0
ファイル: Serializer.php プロジェクト: pointdnd/yii2-modular
 /**
  * Serializes a data provider.
  * @param DataProviderInterface $dataProvider
  * @return array the array representation of the data provider.
  */
 protected function serializeDataProvider($dataProvider)
 {
     $models = $this->serializeModels($dataProvider->getModels());
     if (($pagination = $dataProvider->getPagination()) !== false) {
         $this->addPaginationHeaders($pagination);
     }
     if ($this->request->getIsHead()) {
         return null;
     } elseif ($this->collectionEnvelope === null) {
         return $models;
     } else {
         $result = ['success' => 1, 'message' => \Yii::$app->response->statusText, 'status' => \Yii::$app->response->getStatusCode(), $this->collectionEnvelope => $models];
         if ($pagination !== false) {
             return array_merge($result, $this->serializePagination($pagination));
         } else {
             return $result;
         }
     }
 }
コード例 #6
0
ファイル: IndexPage.php プロジェクト: hiqdev/hipanel-core
 public function renderSorter(array $options)
 {
     return LinkSorter::widget(array_merge(['show' => true, 'sort' => $this->dataProvider->getSort(), 'buttonClass' => 'btn btn-default dropdown-toggle btn-sm'], $options));
 }
コード例 #7
0
ファイル: Serializer.php プロジェクト: tuyakhov/yii2-json-api
 /**
  * Serializes a data provider.
  * @param DataProviderInterface $dataProvider
  * @return array the array representation of the data provider.
  */
 protected function serializeDataProvider($dataProvider)
 {
     if ($this->request->getIsHead()) {
         return null;
     } else {
         $models = [];
         $includedModels = [];
         foreach ($dataProvider->getModels() as $model) {
             if ($model instanceof ResourceInterface) {
                 $models[] = $this->serializeModel($model);
                 $included = $this->serializeIncluded($model);
                 foreach ($included as $document) {
                     $includedModels[] = $document;
                 }
             }
         }
         $result = ['data' => $models];
         if (!empty($includedModels)) {
             $result['included'] = $includedModels;
         }
         if (($pagination = $dataProvider->getPagination()) !== false) {
             return array_merge($result, $this->serializePagination($pagination));
         }
         return $result;
     }
 }