2015-02-20 15:00:09 +01:00
|
|
|
<?php namespace App\Models;
|
2015-02-18 23:15:18 +01:00
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Oeuvre extends Model {
|
|
|
|
|
|
|
|
protected $table = 'oeuvre';
|
|
|
|
|
|
|
|
public $timestamps = false;
|
2015-02-22 16:42:45 +01:00
|
|
|
|
|
|
|
public function designations()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('App\Models\Designation', 'assodesignationaoeuvre');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function auteurs()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('App\Models\Auteur', 'assoauteuraoeuvre');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function technique()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Technique', 'idtechnique', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function domaine()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Domaine', 'iddomaine', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function matiere()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Matiere', 'idmatiere', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function datation()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Datation', 'iddate', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeAuthorFilter($query, $array)
|
|
|
|
{
|
2015-02-23 12:23:01 +01:00
|
|
|
if ($array == []) return $query;
|
|
|
|
$query->whereHas('auteurs', function($q) use ($array)
|
|
|
|
{
|
|
|
|
$q->whereIn('id', $array);
|
|
|
|
});
|
2015-02-22 16:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeDesignationFilter($query, $array)
|
|
|
|
{
|
2015-02-23 12:23:01 +01:00
|
|
|
if ($array == []) return $query;
|
|
|
|
$query->whereHas('designations', function($q) use ($array)
|
|
|
|
{
|
|
|
|
$q->whereIn('id', $array);
|
|
|
|
});
|
2015-02-22 16:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeDomaineFilter($query, $array)
|
|
|
|
{
|
2015-02-23 12:23:01 +01:00
|
|
|
if ($array == []) return $query;
|
|
|
|
$query->whereHas('domaine', function($q) use ($array)
|
|
|
|
{
|
|
|
|
$q->whereIn('id', $array);
|
|
|
|
});
|
2015-02-22 16:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeMatiereFilter($query, $array)
|
|
|
|
{
|
2015-02-23 12:23:01 +01:00
|
|
|
if ($array == []) return $query;
|
|
|
|
$query->whereHas('matiere', function($q) use ($array)
|
|
|
|
{
|
|
|
|
$q->whereIn('id', $array);
|
|
|
|
});
|
2015-02-22 16:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeTechniqueFilter($query, $array)
|
|
|
|
{
|
2015-02-23 12:23:01 +01:00
|
|
|
if ($array == []) return $query;
|
|
|
|
$query->whereHas('technique', function($q) use ($array)
|
|
|
|
{
|
|
|
|
$q->whereIn('id', $array);
|
|
|
|
});
|
2015-02-22 16:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeDebutFilter($query, $date)
|
|
|
|
{
|
|
|
|
if ($date == '') return $query;
|
|
|
|
$query->whereHas('datation', function($q) use ($date)
|
|
|
|
{
|
|
|
|
$q->where('debut', '>=', $date);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeFinFilter($query, $date)
|
|
|
|
{
|
|
|
|
if ($date == '') return $query;
|
|
|
|
$query->whereHas('datation', function($q) use ($date)
|
|
|
|
{
|
|
|
|
$q->where('debut', '<=', $date);
|
|
|
|
});
|
|
|
|
}
|
2015-02-18 23:15:18 +01:00
|
|
|
}
|