Various updates

This commit is contained in:
2023-06-08 20:49:27 -04:00
parent 3ed5acf75e
commit 9307ba330c
45 changed files with 864 additions and 188 deletions

View File

@ -169,4 +169,8 @@ class Attachment implements Model
'decrypted' => $this->isDecrypted()
];
}
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -58,4 +58,8 @@ class Job implements Model
'executed' => $this->isExecuted()
];
}
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -104,6 +104,9 @@ class Mailbox implements Model
public function lastPosition(): int
{
$state = $this->lastState()->getUIDs();
if (count($state) === 0) {
return 0;
}
return array_key_last($state);
}
@ -119,4 +122,8 @@ class Mailbox implements Model
]
];
}
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -99,14 +99,14 @@ class Message implements Model
{
if (!isset($this->states)) {
try {
$this->setStates($this->getFactory()->find(\ProVM\Emails\Model\State\Message::class)->fetchByMessage($this->getId()));
$this->setStates($this->getFactory()->find(State\Message::class)->fetchByMessage($this->getId()));
} catch (BlankResult $e) {
return [];
}
}
return $this->states;
}
public function getState(string $name): \ProVM\Emails\Model\State\Message
public function getState(string $name): State\Message
{
try {
return $this->getStates()[$name];
@ -115,7 +115,7 @@ class Message implements Model
return $this->getStates()[$name];
}
}
public function addState(\ProVM\Emails\Model\State\Message $state): Message
public function addState(State\Message $state): Message
{
$this->states[$state->getName()] = $state;
return $this;
@ -129,7 +129,7 @@ class Message implements Model
}
protected function newState(string $name): Message
{
$this->addState((new \ProVM\Emails\Model\State\Message())
$this->addState((new State\Message())
->setName($name)
->setMessage($this)
->setValue(false)
@ -219,4 +219,8 @@ class Message implements Model
}, $this->getAttachments()) : []
];
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -47,4 +47,18 @@ class Attachment implements Model
$this->value = $value;
return $this;
}
}
public function toArray(): array
{
return [
'id' => $this->getId(),
'attachment_id' => $this->getAttachment()->getId(),
'name' => $this->getName(),
'value' => $this->getValue()
];
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -30,7 +30,7 @@ class Mailbox implements Model
}
public function getUIDs(): array
{
return $this->uids;
return $this->uids ?? [];
}
public function setId(int $id): Mailbox
@ -65,4 +65,19 @@ class Mailbox implements Model
}
return $this;
}
}
public function toArray(): array
{
return [
'id' => $this->getId(),
'mailbox_id' => $this->getMailbox()->getId(),
'date_time' => $this->getDateTime()->format('Y-m-d H:i:s'),
'count' => $this->getCount(),
'uids' => $this->getUIDs()
];
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}

View File

@ -47,4 +47,18 @@ class Message implements Model
$this->value = $value;
return $this;
}
}
public function toArray(): array
{
return [
'id' => $this->getId(),
'message_id' => $this->getMessage()->getId(),
'name' => $this->getName(),
'value' => $this->getValue()
];
}
public function jsonSerialize(): mixed
{
return $this->toArray();
}
}