Finish Advanced Search
This commit is contained in:
@@ -97,6 +97,40 @@ class RecetteRepository extends Repository implements UseIngredientsInterface, U
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
public function advancedRecetteSearch( string $title = "", array $tagsId= [], array $ingredientsId= [] ): ?array {
|
||||
|
||||
$tableLinkIngredients = IngredientRepository::getStructure()['link_recettes'];
|
||||
$tableLinkTags = TagRepository::getStructure()['link_recettes'];
|
||||
|
||||
$sqlQuery = "SELECT ({$this->tableName}.num_recette) FROM {$this->tableName} LEFT JOIN {$tableLinkIngredients} ON {$this->tableName}.num_recette = {$tableLinkIngredients}.num_recette LEFT JOIN {$tableLinkTags} ON {$this->tableName}.num_recette = {$tableLinkTags}.num_recette";
|
||||
|
||||
if( $title != "" || $tagsId !== [] || $ingredientsId !== [] ) {
|
||||
$sqlQuery .= " WHERE ";
|
||||
if ($title != "")
|
||||
$sqlQuery .= " titre_recette LIKE '%{$title}%' AND";
|
||||
if ($tagsId !== [])
|
||||
$sqlQuery .= " num_tag IN (" . implode(",", $tagsId) . ") AND";
|
||||
if ($ingredientsId !== [])
|
||||
$sqlQuery .= " num_ingredient IN (" . implode(",", $ingredientsId) . ") AND";
|
||||
$sqlQuery = substr($sqlQuery, 0, -3);
|
||||
}
|
||||
$sqlQuery .= ";";
|
||||
|
||||
$results = $this->selectGetAll($sqlQuery, true);
|
||||
if( $results === null )
|
||||
return null;
|
||||
|
||||
$alreadyGettedId = [];
|
||||
for( $i = 0; $i < count( $results ); $i++ ){
|
||||
if( in_array( $results[$i]['num_recette'], $alreadyGettedId ) )
|
||||
unset( $results[$i] );
|
||||
else
|
||||
$alreadyGettedId[] = $results[$i]['num_recette'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function add( Model $recette ): bool {
|
||||
return $this->addEntity( $recette );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user