Base de ingrédient terminé

This commit is contained in:
2026-04-02 18:10:47 +02:00
parent e79cc73e6d
commit 8a173ed2c7
10 changed files with 246 additions and 13 deletions

View File

@@ -2,10 +2,13 @@
namespace App\Domain\Recettes;
use App\Domain\Ingredients\Ingredient;
use App\Domain\Ingredients\IngredientRepository;
use App\Domain\Ingredients\UseIngredientsInterface;
use App\Domain\Model;
use App\Domain\Repository;
class RecetteRepository extends Repository {
class RecetteRepository extends Repository implements UseIngredientsInterface {
public static function getEntity(): string
{
@@ -63,4 +66,28 @@ class RecetteRepository extends Repository {
return $this->deleteEntity( $recette, 'num_recette' );
}
public function getAllLinkedIngredients(Model $entity): ?array
{
$ingredientRepo = new IngredientRepository();
$response = $ingredientRepo->getIdLinkedTo( 'recettes', 'num_recette', $entity );
return array_map( function($arr) use($ingredientRepo) {
return $ingredientRepo->getByID( $arr['num_ingredient'] );
}, $response );
}
public function addAnIngredient(Ingredient $ingredient, Model $entity): bool
{
$ingredientRepo = new IngredientRepository();
return $ingredientRepo->addLinkBetween( 'recettes', 'num_recette', $ingredient, $entity );
}
public function removeAnIngredient(Ingredient $ingredient, Model $entity): bool
{
$ingredientRepo = new IngredientRepository();
return $ingredientRepo->removeLinkBetween( 'recettes', 'num_recette', $ingredient, $entity );
}
}