331 lines
8.4 KiB
PHP
331 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Http\Traits\ElasticTrait;
|
|
use App\Models\User;
|
|
use DateTimeInterface;
|
|
use Elasticquent\ElasticquentTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Media extends Model
|
|
{
|
|
use ElasticquentTrait;
|
|
use ElasticTrait;
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'medias';
|
|
|
|
/**
|
|
* The relations to eager load on every query.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $with = [
|
|
'owner', 'tags', 'etiquette', 'articles', 'sujet',
|
|
'typemedia', 'societes', 'marques'
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
// ! id est obligatoire ici pour Jobs/XmlArcadiaMediasIn
|
|
'id'
|
|
];
|
|
|
|
/**
|
|
* ES The elasticsearch settings.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $indexSettings = [
|
|
'analysis' => [
|
|
'char_filter' => [
|
|
'replace' => [
|
|
'type' => 'mapping',
|
|
'mappings' => [
|
|
'&=> and '
|
|
],
|
|
],
|
|
],
|
|
'filter' => [
|
|
'word_delimiter' => [
|
|
'type' => 'word_delimiter',
|
|
'split_on_numerics' => false,
|
|
'split_on_case_change' => true,
|
|
'generate_word_parts' => true,
|
|
'generate_number_parts' => true,
|
|
'catenate_all' => true,
|
|
'preserve_original' => true,
|
|
'catenate_numbers' => true,
|
|
]
|
|
],
|
|
'analyzer' => [
|
|
'default' => [
|
|
'type' => 'custom',
|
|
'char_filter' => [
|
|
'html_strip',
|
|
'replace',
|
|
],
|
|
'tokenizer' => 'whitespace',
|
|
'filter' => [
|
|
'lowercase',
|
|
'word_delimiter',
|
|
],
|
|
],
|
|
],
|
|
'normalizer' => [
|
|
'my_normalizer' => [
|
|
'type' => 'custom',
|
|
'char_filter' => [],
|
|
'filter' => [
|
|
'lowercase'
|
|
]
|
|
]
|
|
]
|
|
],
|
|
];
|
|
|
|
/**
|
|
* ES Mapping Properties
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $mappingProperties = array(
|
|
'libelle' => array(
|
|
'type' => 'text',
|
|
'analyzer' => 'default',
|
|
'fields' => [
|
|
'keyword' => [
|
|
'type' => 'keyword',
|
|
'normalizer' => 'my_normalizer'
|
|
]
|
|
],
|
|
'fielddata' => true
|
|
),
|
|
'commentaire' => array(
|
|
'type' => 'text',
|
|
'analyzer' => 'default',
|
|
'fields' => [
|
|
'keyword' => [
|
|
'type' => 'keyword',
|
|
'normalizer' => 'my_normalizer'
|
|
]
|
|
],
|
|
'fielddata' => true
|
|
),
|
|
'created_at' => [
|
|
'type' => 'date',
|
|
"format" => "yyyy-MM-dd HH:mm:ss",
|
|
// 'fielddata' => true
|
|
],
|
|
'updated_at' => [
|
|
'type' => 'date',
|
|
"format" => "yyyy-MM-dd HH:mm:ss",
|
|
// 'fielddata' => true
|
|
],
|
|
'version' => [
|
|
'type' => 'text',
|
|
'fielddata' => true
|
|
],
|
|
'arcadia_id' => [
|
|
'type' => 'text',
|
|
'analyzer' => 'standard'
|
|
],
|
|
'articles.noArt' => [
|
|
'type' => 'text',
|
|
'analyzer' => 'standard'
|
|
],
|
|
'articles.libCcial' => [
|
|
'type' => 'text',
|
|
'analyzer' => 'default',
|
|
'fields' => [
|
|
'keyword' => [
|
|
'type' => 'keyword',
|
|
'normalizer' => 'my_normalizer'
|
|
]
|
|
],
|
|
'fielddata' => true
|
|
]
|
|
);
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* BelongsTo dossier relation
|
|
* Get the dossier that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function dossier()
|
|
{
|
|
return $this->belongsTo(Dossier::class, 'dossier_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo sujet relation
|
|
* Get the sujet that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function sujet()
|
|
{
|
|
return $this->belongsTo(Sujet::class, 'sujet_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo typemedia relation
|
|
* Get the typemedia that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function typemedia()
|
|
{
|
|
return $this->belongsTo(Typemedia::class, 'typemedia_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo typevue relation
|
|
* Get the typevue that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function typevue()
|
|
{
|
|
return $this->belongsTo(Typevue::class, 'typevue_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo langue relation
|
|
* Get the langue that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function langue()
|
|
{
|
|
return $this->belongsTo(Langue::class, 'typevue_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo copyright relation
|
|
* Get the copyright that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function copyright()
|
|
{
|
|
return $this->belongsTo(Copyright::class, 'copyright_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo etiquette relation
|
|
* Get the etiquette that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function etiquette()
|
|
{
|
|
return $this->belongsTo(Etiquette::class, 'etiquette_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany tags relation
|
|
* The tags that belong to the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function tags()
|
|
{
|
|
return $this->belongsToMany(Tag::class, 'medias_tags', 'media_id', 'tag_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany articles relation
|
|
* The articles that belong to the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function articles()
|
|
{
|
|
return $this->belongsToMany(Article::class, 'medias_articles', 'media_id', 'article_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany societes relation
|
|
* The societes that belong to the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function societes()
|
|
{
|
|
return $this->belongsToMany(Societe::class, 'medias_societes', 'media_id', 'societe_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany marques relation
|
|
* The marques that belong to the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function marques()
|
|
{
|
|
return $this->belongsToMany(Marque::class, 'medias_marques', 'media_id', 'marque_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo user relation
|
|
* Get the user that owns the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function owner()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* HasMany historiques relation
|
|
* Get the historiques for the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function historiques()
|
|
{
|
|
return $this->hasMany(Historique::class);
|
|
}
|
|
|
|
/**
|
|
* BelongsToMany paniers relation
|
|
* The paniers that belong to the media.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function paniers()
|
|
{
|
|
return $this->belongsToMany(Panier::class, 'paniers_medias', 'media_id', 'panier_id');
|
|
}
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Convert the model instance to an array.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function toArray()
|
|
{
|
|
return array_merge(parent::toArray(), [
|
|
'created_at' => $this->created_at->formatLocalized('%Y-%m-%d %H:%M:%S'),
|
|
'updated_at' => $this->updated_at->formatLocalized('%Y-%m-%d %H:%M:%S')
|
|
]);
|
|
}
|
|
}
|