2021-05-08 06:50:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2021-07-19 15:24:17 +02:00
|
|
|
use App\Enums\Role;
|
2021-05-08 06:50:19 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-07-15 02:05:00 +02:00
|
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
2021-05-08 06:50:19 +02:00
|
|
|
|
|
|
|
|
class Site extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
use IsCrudModel;
|
|
|
|
|
|
|
|
|
|
protected $crudLabelColumn = 'name';
|
|
|
|
|
|
|
|
|
|
protected $crudValueColumn = 'id';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'url',
|
|
|
|
|
'name',
|
|
|
|
|
'email_contact',
|
|
|
|
|
'address',
|
|
|
|
|
'city',
|
|
|
|
|
'postcode',
|
|
|
|
|
'latitude',
|
2021-06-28 10:17:27 +02:00
|
|
|
'longitude',
|
|
|
|
|
'societe_id'
|
2021-05-08 06:50:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function __construct($attributes = [])
|
|
|
|
|
{
|
|
|
|
|
self::$editableProperties = [
|
|
|
|
|
'url' => [
|
|
|
|
|
'label' => trans('Url'),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'url',
|
|
|
|
|
'max:255'
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update()
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'name' => [
|
|
|
|
|
'label' => trans('Nom'),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'string',
|
|
|
|
|
'max:255'
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'email_contact' => [
|
|
|
|
|
'label' => trans('Email de contact'),
|
|
|
|
|
'type' => CrudType::email(),
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'validate' => [
|
|
|
|
|
'max:255'
|
|
|
|
|
],
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'address' => [
|
|
|
|
|
'label' => trans('Adresse'),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'string',
|
|
|
|
|
'max:255'
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'city' => [
|
|
|
|
|
'label' => trans('Ville'),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'string',
|
|
|
|
|
'max:70'
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'postcode' => [
|
|
|
|
|
'label' => trans('Code postal'),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'string',
|
|
|
|
|
'max:10'
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'latitude' => [
|
|
|
|
|
'label' => trans('Latitude'),
|
|
|
|
|
'type' => CrudType::float(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'numeric',
|
|
|
|
|
'between:-89.99,90'
|
|
|
|
|
],
|
|
|
|
|
'rules' => [
|
|
|
|
|
'min' => -89.99,
|
|
|
|
|
'max' => 90,
|
|
|
|
|
'step' => 0.01
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
'nullable' => false,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'longitude' => [
|
|
|
|
|
'label' => trans('Longitude'),
|
|
|
|
|
'type' => CrudType::float(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'numeric',
|
|
|
|
|
'between:-179.99,180.00',
|
|
|
|
|
],
|
|
|
|
|
'rules' => [
|
|
|
|
|
'min' => -179.99,
|
|
|
|
|
'max' => 180,
|
|
|
|
|
'step' => 0.01
|
|
|
|
|
],
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'societe_id' => [
|
|
|
|
|
'label' => trans('Societe'),
|
|
|
|
|
'type' => CrudType::belongsTo(),
|
2021-06-29 16:00:58 +02:00
|
|
|
'belongsTo' => Societe::class,
|
2021-05-08 06:50:19 +02:00
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
2021-07-19 15:24:17 +02:00
|
|
|
CrudAction::view()
|
2021-05-08 06:50:19 +02:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
2021-07-22 14:05:29 +02:00
|
|
|
if (auth('web')->user() and auth('web')->user()->role->equals(Role::admin())) {
|
2021-07-19 15:24:17 +02:00
|
|
|
self::$editableProperties['societe_id']['actions'][] = CrudAction::create();
|
|
|
|
|
self::$editableProperties['societe_id']['actions'][] = CrudAction::update();
|
|
|
|
|
}
|
2021-05-08 06:50:19 +02:00
|
|
|
parent::__construct($attributes);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 12:41:38 +02:00
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::deleted(function (self $model) {
|
|
|
|
|
User::whereSelectedSiteId($model->id)->get()
|
|
|
|
|
->map(function (User $user) {
|
|
|
|
|
$user->selected_site_id = null;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-08 06:50:19 +02:00
|
|
|
/**
|
|
|
|
|
* Has one Societe
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function societe()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Societe::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has many Employee
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
|
|
|
|
public function employees()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Employee::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Belongs To Many Sites
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany
|
|
|
|
|
*/
|
|
|
|
|
public function users()
|
|
|
|
|
{
|
2022-06-17 10:36:32 +02:00
|
|
|
return $this->belongsToMany(User::class, 'user_site');
|
2021-05-08 06:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has many Flash
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
|
|
|
|
public function flashes()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Flash::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has many Sondage
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
|
|
|
|
public function sondages()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Sondage::class);
|
|
|
|
|
}
|
|
|
|
|
}
|