Пример #1
0
 /**
  * @param Criteria $criteria
  */
 public function decorate(Criteria $criteria)
 {
     $alcoholFrom = $this->form->get('alcohol')->get('from')->getData();
     $alcoholTo = $this->form->get('alcohol')->get('to')->getData();
     if (!is_null($alcoholFrom)) {
         $criteria->withAlcoholContentGreaterThan($alcoholFrom);
     }
     if (!is_null($alcoholTo)) {
         $criteria->withAlcoholContentLowerThan($alcoholTo);
     }
     $criteria->addQuery($this->form->get('query')->getData());
     $criteria->mustContainIngredients($this->form->get('ingredients')->getData());
     $tasteBuilder = new TasteBuilder();
     foreach ($this->form->get('taste')->getData() as $tasteName) {
         switch ($tasteName) {
             case Tastes::SWEET:
                 $tasteBuilder->sweet();
                 break;
             case Tastes::BITTER:
                 $tasteBuilder->bitter();
                 break;
             case Tastes::SALTY:
                 $tasteBuilder->salty();
                 break;
             case Tastes::SPICY:
                 $tasteBuilder->spicy();
                 break;
             case Tastes::SOUR:
                 $tasteBuilder->sour();
                 break;
         }
     }
     $criteria->updateRequiredTaste($tasteBuilder->buildTaste());
 }
 /**
  * @param UpdateRecipeDescriptionCommand $command
  * @throws RecipeNotFoundException
  * @throws \MyDrinks\Domain\Exception\InvalidArgumentException
  */
 public function handle(UpdateRecipeDescriptionCommand $command)
 {
     $recipe = $this->recipes->findBySlug($command->slug);
     if (is_null($recipe)) {
         throw new RecipeNotFoundException();
     }
     $description = new Description();
     if ((bool) $command->IBAOfficial) {
         $description->markAsIBAOfficial();
     }
     if (strlen($command->text)) {
         $description->setText($command->text);
     }
     if (!is_null($command->alcoholContent)) {
         $description->setAlcoholContent($command->alcoholContent);
     }
     if (!empty($command->taste) && is_array($command->taste)) {
         $tasteBuilder = new TasteBuilder();
         foreach ($command->taste as $tasteName) {
             switch ($tasteName) {
                 case Tastes::SWEET:
                     $tasteBuilder->sweet();
                     break;
                 case Tastes::BITTER:
                     $tasteBuilder->bitter();
                     break;
                 case Tastes::SALTY:
                     $tasteBuilder->salty();
                     break;
                 case Tastes::SPICY:
                     $tasteBuilder->spicy();
                     break;
                 case Tastes::SOUR:
                     $tasteBuilder->sour();
                     break;
             }
         }
         $description->changeTaste($tasteBuilder->buildTaste());
     }
     $recipe->updateDescription($description);
 }
Пример #3
0
 /**
  * @param $recipe
  * @param array $data
  */
 private function deserializeTaste(DomainRecipe $recipe, array $data)
 {
     $tasteBuilder = new TasteBuilder();
     if (array_key_exists('taste', $data)) {
         foreach ($data['taste'] as $tasteName) {
             switch ($tasteName) {
                 case Tastes::SWEET:
                     $tasteBuilder->sweet();
                     break;
                 case Tastes::BITTER:
                     $tasteBuilder->bitter();
                     break;
                 case Tastes::SALTY:
                     $tasteBuilder->salty();
                     break;
                 case Tastes::SPICY:
                     $tasteBuilder->spicy();
                     break;
                 case Tastes::SOUR:
                     $tasteBuilder->sour();
                     break;
             }
         }
     }
     $recipe->getDescription()->changeTaste($tasteBuilder->buildTaste());
 }