2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-03-31 11:38:24 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2017-04-30 21:18:17 +02:00
|
|
|
use App\Models\LookupInvitation;
|
2018-02-07 17:20:53 +01:00
|
|
|
use App\Models\Traits\Inviteable;
|
2018-03-09 10:58:25 +01:00
|
|
|
use Utils;
|
2015-03-31 11:38:24 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class Invitation.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
class Invitation extends EntityModel
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
use SoftDeletes;
|
2018-02-07 17:20:53 +01:00
|
|
|
use Inviteable;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-03-31 11:38:24 +02:00
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
2016-08-08 22:47:09 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return ENTITY_INVITATION;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function invoice()
|
|
|
|
{
|
2015-04-16 21:57:12 +02:00
|
|
|
return $this->belongsTo('App\Models\Invoice')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function contact()
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
return $this->belongsTo('App\Models\Contact')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2015-03-23 07:52:01 +01:00
|
|
|
return $this->belongsTo('App\Models\User')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function account()
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
return $this->belongsTo('App\Models\Account');
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2018-02-08 08:39:19 +01:00
|
|
|
|
|
|
|
public function signatureDiv()
|
|
|
|
{
|
|
|
|
if (! $this->signature_base64) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf('<img src="data:image/svg+xml;base64,%s"></img><p/>%s: %s', $this->signature_base64, trans('texts.signed'), Utils::fromSqlDateTime($this->signature_date));
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2017-04-30 21:18:17 +02:00
|
|
|
|
|
|
|
Invitation::creating(function ($invitation)
|
|
|
|
{
|
|
|
|
LookupInvitation::createNew($invitation->account->account_key, [
|
|
|
|
'invitation_key' => $invitation->invitation_key,
|
|
|
|
]);
|
|
|
|
});
|
2017-05-01 11:29:45 +02:00
|
|
|
|
2017-06-18 13:42:55 +02:00
|
|
|
Invitation::updating(function ($invitation) {
|
|
|
|
$dirty = $invitation->getDirty();
|
|
|
|
if (array_key_exists('message_id', $dirty)) {
|
|
|
|
LookupInvitation::updateInvitation($invitation->account->account_key, $invitation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-05-01 11:29:45 +02:00
|
|
|
Invitation::deleted(function ($invitation)
|
|
|
|
{
|
2017-05-10 12:02:20 +02:00
|
|
|
if ($invitation->forceDeleting) {
|
|
|
|
LookupInvitation::deleteWhere([
|
|
|
|
'invitation_key' => $invitation->invitation_key,
|
|
|
|
]);
|
|
|
|
}
|
2017-05-01 11:29:45 +02:00
|
|
|
});
|