Exemplo n.º 1
0
 /**
  * Serializes a pagination into an array.
  * @param \yii\data\Pagination $pagination
  * @return array the array representation of the pagination
  * @see addPaginationHeaders()
  */
 protected function serializePagination($pagination)
 {
     if ($this->serializedPagination !== null) {
         return $this->serializedPagination;
     }
     /** @var \yii\rest\Serializer $serializer */
     $serializer = $this->serializer;
     return $this->serializedPagination = [$serializer->linksEnvelope => \yii\web\Link::serialize($pagination->getLinks(true)), $serializer->metaEnvelope => ['totalCount' => $pagination->totalCount, 'pageCount' => $pagination->getPageCount(), 'currentPage' => $pagination->getPage() + 1, 'perPage' => $pagination->getPageSize()]];
 }
Exemplo n.º 2
0
 /**
  * Adds HTTP headers about the pagination to the response.
  * @param Pagination $pagination
  */
 protected function addPaginationHeaders($pagination)
 {
     $links = [];
     foreach ($pagination->getLinks(true) as $rel => $url) {
         $links[] = "<{$url}>; rel={$rel}";
     }
     $this->response->getHeaders()->set($this->totalCountHeader, $pagination->totalCount)->set($this->pageCountHeader, $pagination->getPageCount())->set($this->currentPageHeader, $pagination->getPage() + 1)->set($this->perPageHeader, $pagination->pageSize)->set('Link', implode(', ', $links));
 }
Exemplo n.º 3
0
 /**
  * Serializes a pagination into an array.
  * @param Pagination $pagination
  * @return array the array representation of the pagination
  * @see addPaginationHeaders()
  */
 protected function serializePagination($pagination)
 {
     return [$this->linksEnvelope => Link::serialize($pagination->getLinks(true)), $this->metaEnvelope => ['total-count' => $pagination->totalCount, 'page-count' => $pagination->getPageCount(), 'current-page' => $pagination->getPage() + 1, 'per-page' => $pagination->getPageSize()]];
 }