Scheduling UI corrected

This commit is contained in:
2022-11-30 20:45:18 -03:00
parent 5e4e52e620
commit c0ddd00cc6
4 changed files with 115 additions and 200 deletions

View File

@ -108,7 +108,12 @@ class Message implements Model
}
public function getState(string $name): \ProVM\Emails\Model\State\Message
{
return $this->getStates()[$name];
try {
return $this->getStates()[$name];
} catch (\Exception $e) {
$this->newState($name);
return $this->getStates()[$name];
}
}
public function addState(\ProVM\Emails\Model\State\Message $state): Message
{
@ -127,6 +132,7 @@ class Message implements Model
$this->addState((new \ProVM\Emails\Model\State\Message())
->setName($name)
->setMessage($this)
->setValue(false)
);
return $this;
}
@ -143,31 +149,31 @@ class Message implements Model
{
return $this->getState('downloaded_attachments')->getValue() ?? false;
}
public function hasScheduledDownloads(): bool
{
return $this->getState('scheduled_downloads')->getValue() ?? false;
}
public function doesHaveAttachments(): Message
{
if (!isset($this->getStates()['has_attachments'])) {
$this->newState('has_attachments');
}
$this->getState('has_attachments')->setValue(true);
return $this;
}
public function doesHaveValidAttachments(): Message
{
if (!isset($this->getStates()['valid_attachments'])) {
$this->newState('valid_attachments');
}
$this->getState('valid_attachments')->setValue(true);
return $this;
}
public function doesHaveDownloadedAttachments(): Message
{
if (!isset($this->getStates()['downloaded_attachments'])) {
$this->newState('downloaded_attachments');
}
$this->getState('downloaded_attachments')->setValue(true);
return $this;
}
public function doesHaveScheduledDownloads(): Message
{
$this->getState('scheduled_downloads')->setValue(true);
return $this;
}
protected array $attachments;
public function getAttachments(): array
@ -205,11 +211,12 @@ class Message implements Model
'states' => [
'has_attachments' => $this->hasAttachments(),
'valid_attachments' => $this->hasValidAttachments(),
'downloaded_attachments' => $this->hasDownloadedAttachments()
'downloaded_attachments' => $this->hasDownloadedAttachments(),
'scheduled_downloads' => $this->hasScheduledDownloads()
],
'attachments' => $this->hasValidAttachments() ? array_map(function(Attachment $attachment) {
return $attachment->toArray();
}, $this->getAttachments()) : []
];
}
}
}

View File

@ -111,7 +111,8 @@ class Message extends Repository
$valid_states = [
'has_attachments',
'valid_attachments',
'downloaded_attachments'
'downloaded_attachments',
'scheduled_downloads'
];
foreach ($valid_states as $state_name) {
try {
@ -160,4 +161,4 @@ class Message extends Repository
WHERE `mailbox_id` = ? `subject` = ? AND `from` = ? AND `date_time` = ?";
return $this->fetchOne($query, [$mailbox_id, $subject, $from, $dateTime->format('Y-m-d H:i:s')]);
}
}
}