Add answerItem

@param \Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswerItem $answerItem
@return SurveyItem
322314
public function addAnswerItem(\Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswerItem $answerItem)
    {
        $this->answerItems[] = $answerItem;

        return $this;
    }
413828
public function addItem(Item $feedItem)
    {
        if ($feedItem->getVersion() != $this->version)
        {
            $msg = sprintf('Feed type mismatch: This instance can handle %s feeds only, but item for %s feeds given.', $this->version, $feedItem->getVersion());
            throw new \InvalidArgumentException($msg);
        }

        $this->items[] = $feedItem;

        return $this;
    }
412818
public function addQuestion(Item $question)
    {
        $stepQuestions = $this->stepQuestions->toArray();
        foreach ($stepQuestions as $stepQuestion) {
            /** @var StepItem $stepQuestion */
            if ($stepQuestion->getQuestion() === $question) {
                return; // The question is already linked to the Step
            }
        }

        // Create a new StepItem to attach the question to the step
        $stepQuestion = new StepItem();
        $stepQuestion->setOrder($this->stepQuestions->count());
        $stepQuestion->setStep($this);
        $stepQuestion->setQuestion($question);

        return $stepQuestion;
    }
625481
public function correctAnswer(AbstractItem $question, $answer)
    {
        $scoreRule = json_decode($question->getQuestion()->getScoreRule(), true);

        if ('fixed' === $scoreRule['type']) {
            return $this->getCorrectAnswerForFixMode($question, $answer);
        } else {
            // 3 sum submode
            switch ($question->getSumMode()) {
              case GridQuestion::SUM_CELL:
                return $this->getCorrectAnswerForSumCellsMode($question, $answer);
              break;
              case GridQuestion::SUM_COLUMN:
                return $this->getCorrectAnswerForColumnSumMode($question, $answer);
              break;
              case GridQuestion::SUM_ROW:
                return $this->getCorrectAnswerForRowSumMode($question, $answer);
              break;
            }
        }
    }
983122
public function correctAnswer(AbstractItem $question, $answers)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answers)) {
            switch ($question->getMode()) {
               case $question::MODE_FIND:
                  $foundUuids = [];

                  foreach ($answers->positions as $position) {
                      foreach ($question->getSelections()->toArray() as $selection) {
                          if ($position >= $selection->getBegin() && $position <= $selection->getEnd()) {
                              if ($selection->getScore() > 0) {
                                  if (!in_array($selection->getUuid(), $foundUuids)) {
                                      $foundUuids[] = $selection->getUuid();
                                      $corrected->addExpected($selection);
                                  }
                              } else {
                                  $corrected->addUnexpected($selection);
                              }
                          }
                      }
                  }

                  $bestAnswers = $this->expectAnswer($question);
                  $uuids = array_map(function ($selection) {
                      return $selection->getUuid();
                  }, $bestAnswers);

                  if ($question->getPenalty() > 0) {
                      $penaltyTimes = $answers['tries'] - count($foundUuids);

                      for ($i = 0; $i < $penaltyTimes; ++$i) {
                          $unexpected = new Selection();
                          $unexpected->setScore(-1 * $question->getPenalty());
                          $corrected->addUnexpected($unexpected);
                      }
                  }

                  foreach ($uuids as $uuid) {
                      if (!in_array($uuid, $foundUuids)) {
                          $corrected->addMissing($question->getSelection($uuid));
                      }
                  }

                  return $corrected;

               case $question::MODE_SELECT:
                  foreach ($answers['selections'] as $selectionId) {
                      $selection = $question->getSelection($selectionId);
                      $selection->getScore() > 0 ? $corrected->addExpected($selection) : $corrected->addUnexpected($selection);
                  }

                  $bestAnswers = $this->expectAnswer($question);
                  $uuids = array_map(function ($selection) {
                      return $selection->getUuid();
                  }, $bestAnswers);

                  foreach ($uuids as $uuid) {
                      if (!in_array($uuid, $answers['selections'])) {
                          $corrected->addMissing($question->getSelection($uuid));
                      }
                  }

                  return $corrected;
               case $question::MODE_HIGHLIGHT:
                  $foundElements = [];

                  if (isset($answers['highlights'])) {
                      foreach ($answers['highlights'] as $highlightAnswer) {
                          if ($colorSelection = $question->getColorSelection(['color_uuid' => $highlightAnswer['colorId'], 'selection_uuid' => $highlightAnswer['selectionId']])) {
                              $colorSelection->getScore() > 0 ? $corrected->addExpected($colorSelection) : $corrected->addUnexpected($colorSelection);

                              $foundElements[] = ['color_uuid' => $highlightAnswer['colorId'], 'selection_uuid' => $highlightAnswer['selectionId']];
                          }
                      }
                  }
                  $bestAnswers = $this->expectAnswer($question);
                  $elements = array_map(function ($colorSelection) {
                      //id always returns null as of now
                      return ['color_uuid' => $colorSelection->getColor()->getUuid(), 'selection_uuid' => $colorSelection->getSelection()->getUuid()];
                  }, $bestAnswers);

                  $addedMissing = 0;

                  foreach ($elements as $element) {
                      if (!in_array($element, $foundElements)) {
                          ++$addedMissing;
                          $corrected->addMissing($question->getColorSelection(['color_uuid' => $element['color_uuid'], 'selection_uuid' => $element['selection_uuid']]));
                      }
                  }

                  if ($question->getPenalty() > 0) {
                      $penaltyTimes = count($question->getSelections()) - count($foundElements);

                      for ($i = 0; $i < $penaltyTimes; ++$i) {
                          $unexpected = new Selection();
                          $unexpected->setScore(-1 * $question->getPenalty());
                          $corrected->addUnexpected($unexpected);
                      }
                  }

                  return $corrected;
            }
        }
    }
786038
final protected function askList($question, $items)
    {
        $indent = ($this->indent > 0) ? $this->indent : 0;
        $question = sprintf('%s%s: ', str_repeat(' ', 4 * $indent), $question);

        $question = new ChoiceQuestion($question, $items);
        return $this->getHelper('question')->ask($this->input, $this->output, $question);
    }
602631
public function addItem(\Lyon1\Bundle\PoobleBundle\Entity\SurveyItem $item)
    {
        $item->setSurvey($this);
        $this->items[] = $item;

        return $this;
    }
1039497
public function set(\BearFramework\App\Request\FormDataItem $dataItem): self
    {
        $this->data[$dataItem->name] = $dataItem;
        return $this;
    }
269005
public function addQuestion(QuestionInterface $question)
    {
        if (!$this->hasQuestion($question)) {
            $this->questions->add($question);
        }

        return $this;
    }
823952
public function expectAnswer(AbstractItem $question)
    {
        return array_filter($question->getRows()->toArray(), function (GridRow $row) {
            return 0 < $row->getScore();
        });
    }
645019
public function addItem(CartItem $cartItem)
    {
        $itemHash = $cartItem->generateHash();

        if ($this->getItem($itemHash)) {
            $this->getItem($itemHash)->qty += $cartItem->qty;
        } else {
            $this->cart->items[] = $cartItem;
        }

        app('events')->dispatch(
            'laracart.addItem', $cartItem
        );

        return $cartItem;
    }
1112254
public function addGalleryItem(\Amulen\MediaBundle\Entity\GalleryItem $galleryItems) {
        $galleryItems->setGallery($this);
        $this->galleryItems[] = $galleryItems;

        return $this;
    }
1015872
public function addCartItem($cartId, $cartItem)
    {
        $cartItem['id'] = count(session($this->itemsKey)) + 1;

        session()->push($this->itemsKey, $cartItem);
    }
575771
public function askCollection(QuestionWithPredefinedResponse $questionResponseCollection)
    {
        try {
            // If a preselected response exist, try to retireve response and return her
            return $questionResponseCollection->getPredefinedResponseCollection()
                                              ->offsetGetById($questionResponseCollection->getPreselectedResponse())
                                              ->getResponse();
        } catch (PredefinedResponseException $e) {
            // preselected response does not exist

            $choises = array();

            foreach ($questionResponseCollection->getPredefinedResponseCollection() as $response) {
                $choises[] = $response->getLabel();
            }

            // Ask question
            $choise = $this->question->ask(
                $this->input,
                $this->output,
                new ChoiceQuestion(
                    $this->buildQuestionText($questionResponseCollection),
                    $choises,
                    $this->getPreResponse($questionResponseCollection)
                )
            );

            try {
                return $questionResponseCollection->getPredefinedResponseCollection()
                                                  ->offsetGetByLabel($choise)
                                                  ->getResponse();
            } catch (PredefinedResponseException $e) {
                throw new ResponseExpectedException(
                    sprintf(
                        'Response "%s" does not exist',
                        $choise
                    )
                );
            }
        }
    }
412018
public function addLineItem(\HarvestCloud\CoreBundle\Entity\Payment\PaymentLineItem $lineItem)
    {
        $this->lineItems[] = $lineItem;

        $lineItem->setPayment($this);

        $this->recalculateAmount();

        return $this;
    }
44549
public function addCartItem($cartId, $cartItem)
    {
        $cartItem = $this->arraySnakeCase($cartItem);

        $cartItem['cart_id'] = $cartId;
        CartItem::create($cartItem);
    }
199746
public function addItem(
        $itemData,
        $locale,
        $userId,
        OrderEntity $order,
        ItemInterface $lastProcessedProductItem = null
    ) {
        $item = $this->itemManager->save(
            $itemData,
            $locale,
            $userId,
            null,
            null,
            $order->getCustomerContact(),
            $lastProcessedProductItem
        );

        $order->addItem($item->getEntity());

        return $item;
    }