1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Models/VendorContact.php
2017-01-30 21:40:43 +02:00

116 lines
2.0 KiB
PHP

<?php
namespace App\Models;
// vendor
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class VendorContact.
*/
class VendorContact extends EntityModel
{
use SoftDeletes;
/**
* @var array
*/
protected $dates = ['deleted_at'];
/**
* @var string
*/
protected $table = 'vendor_contacts';
/**
* @var array
*/
protected $fillable = [
'first_name',
'last_name',
'email',
'phone',
'send_invoice',
];
/**
* @var string
*/
public static $fieldFirstName = 'first_name';
/**
* @var string
*/
public static $fieldLastName = 'last_name';
/**
* @var string
*/
public static $fieldEmail = 'email';
/**
* @var string
*/
public static $fieldPhone = 'phone';
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Models\Account');
}
/**
* @return mixed
*/
public function user()
{
return $this->belongsTo('App\Models\User')->withTrashed();
}
/**
* @return mixed
*/
public function vendor()
{
return $this->belongsTo('App\Models\Vendor')->withTrashed();
}
/**
* @return mixed
*/
public function getPersonType()
{
return PERSON_VENDOR_CONTACT;
}
/**
* @return mixed|string
*/
public function getName()
{
return $this->getDisplayName();
}
/**
* @return mixed|string
*/
public function getDisplayName()
{
if ($this->getFullName()) {
return $this->getFullName();
} else {
return $this->email;
}
}
/**
* @return string
*/
public function getFullName()
{
if ($this->first_name || $this->last_name) {
return $this->first_name.' '.$this->last_name;
} else {
return '';
}
}
}