modified: SRC/app/Http/Controllers/ReferentController.php

modified:   SRC/app/Models/Oeuvre.php
This commit is contained in:
Malibu 2015-02-23 12:23:01 +01:00
parent d9cc1e2a4c
commit f6027554fe
2 changed files with 29 additions and 81 deletions

View File

@ -131,15 +131,15 @@ class ReferentController extends Controller {
$debut = Input::get('debut'); $debut = Input::get('debut');
$fin = Input::get('fin'); $fin = Input::get('fin');
//echo Oeuvre::find(22)->domaine()->get(); $res = Oeuvre::authorFilter($auteurs)
echo count(Oeuvre::techniqueFilter($techniques)
->authorFilter($auteurs)
->designationFilter($designations) ->designationFilter($designations)
->domaineFilter($domaines) ->domaineFilter($domaines)
->matiereFilter($matieres) ->matiereFilter($matieres)
->debutFilter($debut) ->debutFilter($debut)
->finFilter($fin) ->finFilter($fin)
->get()); ->get();
return Response::json($res->toArray());
} }
} }

View File

@ -40,101 +40,49 @@ class Oeuvre extends Model {
public function scopeAuthorFilter($query, $array) public function scopeAuthorFilter($query, $array)
{ {
foreach ($array as $author_id){ if ($array == []) return $query;
$query->whereHas('auteurs', function($q) use ($array)
if ($author_id === reset($array)){ {
$query->whereHas('auteurs', function($q) use ($author_id) $q->whereIn('id', $array);
{ });
$q->where('id', '=', $author_id);
});
}else{
$query->orWhereHas('auteurs', function($q) use ($author_id)
{
$q->where('id', '=', $author_id);
});
}
}
} }
public function scopeDesignationFilter($query, $array) public function scopeDesignationFilter($query, $array)
{ {
$q = $query; if ($array == []) return $query;
$query->whereHas('designations', function($q) use ($array)
foreach ($array as $designation_id){ {
$q->whereIn('id', $array);
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) public function scopeDomaineFilter($query, $array)
{ {
$q = $query; if ($array == []) return $query;
$query->whereHas('domaine', function($q) use ($array)
foreach ($array as $domaine_id){ {
$q->whereIn('id', $array);
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) public function scopeMatiereFilter($query, $array)
{ {
foreach ($array as $matiere_id){ if ($array == []) return $query;
$query->whereHas('matiere', function($q) use ($array)
if ($matiere_id === reset($array)){ {
$query->whereHas('matiere', function($q) use ($matiere_id) $q->whereIn('id', $array);
{ });
$q->where('id', '=', $matiere_id);
});
}else{
$query->orWhereHas('matiere', function($q) use ($matiere_id)
{
$q->where('id', '=', $matiere_id);
});
}
}
} }
public function scopeTechniqueFilter($query, $array) public function scopeTechniqueFilter($query, $array)
{ {
if ($array == []) return $query;
foreach ($array as $technique_id){ $query->whereHas('technique', function($q) use ($array)
{
if ($technique_id === reset($array)){ $q->whereIn('id', $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) public function scopeDebutFilter($query, $date)
{ {
if ($date == '') return $query; if ($date == '') return $query;