create store for comment draft

This commit is contained in:
isUnknown 2024-12-19 16:03:20 +01:00
parent 13cbfd8309
commit 94ae220174
7 changed files with 162 additions and 47 deletions

View file

@ -4,13 +4,15 @@ namespace adrienpayet\D2P\data;
class Position
{
public int $pageIndex;
public ?int $pageIndex = null;
public ?float $x = null;
public ?float $y = null;
public function __construct(array $data)
{
$this->pageIndex = $data['pageIndex'];
if (isset($data["pageIndex"])) {
$this->pageIndex = $data['pageIndex'];
}
if (isset($data["x"])) {
$this->x = (float) $data['x'];
$this->y = (float) $data['y'];
@ -18,9 +20,11 @@ class Position
}
public function toArray() {
$array = [
"pageIndex" => $this->pageIndex,
];
$array = [];
if ($this->pageIndex) {
$array["pageIndex"] = $this->pageIndex;
}
if ($this->x) {
$array["x"] = $this->x;

View file

@ -31,7 +31,6 @@ return [
"file" => $file
],
"position" => [
"pageIndex" => $data->position->pageIndex,
"x" => $data->position->x,
"y" => $data->position->y
],
@ -42,6 +41,10 @@ return [
"type" => "comment",
];
if ($data->position->pageIndex) {
$commentData["position"]["pageIndex"] = $data->position->pageIndex;
}
$newComment = new Comment($commentData);
$comments[] = $newComment->toArray();