Reimplemented a routine that creates reminders. Cannot act on them yet.

This commit is contained in:
James Cole
2015-03-06 15:12:07 +01:00
parent f9c518f321
commit fc91a50979
13 changed files with 368 additions and 66 deletions

View File

@@ -3,8 +3,10 @@
namespace FireflyIII\Validation;
use Auth;
use Carbon\Carbon;
use DB;
use Illuminate\Validation\Validator;
use Navigation;
/**
* Class FireflyValidator
@@ -32,6 +34,31 @@ class FireflyValidator extends Validator
}
public function validatePiggyBankReminder($attribute, $value, $parameters)
{
$array = $this->data;
// no reminder? dont care.
if (!isset($array['remind_me'])) {
return true;
}
// get or set start date & target date:
$startDate = isset($array['startdate']) ? new Carbon($array['startdate']) : new Carbon;
$targetDate = isset($array['targetdate']) && strlen($array['targetdate']) > 0 ? new Carbon($array['targetdate']) : null;
// target date is null? reminder period is always good.
if ($array['remind_me'] == '1' && is_null($targetDate)) {
return true;
}
$nextReminder = Navigation::addPeriod($startDate, $array['reminder'],0);
// reminder is beyond target?
if($nextReminder > $targetDate) {
return false;
}
return true;
}
/**
* @param $attribute
* @param $value
@@ -41,7 +68,11 @@ class FireflyValidator extends Validator
*/
public function validateUniqueForUser($attribute, $value, $parameters)
{
$count = DB::table($parameters[0])->where($parameters[1], $value)->where('id', '!=', $parameters[2])->count();
$query = DB::table($parameters[0])->where($parameters[1], $value);
if (isset($paramers[2])) {
$query->where('id', '!=', $parameters[2]);
}
$count = $query->count();
if ($count == 0) {
return true;
}