Base de ingrédient terminé
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user