Base de ingrédient terminé
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domain\Recettes;
|
||||
|
||||
use App\Domain\Ingredients\IngredientRepository;
|
||||
use App\Domain\Ingredients\UseIngredientsInterface;
|
||||
use App\Domain\Model;
|
||||
use App\Helpers\Markdown;
|
||||
|
||||
@@ -15,8 +17,18 @@ class Recette extends Model {
|
||||
public string $publication_date;
|
||||
public int $temps_de_preparation;
|
||||
|
||||
public function getID(): int
|
||||
{
|
||||
return $this->num_recette;
|
||||
}
|
||||
|
||||
public function getHTMLDescription(): string {
|
||||
return Markdown::convertToHTML( $this->description_recette );
|
||||
}
|
||||
|
||||
public function getAllLinkedIngredients(): ?array
|
||||
{
|
||||
return new RecetteRepository()->getAllLinkedIngredients( $this );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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