1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Models/Invitation.php

95 lines
2.0 KiB
PHP
Raw Normal View History

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:09 +01:00
use Utils;
2015-03-31 11:38:24 +02:00
/**
2017-01-30 20:40:43 +01:00
* Class Invitation.
*/
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;
/**
* @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;
}
/**
* @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
}
/**
* @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
}
/**
* @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
}
/**
* @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
});