2014-07-05 16:19:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Firefly\Storage\Component;
|
|
|
|
|
|
|
|
class EloquentComponentRepository implements ComponentRepositoryInterface
|
|
|
|
{
|
|
|
|
public $validator;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return \Auth::user()->accounts()->count();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function store($data)
|
|
|
|
{
|
2014-07-05 19:44:26 +02:00
|
|
|
if (!isset($data['class'])) {
|
|
|
|
throw new \Firefly\Exception\FireflyException('No class type present.');
|
|
|
|
}
|
|
|
|
switch ($data['class']) {
|
|
|
|
case 'Budget':
|
|
|
|
$component = new \Budget;
|
|
|
|
break;
|
|
|
|
case 'Category':
|
|
|
|
$component = new \Category;
|
|
|
|
break;
|
|
|
|
|
2014-07-05 16:19:15 +02:00
|
|
|
}
|
|
|
|
$component->name = $data['name'];
|
|
|
|
$component->user()->associate(\Auth::user());
|
|
|
|
try {
|
|
|
|
$component->save();
|
|
|
|
} catch (\Illuminate\Database\QueryException $e) {
|
|
|
|
\Log::error('DB ERROR: ' . $e->getMessage());
|
2014-07-05 19:44:26 +02:00
|
|
|
throw new \Firefly\Exception\FireflyException('Could not save component ' . $data['name'] . ' of type'
|
|
|
|
. $data['class']);
|
2014-07-05 16:19:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $component;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|