2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
2015-03-17 07:45:25 +10:00
|
|
|
|
2015-03-31 12:38:24 +03:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2017-04-30 22:18:17 +03:00
|
|
|
use App\Models\LookupInvitation;
|
2018-02-07 18:20:53 +02:00
|
|
|
use App\Models\Traits\Inviteable;
|
2018-03-09 11:58:25 +02:00
|
|
|
use Utils;
|
2015-03-31 12:38:24 +03:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 21:40:43 +02:00
|
|
|
* Class Invitation.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
class Invitation extends EntityModel
|
|
|
|
|
{
|
2015-03-31 12:38:24 +03:00
|
|
|
use SoftDeletes;
|
2018-02-07 18:20:53 +02:00
|
|
|
use Inviteable;
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2015-03-31 12:38:24 +03:00
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
|
2016-08-08 23:47:09 +03:00
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getEntityType()
|
|
|
|
|
{
|
|
|
|
|
return ENTITY_INVITATION;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
public function invoice()
|
|
|
|
|
{
|
2015-04-16 22:57:12 +03:00
|
|
|
return $this->belongsTo('App\Models\Invoice')->withTrashed();
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
public function contact()
|
|
|
|
|
{
|
2015-03-31 12:38:24 +03:00
|
|
|
return $this->belongsTo('App\Models\Contact')->withTrashed();
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
public function user()
|
|
|
|
|
{
|
2015-03-23 16:52:01 +10:00
|
|
|
return $this->belongsTo('App\Models\User')->withTrashed();
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
public function account()
|
|
|
|
|
{
|
2015-03-31 12:38:24 +03:00
|
|
|
return $this->belongsTo('App\Models\Account');
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
2018-02-08 09:39:19 +02: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-17 07:45:25 +10:00
|
|
|
}
|
2017-04-30 22:18:17 +03:00
|
|
|
|
|
|
|
|
Invitation::creating(function ($invitation)
|
|
|
|
|
{
|
|
|
|
|
LookupInvitation::createNew($invitation->account->account_key, [
|
|
|
|
|
'invitation_key' => $invitation->invitation_key,
|
|
|
|
|
]);
|
|
|
|
|
});
|
2017-05-01 12:29:45 +03:00
|
|
|
|
2017-06-18 14:42:55 +03: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 12:29:45 +03:00
|
|
|
Invitation::deleted(function ($invitation)
|
|
|
|
|
{
|
2017-05-10 13:02:20 +03:00
|
|
|
if ($invitation->forceDeleting) {
|
|
|
|
|
LookupInvitation::deleteWhere([
|
|
|
|
|
'invitation_key' => $invitation->invitation_key,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2017-05-01 12:29:45 +03:00
|
|
|
});
|