ldc-dam/app/Models/Media.php
Jérémy Munsch 3adefc6fdc
Ticket 754: Rewrite Arcadia Xml in job:
- composer require kwaadpepper/enum
- add MAIL_LIST_SERVICEWEB var to .env
- add XmlJobs, XArcadiaFlux
- ArcadiaLink is now a Job instead of a simple comand
- Add real progressbar to XArcadiaFlux
- Add XmlArcadiaMediasIn to Kernel to execute twice daily on one server
- Add Lib\Utils class with sendEmailErrorManually until laravel bump is done
- Changed XmlJobs can now handle xml files which have only one entity within
- Add guessed XSD
- Changed XmlJobs can now validate xml with xsd before parse
- Changed XmlJobs Report Query Exceptions on save
- Added XmlJobs Add save callback to handle save
- Extensive tests
2022-03-25 13:59:30 +01:00

315 lines
8 KiB
PHP

<?php
namespace App\Models;
use App\Http\Traits\ElasticTrait;
use App\User;
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');
}
}