Finish tag et commencer à ajouter les template.s
This commit is contained in:
@@ -6,15 +6,30 @@ use App\Domain\LinkableInterface;
|
||||
use App\Domain\Recettes\Recette;
|
||||
use App\Domain\Repository;
|
||||
use App\Domain\Model;
|
||||
use App\Domain\Tags\Tag;
|
||||
use App\Kernel;
|
||||
|
||||
/**
|
||||
* Classe qui va permettre de gérer les requêtes BDD en lien avec les ingrédients.
|
||||
* Les ingrédients sont liables à d'autres entités comme les Recettes.
|
||||
*/
|
||||
class IngredientRepository extends Repository implements LinkableInterface {
|
||||
|
||||
/**
|
||||
* Permet d'avoir le nom de l'entité dont dépend ce repo.
|
||||
* @return string
|
||||
*/
|
||||
public static function getEntity(): string
|
||||
{
|
||||
return Ingredient::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* La structure de notre table dans la BDD.
|
||||
* Un champ link_recettes a été ajouté pour donner le nom de la table de lien entre nos recettes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStructure(): array
|
||||
{
|
||||
return [
|
||||
@@ -27,6 +42,19 @@ class IngredientRepository extends Repository implements LinkableInterface {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'obtenir une liste de tous les ingrédients objet Ingreident.
|
||||
*
|
||||
* @return Ingredient[]|null
|
||||
*/
|
||||
public function getAll(): ?array {
|
||||
$sqlQuery = "SELECT * FROM {$this->tableName};";
|
||||
$results = $this->selectGetAll($sqlQuery);
|
||||
if( $results === null )
|
||||
return null;
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'obtenir un ingrédient spécifique par son ID.
|
||||
*
|
||||
@@ -49,6 +77,7 @@ class IngredientRepository extends Repository implements LinkableInterface {
|
||||
* @param string $linkingField Le champ qui permet de faire la liaison des ingrédients avec une autre entité.
|
||||
* @param Model $linkedEntity L'autre entité.
|
||||
*
|
||||
* @see LinkableInterface
|
||||
* @return array|null
|
||||
*/
|
||||
public function getIdLinkedTo( string $linkedTo, string $linkingField, Model $linkedEntity ): ?array {
|
||||
@@ -64,6 +93,17 @@ class IngredientRepository extends Repository implements LinkableInterface {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'ajouter un lien entre un ingrédient et une autre entité comme Recette.
|
||||
*
|
||||
* @param string $linkedTo
|
||||
* @param string $linkingField
|
||||
* @param Model $linkedEntity
|
||||
* @param Model $ingredientEntity
|
||||
*
|
||||
* @see LinkableInterface
|
||||
* @return bool
|
||||
*/
|
||||
public function addLinkBetween( string $linkedTo, string $linkingField, Model $linkedEntity, Model $ingredientEntity ): bool {
|
||||
|
||||
$linkName = 'link_' . $linkedTo;
|
||||
@@ -77,6 +117,17 @@ class IngredientRepository extends Repository implements LinkableInterface {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retire un lien dans la BDD entre un ingrédient et une autre entité.
|
||||
*
|
||||
* @param string $linkedTo
|
||||
* @param string $linkingField
|
||||
* @param Model $linkedEntity
|
||||
* @param Model $ingredientEntity
|
||||
*
|
||||
* @see LinkableInterface
|
||||
* @return bool
|
||||
*/
|
||||
public function removeLinkBetween(string $linkedTo, string $linkingField, Model $linkedEntity, Model $ingredientEntity ): bool
|
||||
{
|
||||
$linkName = 'link_' . $linkedTo;
|
||||
@@ -88,14 +139,35 @@ class IngredientRepository extends Repository implements LinkableInterface {
|
||||
return $statement->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajouter un ingrédient dans la BDD.
|
||||
*
|
||||
* @param Model $ingredient
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function add( Model $ingredient ): bool {
|
||||
return $this->addEntity( $ingredient );
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour un ingrédient dans la BDD.
|
||||
*
|
||||
* @param Model $ingredient
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update( Model $ingredient ): bool {
|
||||
return $this->updateEntity( $ingredient, 'num_ingredient' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime un ingrédient de la BDD.
|
||||
*
|
||||
* @param Model $ingredient
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete( Model $ingredient ): bool {
|
||||
return $this->deleteEntity( $ingredient, 'num_ingredient' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user