mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Update rule group repository and provider.
This commit is contained in:
@@ -10,7 +10,7 @@ use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use Log;
|
||||
/**
|
||||
* Class RuleGroupRepository
|
||||
*
|
||||
@@ -18,12 +18,26 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* BillRepository constructor.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
Log::debug('Constructed piggy bank repository for user #' . $user->id . ' (' . $user->email . ')');
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return Auth::user()->ruleGroups()->count();
|
||||
return $this->user->ruleGroups()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +76,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return Auth::user()->ruleGroups()->orderBy('order', 'ASC')->get();
|
||||
return $this->user->ruleGroups()->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +84,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function getHighestOrderRuleGroup()
|
||||
{
|
||||
$entry = Auth::user()->ruleGroups()->max('order');
|
||||
$entry = $this->user->ruleGroups()->max('order');
|
||||
|
||||
return intval($entry);
|
||||
}
|
||||
@@ -112,7 +126,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
$order = $ruleGroup->order;
|
||||
|
||||
// find the rule with order+1 and give it order-1
|
||||
$other = Auth::user()->ruleGroups()->where('order', ($order + 1))->first();
|
||||
$other = $this->user->ruleGroups()->where('order', ($order + 1))->first();
|
||||
if ($other) {
|
||||
$other->order = ($other->order - 1);
|
||||
$other->save();
|
||||
@@ -133,7 +147,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
$order = $ruleGroup->order;
|
||||
|
||||
// find the rule with order-1 and give it order+1
|
||||
$other = Auth::user()->ruleGroups()->where('order', ($order - 1))->first();
|
||||
$other = $this->user->ruleGroups()->where('order', ($order - 1))->first();
|
||||
if ($other) {
|
||||
$other->order = ($other->order + 1);
|
||||
$other->save();
|
||||
@@ -149,9 +163,9 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function resetRuleGroupOrder()
|
||||
{
|
||||
Auth::user()->ruleGroups()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||
$this->user->ruleGroups()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||
|
||||
$set = Auth::user()->ruleGroups()->where('active', 1)->orderBy('order', 'ASC')->get();
|
||||
$set = $this->user->ruleGroups()->where('active', 1)->orderBy('order', 'ASC')->get();
|
||||
$count = 1;
|
||||
/** @var RuleGroup $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
Reference in New Issue
Block a user