Beispiel #1
0
 /**
  * @param PaginatedDataInterface $data
  *
  * @return void
  */
 private function addPagingLinksIfNeeded(PaginatedDataInterface $data)
 {
     if ($data->isCollection() === true && (0 < $data->getOffset() || $data->hasMoreItems() === true) && $this->getOriginalUri() !== null) {
         $links = [];
         $linkClosure = $this->createLinkClosure($data->getLimit());
         $prev = DocumentInterface::KEYWORD_PREV;
         $next = DocumentInterface::KEYWORD_NEXT;
         $data->getOffset() <= 0 ?: ($links[$prev] = $linkClosure(max(0, $data->getOffset() - $data->getLimit())));
         $data->hasMoreItems() === false ?: ($links[$next] = $linkClosure($data->getOffset() + $data->getLimit()));
         $this->withLinks($links);
     }
 }
Beispiel #2
0
 /**
  * @param PaginatedDataInterface $data
  * @param string                 $uri
  *
  * @return array
  */
 protected function getRelationshipDescription(PaginatedDataInterface $data, $uri)
 {
     if ($data->hasMoreItems() === false) {
         return [static::DATA => $data->getData()];
     }
     $buildUrl = function ($offset) use($data, $uri) {
         $paramsWithPaging = [PaginationStrategyInterface::PARAM_PAGING_SKIP => $offset, PaginationStrategyInterface::PARAM_PAGING_SIZE => $data->getLimit()];
         $fullUrl = $uri . '?' . http_build_query($paramsWithPaging);
         return $fullUrl;
     };
     $links = [];
     // It looks like relationship can only hold first data rows so we might need `next` link but never `prev`
     if ($data->hasMoreItems() === true) {
         $offset = $data->getOffset() + $data->getLimit();
         $links[DocumentInterface::KEYWORD_NEXT] = $this->createLink($buildUrl($offset));
     }
     return [static::DATA => $data->getData(), static::LINKS => $links];
 }