firefly-iii/app/Repositories/Attachment/AttachmentRepository.php

84 lines
1.8 KiB
PHP
Raw Normal View History

2015-07-19 02:37:28 -05:00
<?php
/**
* AttachmentRepository.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2015-07-19 02:37:28 -05:00
namespace FireflyIII\Repositories\Attachment;
2016-05-02 13:49:19 -05:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
2015-07-19 02:37:28 -05:00
use FireflyIII\Models\Attachment;
2016-03-03 01:38:24 -06:00
use FireflyIII\User;
use Illuminate\Support\Collection;
2015-07-19 02:37:28 -05:00
/**
* Class AttachmentRepository
*
* @package FireflyIII\Repositories\Attachment
*/
class AttachmentRepository implements AttachmentRepositoryInterface
{
2016-03-03 01:38:24 -06:00
/** @var User */
private $user;
/**
* AttachmentRepository constructor.
*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
2015-07-19 02:37:28 -05:00
2015-07-26 08:51:07 -05:00
/**
* @param Attachment $attachment
*
* @return bool
*/
2016-02-06 11:59:48 -06:00
public function destroy(Attachment $attachment): bool
2015-07-26 08:51:07 -05:00
{
2016-05-02 13:49:19 -05:00
/** @var AttachmentHelperInterface $helper */
$helper = app(AttachmentHelperInterface::class);
2015-07-26 08:51:07 -05:00
$file = $helper->getAttachmentLocation($attachment);
unlink($file);
$attachment->delete();
2016-02-06 11:59:48 -06:00
return true;
2015-07-26 08:51:07 -05:00
}
/**
* @return Collection
*/
public function get(): Collection
{
2016-03-03 01:38:24 -06:00
return $this->user->attachments()->get();
}
2015-07-19 02:37:28 -05:00
/**
* @param Attachment $attachment
* @param array $data
*
* @return Attachment
*/
2016-02-06 11:59:48 -06:00
public function update(Attachment $attachment, array $data): Attachment
2015-07-19 02:37:28 -05:00
{
$attachment->title = $data['title'];
$attachment->description = $data['description'];
$attachment->notes = $data['notes'];
$attachment->save();
return $attachment;
}
2015-07-19 02:38:44 -05:00
}