Code clean up and reformat.

This commit is contained in:
James Cole
2014-11-12 22:37:09 +01:00
parent 258d6a1688
commit 4aa9a04516
33 changed files with 1543 additions and 1611 deletions

View File

@@ -35,9 +35,40 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
public function destroy(Ardent $model)
{
$model->delete();
return true;
}
/**
* @param array $data
*
* @return Ardent
*/
public function store(array $data)
{
// TODO: Implement store() method.
throw new NotImplementedException;
}
/**
* @param Ardent $model
* @param array $data
*
* @return bool
*/
public function update(Ardent $model, array $data)
{
$model->name = $data['name'];
if (!$model->validate()) {
var_dump($model->errors()->all());
exit;
}
$model->save();
return true;
}
/**
* Validates an array. Returns an array containing MessageBags
@@ -49,9 +80,9 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
*/
public function validate(array $model)
{
$warnings = new MessageBag;
$warnings = new MessageBag;
$successes = new MessageBag;
$errors = new MessageBag;
$errors = new MessageBag;
if (isset($model['name'])) {
if (strlen($model['name']) < 1) {
@@ -75,68 +106,7 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
$successes->add('name', 'OK');
}
return [
'errors' => $errors,
'warnings' => $warnings,
'successes' => $successes
];
}
/**
* Returns all objects.
*
* @return Collection
*/
public function get()
{
return $this->getUser()->categories()->orderBy('name', 'ASC')->get();
}
/**
* @param \Category $budget
* @param Carbon $date
*
* @return null
*/
public function repetitionOnStartingOnDate(\Category $category, Carbon $date)
{
return null;
}
/**
* @param \Category $category
* @param Carbon $date
*
* @return float
*/
public function spentInMonth(\Category $category, Carbon $date)
{
$end = clone $date;
$date->startOfMonth();
$end->endOfMonth();
$sum = floatval($category->transactionjournals()->before($end)->after($date)->lessThan(0)->sum('amount')) * -1;
return $sum;
}
/**
* @param Ardent $model
* @param array $data
*
* @return bool
*/
public function update(Ardent $model, array $data)
{
$model->name = $data['name'];
if (!$model->validate()) {
var_dump($model->errors()->all());
exit;
}
$model->save();
return true;
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
}
/**
@@ -153,17 +123,6 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
throw new NotImplementedException;
}
/**
* @param array $data
*
* @return Ardent
*/
public function store(array $data)
{
// TODO: Implement store() method.
throw new NotImplementedException;
}
/**
* Returns an object with id $id.
*
@@ -177,17 +136,6 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
throw new NotImplementedException;
}
/**
* @param array $ids
*
* @return Collection
*/
public function getByIds(array $ids)
{
// TODO: Implement getByIds() method.
throw new NotImplementedException;
}
/**
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
@@ -200,4 +148,52 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
// TODO: Implement findByWhat() method.
throw new NotImplementedException;
}
/**
* Returns all objects.
*
* @return Collection
*/
public function get()
{
return $this->getUser()->categories()->orderBy('name', 'ASC')->get();
}
/**
* @param array $ids
*
* @return Collection
*/
public function getByIds(array $ids)
{
// TODO: Implement getByIds() method.
throw new NotImplementedException;
}
/**
* @param \Category $budget
* @param Carbon $date
*
* @return null
*/
public function repetitionOnStartingOnDate(\Category $category, Carbon $date)
{
return null;
}
/**
* @param \Category $category
* @param Carbon $date
*
* @return float
*/
public function spentInMonth(\Category $category, Carbon $date)
{
$end = clone $date;
$date->startOfMonth();
$end->endOfMonth();
$sum = floatval($category->transactionjournals()->before($end)->after($date)->lessThan(0)->sum('amount')) * -1;
return $sum;
}
}