mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Update rule group repository and provider.
This commit is contained in:
parent
7800b0a7f5
commit
a51d752a35
@ -87,7 +87,6 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\Rule\RuleRepositoryInterface', 'FireflyIII\Repositories\Rule\RuleRepository');
|
||||
$this->app->bind('FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface', 'FireflyIII\Repositories\RuleGroup\RuleGroupRepository');
|
||||
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
||||
|
||||
// CSV import
|
||||
|
50
app/Providers/RuleGroupServiceProvider.php
Normal file
50
app/Providers/RuleGroupServiceProvider.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Providers;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
||||
/**
|
||||
* Class RuleGroupServiceProvider
|
||||
*
|
||||
* @package FireflyIII\Providers
|
||||
*/
|
||||
class RuleGroupServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface',
|
||||
function (Application $app, array $arguments) {
|
||||
if (!isset($arguments[0]) && Auth::check()) {
|
||||
return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', [Auth::user()]);
|
||||
} else {
|
||||
if (!isset($arguments[0]) && !Auth::check()) {
|
||||
throw new FireflyException('There is no user present.');
|
||||
}
|
||||
}
|
||||
|
||||
return app('FireflyIII\Repositories\RuleGroup\RuleGroupRepository', $arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user