Full implemantation
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
namespace ProVM\Emails\Model;
|
||||
|
||||
use ProVM\Common\Define\Model;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
|
||||
class Attachment implements Model
|
||||
{
|
||||
@ -53,13 +54,22 @@ class Attachment implements Model
|
||||
public function getStates(): array
|
||||
{
|
||||
if (!isset($this->states)) {
|
||||
$this->setStates($this->getStateRepository()->fetchByAttachment($this->getId()));
|
||||
try {
|
||||
$this->setStates($this->getStateRepository()->fetchByAttachment($this->getId()));
|
||||
} catch (BlankResult $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return $this->states;
|
||||
}
|
||||
public function getState(string $name): State\Attachment
|
||||
{
|
||||
return $this->getStates()[$name];
|
||||
try {
|
||||
return $this->getStates()[$name];
|
||||
} catch (\Exception $e) {
|
||||
$this->newState($name);
|
||||
return $this->getStates()[$name];
|
||||
}
|
||||
}
|
||||
public function addState(State\Attachment $state): Attachment
|
||||
{
|
||||
@ -76,19 +86,47 @@ class Attachment implements Model
|
||||
protected function newState(string $name): Attachment
|
||||
{
|
||||
$this->addState((new State\Attachment())
|
||||
->setName($name)
|
||||
->setAttachment($this)
|
||||
->setName($name)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFullFilename(): string
|
||||
{
|
||||
return implode(' - ', [
|
||||
$this->getMessage()->getSubject(),
|
||||
$this->getMessage()->getDateTime()->format('Y-m-d His'),
|
||||
$this->getFilename()
|
||||
]);
|
||||
}
|
||||
|
||||
public function isDownloaded(): bool
|
||||
{
|
||||
return $this->getState('downloaded')?->getValue() ?? false;
|
||||
}
|
||||
public function isEncrypted(): bool
|
||||
{
|
||||
return $this->getState('encrypted')->getValue() ?? false;
|
||||
return $this->getState('encrypted')?->getValue() ?? false;
|
||||
}
|
||||
public function isDecrypted(): bool
|
||||
{
|
||||
return $this->getState('encrypted')->getValue() ?? false;
|
||||
try {
|
||||
return $this->getState('decrypted')?->getValue() ?? false;
|
||||
} catch (\Exception $e) {
|
||||
$this->newState('decrypted');
|
||||
return $this->getState('decrypted')?->getValue() ?? false;
|
||||
}
|
||||
}
|
||||
public function itIsDownloaded(): Attachment
|
||||
{
|
||||
try {
|
||||
$this->getState('downloaded')->setValue(true);
|
||||
} catch (\Exception $e) {
|
||||
$this->newState('downloaded');
|
||||
$this->getState('downloaded')->setValue(true);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function itIsEncrypted(): Attachment
|
||||
{
|
||||
@ -105,7 +143,7 @@ class Attachment implements Model
|
||||
try {
|
||||
$this->getState('decrypted')->setValue(true);
|
||||
} catch (\Exception $e) {
|
||||
$this->newState('encrypted');
|
||||
$this->newState('decrypted');
|
||||
$this->getState('decrypted')->setValue(true);
|
||||
}
|
||||
return $this;
|
||||
@ -115,8 +153,17 @@ class Attachment implements Model
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'message' => $this->getMessage()->toArray(),
|
||||
'message' => [
|
||||
'id' => $this->getMessage()->getId(),
|
||||
'mailbox' => $this->getMessage()->getMailbox()->toArray(),
|
||||
'position' => $this->getMessage()->getPosition(),
|
||||
'uid' => $this->getMessage()->getUID(),
|
||||
'subject' => $this->getMessage()->getSubject(),
|
||||
'from' => $this->getMessage()->getFrom(),
|
||||
'date_time' => $this->getMessage()->getDateTime()->format('Y-m-d H:i:s')
|
||||
],
|
||||
'filename' => $this->getFilename(),
|
||||
'downloaded' => $this->isDownloaded(),
|
||||
'encrypted' => $this->isEncrypted(),
|
||||
'decrypted' => $this->isDecrypted()
|
||||
];
|
||||
|
Reference in New Issue
Block a user