Remove answer

@param ServerQuestionAnswer $answer

@return Server
169017
public function removeAnswer(ServerQuestionAnswer $answer)
    {
        if ($this->answers->contains($answer) === false) {
            $this->answers->removeElement($answer);
        }

        return $this;
    }
174843
public function deserialize($data, Answer $answer = null, array $options = [])
    {
        $answer = $answer ?: new Answer();

        $this->sipe('id', 'setUuid', $data, $answer);
        $this->sipe('questionId', 'setQuestionId', $data, $answer);
        $this->sipe('tries', 'setTries', $data, $answer);
        $this->sipe('score', 'setScore', $data, $answer);
        $this->sipe('feedback', 'setFeedback', $data, $answer);

        if (isset($data['usedHints'])) {
            foreach ($data['usedHints'] as $usedHint) {
                $answer->addUsedHint($usedHint['id']);
            }
        }
        if (!empty($data['data'])) {
            $answer->setData(json_encode($data['data']));
        }

        return $answer;
    }
1005048
public function removeResponse(FormResponse $response)
    {
        if ($this->responses->contains($response) === true) {
            $response->setForm(null);
            $this->responses->removeElement($response);
        }

        return $this;
    }
80614
protected function parseAnswerLine(string $answer)
    {
        if (is_null($this->question)) {
            throw new SyntaxException(_('辞書は「Q,」で始めなければなりません。'));
        } elseif ($this->answers) {
            $this->answers .= ",$answer";
        } else {
            $this->answers = $answer;
        }
    }
743377
public function deleteFact(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref    = $request->get('xref', '');
        $fact_id = $request->get('fact_id');

        $record = GedcomRecord::getInstance($xref, $tree);

        Auth::checkRecordAccess($record, true);

        foreach ($record->facts() as $fact) {
            if ($fact->id() == $fact_id && $fact->canShow() && $fact->canEdit()) {
                $record->deleteFact($fact_id, true);
                break;
            }
        }

        return response();
    }
138297
public function convertToBool($answer)
    {
        if (!$this->caseSensitive) {
            $answer = strtoupper($answer);
        }

        // If it equals confirm yes
        if ($answer == $this->confirmYes) {
            return true;
        }

        if ($answer == $this->confirmNo || $this->explicit === false) {
            return false;
        }

        $this->output->writeln($this->invalidConfirmationError);
    }
521045
public function destroy(FaqRequest $request, Faq $faq)
    {
        try {

            $faq->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('faq::faq.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('faq/faq/0'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('faq/faq/' . $faq->getRouteKey()))
                ->redirect();
        }

    }
785088
protected function delete(ServerRequestInterface $request)
    {
        $pollId = array_get($request->getQueryParams(), 'id');

        $actor = $request->getAttribute('actor');

        if ($actor->can('edit.polls') || ($actor->id == Question::find($pollId)->user_id && $actor->can('selfEditPolls'))) {
            return $this->fields->deletePoll($pollId);
        } else {
            throw new PermissionDeniedException();
        }
    }
934010
public function delete(string $version = HttpVersion::HTTP_1_1): HttpResponse
    {
        return HttpRequest::create($this->httpUri, $this->headers)
                ->delete($this->timeout, $version);
    }
502502
private function getCorrectAnswerForSumCellsMode(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answer)) {
            foreach ($answer as $gridAnswer) {
                $cell = $question->getCell($gridAnswer['cellId']);
                $choice = $cell->getChoice($gridAnswer['text']);

                if (!empty($choice)) {
                    if (0 < $choice->getScore()) {
                        $corrected->addExpected($choice);
                    } else {
                        $corrected->addUnexpected($choice);
                    }
                } else {
                    // Retrieve the best answer for the cell
                    $corrected->addMissing($this->findCellExpectedAnswer($cell));
                }
            }
        } else {
            $cells = $question->getCells();

            foreach ($cells as $cell) {
                if ($cell->isInput()) {
                    $corrected->addMissing($this->findCellExpectedAnswer($cell));
                }
            }
        }

        return $corrected;
    }
1262075
public function setQuestion($question)
    {
        if (false === is_string($question)) {
            throw new \InvalidArgumentException('Question should be a string');
        }

        $this->question = trim($question) . " " ;

        return $this;
    }
59890
public function removeAnswer(int $answerId): PodiumResponse
    {
        $pollAnswerRemover = $this->getAnswerRemover($answerId);

        if ($pollAnswerRemover === null) {
            throw new ModelNotFoundException('Poll of given ID can not be found.');
        }

        return $pollAnswerRemover->remove();
    }
1368866
protected function _filterAnswersOnly($sourceSurveyId, array $answers)
    {
        $s = $sourceSurveyId . 'X';
        $l = strlen($s);

        $results = array();
        foreach ($answers as $key => $value) {
            if (substr($key, 0, $l) == $s) {
                $results[$key] = $value;
            }
        }

        return $results;
    }
644025
public function removeAnswer(Answer $answer)
    {
        if ($this->answers->contains($answer)) {
            $this->answers->removeElement($answer);
        }
    }
223494
private function getCorrectAnswerForRowSumMode(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answer)) {
            // correct answers per row
            for ($i = 0; $i < $question->getRows(); ++$i) {
                // get cells where there is at least 1 expected answer for the current row (none possible)
                $rowCellsUuids = [];

                foreach ($question->getCells() as $cell) {
                    if ($cell->getCoordsY() === $i && $cell->isInput()) {
                        $rowCellsUuids[] = $cell->getUuid();
                    }
                }

                // if any answer is needed in this row
                if (!empty($rowCellsUuids)) {
                    // score will be applied only if all expected answers are there and valid
                    $all = true;

                    foreach ($rowCellsUuids as $expectedCellUuid) {
                        // if $expectedCellUuid found in answers
                        $givenAnwser = array_filter($answer, function ($given) use ($expectedCellUuid) {
                            return $given['cellId'] === $expectedCellUuid;
                        });
                        if (empty($givenAnwser)) {
                            $all = false;
                            break;
                        } else {
                            // check answer
                            $cell = $question->getCell($expectedCellUuid);
                            $currentAnswer = reset($givenAnwser);
                            $choice = $cell->getChoice($currentAnswer['text']);
                            // wrong or empty anwser -> score will not be applied
                            if (empty($choice) || (!empty($choice) && !$choice->isExpected())) {
                                $all = false;
                                break;
                            }
                        }
                    }

                    if ($all) {
                        $scoreToApply = $choice->getScore();
                        $corrected->addExpected(new GenericScore($scoreToApply));
                    } else {
                        $corrected->addPenalty(new GenericPenalty($question->getPenalty()));
                    }
                }
            }
        }

        return $corrected;
    }
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;
            }
        }
    }
1253049
public function remove($name)
    {
        $name = $this->getFullName($name);

        // Delete existing response cookie
        if (isset($this->responseCookies[$name])) {
            unset($this->responseCookies[$name]);
        }

        // Set response cookie if request cookie was set
        if (null !== $this->get($name)) {
            // Note: timestamp '1' = '1970-01-01 00:00:00 UTC'
            $this->set($name, 'deleted', '1');
        }

        return $this;
    }