From d9cc1e2a4c560dc2723f652e1665be5303f5a1b9 Mon Sep 17 00:00:00 2001 From: Malibu Date: Sun, 22 Feb 2015 16:42:45 +0100 Subject: [PATCH] modified: SRC/app/Http/Controllers/ReferentController.php modified: SRC/app/Http/routes.php modified: SRC/app/Models/Oeuvre.php modified: SRC/resources/views/referent.blade.php --- .../Http/Controllers/ReferentController.php | 22 +++ SRC/app/Http/routes.php | 1 + SRC/app/Models/Oeuvre.php | 145 ++++++++++++++++++ SRC/resources/views/referent.blade.php | 25 +-- 4 files changed, 181 insertions(+), 12 deletions(-) diff --git a/SRC/app/Http/Controllers/ReferentController.php b/SRC/app/Http/Controllers/ReferentController.php index 9029bac..7d27245 100755 --- a/SRC/app/Http/Controllers/ReferentController.php +++ b/SRC/app/Http/Controllers/ReferentController.php @@ -10,6 +10,7 @@ use App\Models\Designation; use App\Models\Domaine; use App\Models\Matiere; use App\Models\Technique; +use App\Models\Oeuvre; use Response; @@ -120,4 +121,25 @@ class ReferentController extends Controller { return Response::json(array()); } + public function search() + { + $auteurs = Input::get('auteur', array()); + $designations = Input::get('designation', array()); + $domaines = Input::get('domaine', array()); + $matieres = Input::get('matiere', array()); + $techniques = Input::get('technique', array()); + $debut = Input::get('debut'); + $fin = Input::get('fin'); + + //echo Oeuvre::find(22)->domaine()->get(); + echo count(Oeuvre::techniqueFilter($techniques) + ->authorFilter($auteurs) + ->designationFilter($designations) + ->domaineFilter($domaines) + ->matiereFilter($matieres) + ->debutFilter($debut) + ->finFilter($fin) + ->get()); + } + } diff --git a/SRC/app/Http/routes.php b/SRC/app/Http/routes.php index c363a82..0a5d503 100644 --- a/SRC/app/Http/routes.php +++ b/SRC/app/Http/routes.php @@ -40,6 +40,7 @@ Route::group(['middleware' => 'auth'], function () Route::post('addListeOeuvre', 'ReferentController@addListeOeuvre'); Route::get('showListOeuvres/{id}', 'ReferentController@showListeOeuvres'); Route::post('setListOeuvres', 'ReferentController@setListOeuvres'); + Route::post('search', 'ReferentController@search'); }); Route::group(['middleware' => 'admin'], function () diff --git a/SRC/app/Models/Oeuvre.php b/SRC/app/Models/Oeuvre.php index 22b26f8..1a3f8ea 100644 --- a/SRC/app/Models/Oeuvre.php +++ b/SRC/app/Models/Oeuvre.php @@ -7,4 +7,149 @@ class Oeuvre extends Model { protected $table = 'oeuvre'; public $timestamps = false; + + 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) + { + foreach ($array as $author_id){ + + if ($author_id === reset($array)){ + $query->whereHas('auteurs', function($q) use ($author_id) + { + $q->where('id', '=', $author_id); + }); + }else{ + $query->orWhereHas('auteurs', function($q) use ($author_id) + { + $q->where('id', '=', $author_id); + }); + } + } + } + + public function scopeDesignationFilter($query, $array) + { + $q = $query; + + foreach ($array as $designation_id){ + + if ($designation_id === reset($array)){ + $query->whereHas('designations', function($q) use ($designation_id) + { + $q->where('id', '=', $designation_id); + }); + }else{ + $query->orWhereHas('designations', function($q) use ($designation_id) + { + $q->where('id', '=', $designation_id); + }); + } + } + } + + public function scopeDomaineFilter($query, $array) + { + $q = $query; + + foreach ($array as $domaine_id){ + + if ($domaine_id === reset($array)){ + $query->whereHas('domaine', function($q) use ($domaine_id) + { + $q->where('id', '=', $domaine_id); + }); + }else{ + $query->orWhereHas('domaine', function($q) use ($domaine_id) + { + $q->where('id', '=', $domaine_id); + }); + } + } + } + + public function scopeMatiereFilter($query, $array) + { + foreach ($array as $matiere_id){ + + if ($matiere_id === reset($array)){ + $query->whereHas('matiere', function($q) use ($matiere_id) + { + $q->where('id', '=', $matiere_id); + }); + }else{ + $query->orWhereHas('matiere', function($q) use ($matiere_id) + { + $q->where('id', '=', $matiere_id); + }); + } + } + } + + public function scopeTechniqueFilter($query, $array) + { + + foreach ($array as $technique_id){ + + if ($technique_id === reset($array)){ + $query->whereHas('technique', function($q) use ($technique_id) + { + $q->where('id', '=', $technique_id); + }); + }else{ + $query->orWhereHas('technique', function($q) use ($technique_id) + { + $q->where('id', '=', $technique_id); + }); + } + + } + } + + + 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); + }); + } } diff --git a/SRC/resources/views/referent.blade.php b/SRC/resources/views/referent.blade.php index ef16cc1..2c286b0 100755 --- a/SRC/resources/views/referent.blade.php +++ b/SRC/resources/views/referent.blade.php @@ -107,11 +107,12 @@ Recherche avancée
-
+ +
- @foreach ($data['auteur'] as $val) @@ -122,7 +123,7 @@
- @foreach ($data['designation'] as $val) @@ -133,7 +134,7 @@
- @foreach ($data['domaine'] as $val) @@ -144,7 +145,7 @@
- @foreach ($data['matiere'] as $val) @@ -155,9 +156,9 @@
- - @foreach ($data['designation'] as $val) + @foreach ($data['technique'] as $val) @endforeach @@ -166,19 +167,19 @@
- +
-
- +
+
-
- +
+