1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Models/VendorContact.php

165 lines
3.9 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2022-06-06 14:27:17 +02:00
use App\Models\Presenters\VendorContactPresenter;
2020-10-01 12:49:47 +02:00
use App\Notifications\ClientContactResetPassword;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Translation\HasLocalePreference;
2020-10-01 12:49:47 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2020-10-28 11:10:49 +01:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Cache;
use Laracasts\Presenter\PresentableTrait;
class VendorContact extends Authenticatable implements HasLocalePreference
{
use Notifiable;
use MakesHash;
use PresentableTrait;
use SoftDeletes;
2020-10-01 12:49:47 +02:00
use HasFactory;
/* Used to authenticate a vendor */
protected $guard = 'vendor';
protected $touches = ['vendor'];
2022-06-06 14:27:17 +02:00
protected $presenter = VendorContactPresenter::class;
/* Allow microtime timestamps */
protected $dateFormat = 'Y-m-d H:i:s.u';
2022-06-21 12:03:51 +02:00
protected $appends = [
'hashed_id',
];
2022-09-09 03:07:14 +02:00
protected $with = [];
protected $casts = [
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
];
protected $fillable = [
'first_name',
'last_name',
'phone',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
'email',
'is_primary',
2020-10-31 06:35:05 +01:00
'vendor_id',
2022-11-24 01:38:57 +01:00
'send_email',
];
2022-06-13 11:59:24 +02:00
public function avatar()
{
if ($this->avatar) {
return $this->avatar;
}
return asset('images/svg/user.svg');
}
2022-06-13 11:59:24 +02:00
public function setAvatarAttribute($value)
{
if (! filter_var($value, FILTER_VALIDATE_URL) && $value) {
$this->attributes['avatar'] = url('/').$value;
} else {
$this->attributes['avatar'] = $value;
}
}
public function getEntityType()
{
return self::class;
}
public function getHashedIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
public function getContactIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
public function vendor()
{
return $this->belongsTo(Vendor::class)->withTrashed();
}
public function primary_contact()
{
return $this->where('is_primary', true);
}
public function company()
{
return $this->belongsTo(Company::class);
}
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
}
public function sendPasswordResetNotification($token)
{
2022-06-10 09:04:16 +02:00
// $this->notify(new ClientContactResetPassword($token));
}
public function preferredLocale()
{
$languages = Cache::get('languages');
return $languages->filter(function ($item) {
2022-06-10 09:04:16 +02:00
return $item->id == $this->company->getSetting('language_id');
})->first()->locale;
}
/**
* Retrieve the model for a bound value.
*
2020-10-28 11:10:49 +01:00
* @param mixed $value
* @param null $field
* @return Model|null
*/
2020-11-25 15:19:52 +01:00
public function resolveRouteBinding($value, $field = null)
{
return $this
->withTrashed()
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
public function purchase_order_invitations(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(PurchaseOrderInvitation::class);
}
2022-08-04 08:22:48 +02:00
public function getLoginLink()
{
$domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain();
2022-08-04 08:30:11 +02:00
return $domain.'/vendor/key_login/'.$this->contact_key;
2022-08-04 08:22:48 +02:00
}
}