Skip to content
Snippets Groups Projects

Test

Merged Djojomoenawie, N.E. (Nathan, Student M-CS) requested to merge test into main
7 files
+ 1825
49
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 134
22
@@ -2,55 +2,167 @@
namespace Compucie\Congressus;
use Compucie\Congressus\Model\PaginationMetadata;
class Page extends PaginationMetadata
class Page
{
private bool $hasPrevious;
private ?int $previousPageNumber;
private bool $hasNext;
private ?int $nextPageNumber;
private array $data;
private int $total;
public function __construct(
private mixed $pagination,
private string $responseType,
array $responseBody,
private string $caller,
private array $parameters,
) {
parent::__construct(array(
"total" => $pagination->getTotal(),
"previous_page" => $pagination->getPrevNum(),
"next_page" => $pagination->getNextNum(),
));
$this->setHasPrevious($responseBody["has_prev"]);
$this->setPreviousPageNumber($responseBody["prev_num"]);
$this->setHasNext($responseBody["has_next"]);
$this->setNextPageNumber($responseBody["next_num"]);
$this->setData($responseBody["data"]);
$this->setTotal($responseBody["total"]);
}
private function getPagination(): mixed
/**
* Get the value of hasPrevious
*/
public function hasPrevious(): bool
{
return $this->pagination;
return $this->hasPrevious;
}
/**
* Return the client's method that was called to request this page.
* Set the value of hasPrevious
*/
public function getCaller(): string
public function setHasPrevious(bool $hasPrevious): self
{
return $this->caller;
$this->hasPrevious = $hasPrevious;
return $this;
}
/**
* Return the parameters that yielded this page.
* Get the value of previousPageNumber
*/
public function getParameters(): array
public function getPreviousPageNumber(): int
{
return $this->parameters;
return $this->previousPageNumber;
}
public function hasPrevious(): bool
/**
* Set the value of previousPageNumber
*/
public function setPreviousPageNumber(?int $previousPageNumber): self
{
return $this->getPagination()->getHasPrev();;
$this->previousPageNumber = $previousPageNumber;
return $this;
}
/**
* Get the value of hasNext
*/
public function hasNext(): bool
{
return $this->getPagination()->getHasNext();
return $this->hasNext;
}
/**
* Set the value of hasNext
*/
public function setHasNext(bool $hasNext): self
{
$this->hasNext = $hasNext;
return $this;
}
/**
* Get the value of nextPageNumber
*/
public function getNextPageNumber(): int
{
return $this->nextPageNumber;
}
/**
* Set the value of nextPageNumber
*/
public function setNextPageNumber(?int $nextPageNumber): self
{
$this->nextPageNumber = $nextPageNumber;
return $this;
}
/**
* Get the value of data
*/
public function getData(): array
{
return $this->data;
}
/**
* Set the value of data
*/
public function setData(array $data): void
{
$elementType = array_fill(
0,
count($data),
str_replace("Pagination", "", $this->getResponseType())
);
$this->data = array_map([$this, 'buildObjectArray'], $elementType, $data);
}
/**
* Get the value of total
*/
public function getTotal(): int
{
return $this->total;
}
/**
* Set the value of total
*/
public function setTotal(int $total): self
{
$this->total = $total;
return $this;
}
/**
* Get the value of responseType
*/
public function getResponseType(): string
{
return $this->responseType;
}
/**
* Get the value of caller
*/
public function getCaller(): string
{
return $this->caller;
}
/**
* Get the value of parameters
*/
public function getParameters(): array
{
return $this->parameters;
}
public function getData(): mixed
private static function buildObjectArray($type, $element): mixed
{
return $this->getPagination()->getData();
return new $type($element);
}
}
Loading