public function getPagination() { $links = []; if ($this->itemsPerPage == 0) { $totalpages = 1; } else { $totalpages = ceil($this->totalItems / $this->itemsPerPage); } $query = 'songs?limit=' . $this->itemsPerPage . '&start='; // First array_push($links, ResponseObject::generateLink('first', BASE_URL . $query . 1)); $links[0]->page = 1; // Last array_push($links, ResponseObject::generateLink('last', BASE_URL . $query . $totalpages)); $links[1]->page = $totalpages; // Previous if ($this->page <= 1) { $prevPage = 1; } else { $prevPage = $this->page - 1; } array_push($links, ResponseObject::generateLink('previous', BASE_URL . $query . $prevPage)); $links[2]->page = $prevPage; // Next if ($this->page >= $totalpages) { $nextPage = $totalpages; } else { $nextPage = $this->page + 1; } array_push($links, ResponseObject::generateLink('next', BASE_URL . $query . $nextPage)); $links[3]->page = $nextPage; $pagination = new stdClass(); $pagination->currentPage = $this->page; $pagination->currentItems = count($this->songs); $pagination->totalItems = $this->totalItems; $pagination->totalPages = $totalpages; $pagination->links = $links; return $pagination; }
public function getResponseItem($detailed = false) { $song = new stdClass(); $song->id = $this->id; $song->slug = $this->slug; $song->title = $this->title; $song->artist = $this->artist; $song->added = $this->added; if ($detailed) { $song->notes = $this->notes; $song->key = $this->key; $song->examples = $this->examples; } else { $song->links = [ResponseObject::generateLink('self', BASE_URL . 'songs/' . $this->slug), ResponseObject::generateLink('collection', BASE_URL . 'songs')]; } return $song; }