1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Models/ProposalInvitation.php

86 lines
1.7 KiB
PHP
Raw Normal View History

2018-02-07 17:20:53 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
2018-02-11 12:09:29 +01:00
use App\Models\LookupProposalInvitation;
2018-02-07 17:20:53 +01:00
use App\Models\Traits\Inviteable;
/**
* Class Invitation.
*/
class ProposalInvitation extends EntityModel
{
use SoftDeletes;
use Inviteable;
/**
* @var array
*/
protected $dates = ['deleted_at'];
/**
* @return mixed
*/
public function getEntityType()
{
return ENTITY_PROPOSAL_INVITATION;
}
/**
* @return mixed
*/
public function proposal()
{
return $this->belongsTo('App\Models\Proposal')->withTrashed();
}
/**
* @return mixed
*/
public function contact()
{
return $this->belongsTo('App\Models\Contact')->withTrashed();
}
/**
* @return mixed
*/
public function user()
{
return $this->belongsTo('App\Models\User')->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Models\Account');
}
}
ProposalInvitation::creating(function ($invitation)
{
LookupProposalInvitation::createNew($invitation->account->account_key, [
'invitation_key' => $invitation->invitation_key,
]);
});
2018-02-11 12:09:29 +01:00
ProposalInvitation::updating(function ($invitation)
{
2018-02-07 17:20:53 +01:00
$dirty = $invitation->getDirty();
if (array_key_exists('message_id', $dirty)) {
LookupProposalInvitation::updateInvitation($invitation->account->account_key, $invitation);
}
});
ProposalInvitation::deleted(function ($invitation)
{
if ($invitation->forceDeleting) {
LookupProposalInvitation::deleteWhere([
'invitation_key' => $invitation->invitation_key,
]);
}
});