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