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)
Esempio n. 1
0
 /**
  * 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];
     }
 }
 /**
  * @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());
 }
Esempio n. 3
0
 /**
  * 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;
         }
     }
 }
 /**
  * Get items from data provider.
  *
  * @return array
  */
 protected function getItems()
 {
     return $this->dataProvider->getModels();
 }
Esempio n. 5
0
 /**
  * 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;
         }
     }
 }
Esempio n. 6
0
 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));
 }
Esempio n. 7
0
 /**
  * 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;
     }
 }