mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 10:51:12 -06:00
74 lines
1.5 KiB
PHP
74 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types = 1);
|
|
|
|
namespace FireflyIII\Repositories\Attachment;
|
|
|
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
|
use FireflyIII\Models\Attachment;
|
|
use FireflyIII\User;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Class AttachmentRepository
|
|
*
|
|
* @package FireflyIII\Repositories\Attachment
|
|
*/
|
|
class AttachmentRepository implements AttachmentRepositoryInterface
|
|
{
|
|
/** @var User */
|
|
private $user;
|
|
|
|
/**
|
|
* AttachmentRepository constructor.
|
|
*
|
|
* @param User $user
|
|
*/
|
|
public function __construct(User $user)
|
|
{
|
|
$this->user = $user;
|
|
}
|
|
|
|
/**
|
|
* @param Attachment $attachment
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function destroy(Attachment $attachment): bool
|
|
{
|
|
/** @var AttachmentHelperInterface $helper */
|
|
$helper = app(AttachmentHelperInterface::class);
|
|
|
|
$file = $helper->getAttachmentLocation($attachment);
|
|
unlink($file);
|
|
$attachment->delete();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return Collection
|
|
*/
|
|
public function get(): Collection
|
|
{
|
|
return $this->user->attachments()->get();
|
|
}
|
|
|
|
/**
|
|
* @param Attachment $attachment
|
|
* @param array $data
|
|
*
|
|
* @return Attachment
|
|
*/
|
|
public function update(Attachment $attachment, array $data): Attachment
|
|
{
|
|
|
|
$attachment->title = $data['title'];
|
|
$attachment->description = $data['description'];
|
|
$attachment->notes = $data['notes'];
|
|
$attachment->save();
|
|
|
|
return $attachment;
|
|
|
|
}
|
|
}
|