mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Reimplemented a routine that creates reminders. Cannot act on them yet.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user