designtopack/public/site/plugins/classes/location/Location.php

45 lines
1 KiB
PHP
Raw Normal View History

<?php
namespace adrienpayet\D2P\data\location;
class Location
{
protected PageDetails $page;
protected ?FileDetails $file = null;
2024-12-19 10:32:48 +01:00
protected ?array $parent = null;
public function __construct(array $data)
{
$this->page = new PageDetails($data["page"]);
if (isset($data['file'])) {
$this->file = new FileDetails($data["file"]);
}
2024-12-19 10:32:48 +01:00
if (isset($data["parent"])) {
$this->parent = [
"author" => [
"name" => $data["parent"]["author"]["name"],
"email" => $data["parent"]["author"]["email"],
],
"id" => $data["parent"]["id"]
];
}
}
public function toArray() {
$array = [
"page" => $this->page->toArray(),
];
if ($this->file) {
$array["file"] = $this->file;
}
2024-12-19 10:32:48 +01:00
if ($this->parent) {
$array["parent"] = $this->parent;
2024-12-18 18:39:45 +01:00
}
return $array;
}
}