mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
chore: code cleanup.
This commit is contained in:
@@ -31,6 +31,16 @@ use FireflyIII\Models\ObjectGroup;
|
||||
*/
|
||||
trait CreatesObjectGroups
|
||||
{
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return null|ObjectGroup
|
||||
*/
|
||||
protected function findObjectGroup(string $title): ?ObjectGroup
|
||||
{
|
||||
return $this->user->objectGroups()->where('title', $title)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $groupId
|
||||
*
|
||||
@@ -80,14 +90,4 @@ trait CreatesObjectGroups
|
||||
{
|
||||
return 1 === $this->user->objectGroups()->where('title', $title)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return null|ObjectGroup
|
||||
*/
|
||||
protected function findObjectGroup(string $title): ?ObjectGroup
|
||||
{
|
||||
return $this->user->objectGroups()->where('title', $title)->first();
|
||||
}
|
||||
}
|
||||
|
@@ -53,17 +53,6 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->objectGroups()
|
||||
->with(['piggyBanks', 'bills'])
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -93,6 +82,17 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
$objectGroup->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->objectGroups()
|
||||
->with(['piggyBanks', 'bills'])
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -151,34 +151,6 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
return $dbQuery->take($limit)->get(['object_groups.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update(ObjectGroup $objectGroup, array $data): ObjectGroup
|
||||
{
|
||||
if (array_key_exists('title', $data)) {
|
||||
$objectGroup->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($objectGroup, (int)$data['order']);
|
||||
}
|
||||
|
||||
$objectGroup->save();
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -207,4 +179,32 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update(ObjectGroup $objectGroup, array $data): ObjectGroup
|
||||
{
|
||||
if (array_key_exists('title', $data)) {
|
||||
$objectGroup->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($objectGroup, (int)$data['order']);
|
||||
}
|
||||
|
||||
$objectGroup->save();
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user