1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Models/VendorContact.php

113 lines
2.0 KiB
PHP
Raw Normal View History

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