Add some forgotten code to the mobile piggy bank controller things.

Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole
2016-08-24 20:06:45 +02:00
parent d4f8c41d80
commit 5aadb29905
8 changed files with 157 additions and 69 deletions

View File

@@ -51,17 +51,32 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereEncrypted($value)
* @mixin \Eloquent
* @property boolean $active
* @property boolean $active
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereActive($value)
*/
class PiggyBank extends Model
{
use SoftDeletes;
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
protected $fillable
= ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate'];
protected $hidden = ['targetamount_encrypted', 'encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
/**
* @param PiggyBank $value
*
* @return PiggyBank
*/
public static function routeBinder(PiggyBank $value)
{
if (Auth::check()) {
if ($value->account->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -76,13 +91,16 @@ class PiggyBank extends Model
*
* @returns PiggyBankRepetition
*/
public function currentRelevantRep()
public function currentRelevantRep(): PiggyBankRepetition
{
if (!is_null($this->currentRep)) {
return $this->currentRep;
}
// repeating piggy banks are no longer supported.
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
if (is_null($rep)) {
return new PiggyBankRepetition();
}
$this->currentRep = $rep;
return $rep;
@@ -90,14 +108,6 @@ class PiggyBank extends Model
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankRepetitions()
{
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
}
/**
*
* @param $value
@@ -122,6 +132,14 @@ class PiggyBank extends Model
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankRepetitions()
{
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
}
/**
*
* @param $value
@@ -139,19 +157,4 @@ class PiggyBank extends Model
{
$this->attributes['targetamount'] = strval(round($value, 2));
}
/**
* @param PiggyBank $value
*
* @return PiggyBank
*/
public static function routeBinder(PiggyBank $value)
{
if (Auth::check()) {
if ($value->account->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}