2014-06-29 15:12:33 -05:00
|
|
|
<?php
|
2014-11-30 07:52:17 -06:00
|
|
|
use Carbon\Carbon;
|
2014-11-12 07:38:32 -06:00
|
|
|
use FireflyIII\Shared\SingleTableInheritanceEntity;
|
2014-12-06 05:12:55 -06:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
|
|
|
use Watson\Validating\ValidatingTrait;
|
2014-06-29 15:12:33 -05:00
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* Class Component
|
|
|
|
*/
|
2014-08-23 15:32:12 -05:00
|
|
|
class Component extends SingleTableInheritanceEntity
|
2014-06-29 15:12:33 -05:00
|
|
|
{
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-05 09:19:15 -05:00
|
|
|
public static $rules
|
2014-11-18 02:47:50 -06:00
|
|
|
= [
|
|
|
|
'user_id' => 'exists:users,id|required',
|
|
|
|
'name' => 'required|between:1,100|alphabasic',
|
|
|
|
'class' => 'required',
|
|
|
|
];
|
2014-12-13 14:59:02 -06:00
|
|
|
// @codingStandardsIgnoreStart
|
2014-12-06 05:12:55 -06:00
|
|
|
protected $dates = ['deleted_at', 'created_at', 'updated_at'];
|
2014-11-12 15:37:44 -06:00
|
|
|
protected $fillable = ['name', 'user_id'];
|
|
|
|
protected $subclassField = 'class';
|
|
|
|
protected $table = 'components';
|
2014-12-13 14:59:02 -06:00
|
|
|
// @codingStandardsIgnoreEnd
|
2014-12-06 05:12:55 -06:00
|
|
|
use SoftDeletingTrait, ValidatingTrait;
|
2014-07-05 09:19:15 -05:00
|
|
|
|
2014-08-10 11:22:42 -05:00
|
|
|
/**
|
2014-11-17 13:45:55 -06:00
|
|
|
* TODO remove this method in favour of something in the FireflyIII libraries.
|
2014-11-18 02:47:50 -06:00
|
|
|
*
|
2014-11-17 13:45:55 -06:00
|
|
|
* @return Carbon
|
2014-08-10 11:22:42 -05:00
|
|
|
*/
|
2014-11-17 13:45:55 -06:00
|
|
|
public function lastActionDate()
|
2014-07-20 11:24:27 -05:00
|
|
|
{
|
2014-11-17 13:45:55 -06:00
|
|
|
$transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first();
|
|
|
|
if (is_null($transaction)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transaction->date;
|
2014-07-17 13:52:54 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:22:42 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
*/
|
2014-07-05 12:44:26 -05:00
|
|
|
public function transactionjournals()
|
|
|
|
{
|
2014-11-18 02:47:50 -06:00
|
|
|
return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id');
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|
2014-06-29 15:12:33 -05:00
|
|
|
|
2014-08-10 11:22:42 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
*/
|
2014-08-09 12:10:31 -05:00
|
|
|
public function transactions()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('Transaction');
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:22:42 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2014-06-29 15:12:33 -05:00
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('User');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|