2016-01-09 08:47:03 -06:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-09 08:47:03 -06:00
|
|
|
/**
|
|
|
|
* BudgetList.php
|
2016-04-01 09:44:46 -05:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-01-09 08:47:03 -06:00
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace FireflyIII\Support\Binder;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use FireflyIII\Models\Budget;
|
2016-02-06 03:11:06 -06:00
|
|
|
use Illuminate\Support\Collection;
|
2016-01-09 08:47:03 -06:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BudgetList
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Support\Binder
|
|
|
|
*/
|
|
|
|
class BudgetList implements BinderInterface
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
* @param $route
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public static function routeBinder($value, $route): Collection
|
2016-01-09 08:47:03 -06:00
|
|
|
{
|
|
|
|
if (Auth::check()) {
|
|
|
|
$ids = explode(',', $value);
|
|
|
|
/** @var \Illuminate\Support\Collection $object */
|
|
|
|
$object = Budget::where('active', 1)
|
|
|
|
->whereIn('id', $ids)
|
|
|
|
->where('user_id', Auth::user()->id)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
// add empty budget if applicable.
|
|
|
|
if (in_array('0', $ids)) {
|
|
|
|
$object->push(new Budget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($object->count() > 0) {
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundHttpException;
|
|
|
|
}
|
2016-01-28 14:50:20 -06:00
|
|
|
}
|