mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-21 00:50:07 +00:00
Fixed some bugs in various controllers and started rebuilding the category controller.
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Collection;
|
||||
use FireflyIII\Database\Ifaces\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\Ifaces\CUD;
|
||||
use FireflyIII\Database\Ifaces\BudgetInterface;
|
||||
|
||||
/**
|
||||
* Class Budget
|
||||
*
|
||||
@@ -80,11 +81,11 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
$successes = new MessageBag;
|
||||
$errors = new MessageBag;
|
||||
|
||||
if(isset($model['name'])) {
|
||||
if(strlen($model['name']) < 1) {
|
||||
if (isset($model['name'])) {
|
||||
if (strlen($model['name']) < 1) {
|
||||
$errors->add('name', 'Name is too short');
|
||||
}
|
||||
if(strlen($model['name']) > 200) {
|
||||
if (strlen($model['name']) > 200) {
|
||||
$errors->add('name', 'Name is too long');
|
||||
|
||||
}
|
||||
@@ -98,8 +99,8 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
}
|
||||
|
||||
|
||||
if(!$errors->has('name')) {
|
||||
$successes->add('name','OK');
|
||||
if (!$errors->has('name')) {
|
||||
$successes->add('name', 'OK');
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -118,7 +119,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
{
|
||||
$data['user_id'] = $this->getUser()->id;
|
||||
|
||||
$budget = new \Budget($data);
|
||||
$budget = new \Budget($data);
|
||||
$budget->class = 'Budget';
|
||||
|
||||
if (!$budget->validate()) {
|
||||
@@ -155,10 +156,12 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $date
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function spentInMonth(\Budget $budget, Carbon $date) {
|
||||
public function spentInMonth(\Budget $budget, Carbon $date)
|
||||
{
|
||||
$end = clone $date;
|
||||
$date->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
@@ -220,7 +223,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
*/
|
||||
public function update(Ardent $model, array $data)
|
||||
{
|
||||
$model->name = $data['name'];
|
||||
$model->name = $data['name'];
|
||||
if (!$model->validate()) {
|
||||
var_dump($model->errors()->all());
|
||||
exit;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace FireflyIII\Database;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -33,7 +34,8 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
*/
|
||||
public function destroy(Ardent $model)
|
||||
{
|
||||
// TODO: Implement destroy() method.
|
||||
$model->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,37 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
*/
|
||||
public function validate(array $model)
|
||||
{
|
||||
// TODO: Implement validate() method.
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
$errors = new MessageBag;
|
||||
|
||||
if (isset($model['name'])) {
|
||||
if (strlen($model['name']) < 1) {
|
||||
$errors->add('name', 'Name is too short');
|
||||
}
|
||||
if (strlen($model['name']) > 200) {
|
||||
$errors->add('name', 'Name is too long');
|
||||
|
||||
}
|
||||
} else {
|
||||
$errors->add('name', 'Name is mandatory');
|
||||
}
|
||||
$validator = \Validator::make($model, \Component::$rules);
|
||||
|
||||
if ($validator->invalid()) {
|
||||
$errors->merge($validator->errors());
|
||||
}
|
||||
|
||||
|
||||
if (!$errors->has('name')) {
|
||||
$successes->add('name', 'OK');
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $errors,
|
||||
'warnings' => $warnings,
|
||||
'successes' => $successes
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +123,7 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
// TODO: Implement get() method.
|
||||
return $this->getUser()->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,6 +156,15 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
*/
|
||||
public function update(Ardent $model, array $data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
$model->name = $data['name'];
|
||||
if (!$model->validate()) {
|
||||
var_dump($model->errors()->all());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$model->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user