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

68 lines
1.3 KiB
PHP
Raw Normal View History

2015-03-18 00:39:03 +01:00
<?php namespace App\Models;
2015-03-16 22:45:25 +01:00
2015-03-31 20:50:58 +02:00
use HTML;
2015-03-31 11:38:24 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
2015-03-16 22:45:25 +01:00
class Contact extends EntityModel
{
2015-03-31 11:38:24 +02:00
use SoftDeletes;
protected $dates = ['deleted_at'];
2015-10-28 20:22:07 +01:00
protected $fillable = [
'first_name',
'last_name',
'email',
'phone',
'send_invoice',
];
2015-11-24 20:45:38 +01:00
public static $fieldFirstName = 'first_name';
public static $fieldLastName = 'last_name';
public static $fieldEmail = 'email';
public static $fieldPhone = 'phone';
2015-03-16 22:45:25 +01:00
2015-11-07 13:15:37 +01:00
public function account()
{
return $this->belongsTo('App\Models\Account');
}
2015-11-12 21:36:28 +01:00
public function user()
{
return $this->belongsTo('App\Models\User');
}
2015-03-16 22:45:25 +01:00
public function client()
{
2015-11-15 18:23:45 +01:00
return $this->belongsTo('App\Models\Client')->withTrashed();
2015-03-16 22:45:25 +01:00
}
public function getPersonType()
{
return PERSON_CONTACT;
}
2015-07-02 22:21:29 +02:00
public function getName()
{
return $this->getDisplayName();
}
2015-03-16 22:45:25 +01:00
public function getDisplayName()
{
if ($this->getFullName()) {
return $this->getFullName();
} else {
return $this->email;
}
}
public function getFullName()
{
if ($this->first_name || $this->last_name) {
return $this->first_name.' '.$this->last_name;
} else {
return '';
}
}
}