Expand binder test.

This commit is contained in:
James Cole
2017-12-25 15:30:50 +01:00
parent 58eaf3bccc
commit 01818af963
6 changed files with 411 additions and 40 deletions

View File

@@ -41,20 +41,29 @@ class BudgetList implements BinderInterface
public static function routeBinder(string $value, Route $route): Collection
{
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);
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = intval($entry);
}
$list = array_unique($list);
if (count($list) === 0) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}
if ($object->count() > 0) {
return $object;
/** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->budgets()
->where('active', 1)
->whereIn('id', $list)
->get();
// add empty budget if applicable.
if (in_array(0, $list)) {
$collection->push(new Budget);
}
if ($collection->count() > 0) {
return $collection;
}
}
throw new NotFoundHttpException;

View File

@@ -41,19 +41,28 @@ class CategoryList implements BinderInterface
public static function routeBinder(string $value, Route $route): Collection
{
if (auth()->check()) {
$ids = explode(',', $value);
/** @var \Illuminate\Support\Collection $object */
$object = Category::whereIn('id', $ids)
->where('user_id', auth()->user()->id)
->get();
// add empty category if applicable.
if (in_array('0', $ids)) {
$object->push(new Category);
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = intval($entry);
}
$list = array_unique($list);
if (count($list) === 0) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}
if ($object->count() > 0) {
return $object;
/** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->categories()
->whereIn('id', $list)
->get();
// add empty category if applicable.
if (in_array(0, $list)) {
$collection->push(new Category);
}
if ($collection->count() > 0) {
return $collection;
}
}
throw new NotFoundHttpException;

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Binder;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\FiscalHelper;
use FireflyIII\Helpers\FiscalHelperInterface;
use Illuminate\Routing\Route;
use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -42,7 +43,8 @@ class Date implements BinderInterface
*/
public static function routeBinder(string $value, Route $route): Carbon
{
$fiscalHelper = new FiscalHelper;
/** @var FiscalHelperInterface $fiscalHelper */
$fiscalHelper = app(FiscalHelperInterface::class);
switch ($value) {
default:

View File

@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -41,14 +40,24 @@ class JournalList implements BinderInterface
public static function routeBinder(string $value, Route $route): Collection
{
if (auth()->check()) {
$ids = explode(',', $value);
/** @var \Illuminate\Support\Collection $object */
$object = TransactionJournal::whereIn('transaction_journals.id', $ids)
->where('transaction_journals.user_id', auth()->user()->id)
->get(['transaction_journals.*']);
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = intval($entry);
}
$list = array_unique($list);
if (count($list) === 0) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}
if ($object->count() > 0) {
return $object;
/** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->transactionJournals()
->whereIn('transaction_journals.id', $list)
->where('transaction_journals.completed', 1)
->get(['transaction_journals.*']);
if ($collection->count() > 0) {
return $collection;
}
}
throw new NotFoundHttpException;

View File

@@ -42,18 +42,27 @@ class TagList implements BinderInterface
public static function routeBinder(string $value, Route $route): Collection
{
if (auth()->check()) {
$tags = explode(',', $value);
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = trim($entry);
}
$list = array_unique($list);
if (count($list) === 0) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$allTags = $repository->get();
$set = $allTags->filter(
function (Tag $tag) use ($tags) {
return in_array($tag->tag, $tags);
$collection = $allTags->filter(
function (Tag $tag) use ($list) {
return in_array($tag->tag, $list);
}
);
if ($set->count() > 0) {
return $set;
if ($collection->count() > 0) {
return $collection;
}
}
throw new NotFoundHttpException;