Add answer

@param \Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswer $answer
@return Survey
15930
public function addAnswer(\Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswer $answer)
    {
        $this->answers[] = $answer;

        return $this;
    }
1352976
public function correctAnswer(AbstractItem $question, $answer = [])
    {
        $corrected = new CorrectedAnswer();

        if (is_array($answer)) {
            foreach ($answer as $givenAnswer) {
                $item = $question->getItem($givenAnswer['itemId']);
                if (!empty($item->getPosition()) && $item->getPosition() === $givenAnswer['position']) {
                    $corrected->addExpected($item);
                } else {
                    $penalty = new GenericPenalty($question->getPenalty());
                    $corrected->addPenalty($penalty);
                }
            }
        }

        return $corrected;
    }
1142690
protected function expandQuestion($question, $questions) {
        if ($question->qtype == 'randomsamatch') {
            $subquestions = [];
            foreach ($questions as $otherquestion) {
                if ($otherquestion->qtype == 'shortanswer') {
                    foreach ($otherquestion->answers as $answer) {
                        if (intval($answer->fraction) === 1) {
                            array_push(
                                $subquestions, 
                                (object) [
                                    "id" => $answer->id,
                                    "questiontext" => $otherquestion->questiontext,
                                    "answertext" => $answer->answer
                                ]
                            );
                            // Only take the first correct answer because that's what Moodle does. 
                            break;
                        }
                    }
                } 
            }

            $question->match = (object) [
             'subquestions' => $subquestions
            ];
        }
        return $question;
    }
913505
public function validateAnswer($answer, AbstractItem $question, array $options = [])
    {
        $options[Validation::QUESTION] = $question;

        return $this->getAnswerValidator()->validate($answer, $options);
    }
408103
public function validateAfterSchema($answer, array $options = [])
    {
        $errors = [];

        if (empty($options[Validation::QUESTION])) {
            $question = $this->om->getRepository('UJMExoBundle:Item\Item')->findOneBy([
                'uuid' => $answer->questionId,
            ]);

            $options[Validation::QUESTION] = $question->getInteraction();
        }

        if (empty($options[Validation::QUESTION])) {
            $errors[] = [
                'path' => '/questionId',
                'message' => 'question does not exist',
            ];
        } elseif (!empty($answer['data']) && $this->itemDefinitions->isQuestionType($options[Validation::QUESTION]->getQuestion()->getMimeType())) {
            // Forward to item type validator
            $definition = $this->itemDefinitions->get($options[Validation::QUESTION]->getQuestion()->getMimeType());
            $errors = array_merge(
                $errors,
                $definition->validateAnswer($answer['data'], $options[Validation::QUESTION], array_merge($options, [Validation::NO_SCHEMA]))
            );
        }

        return $errors;
    }
941665
protected function updateProjectYml($answers) {
    $config_file = $this->getConfigValue('blt.config-files.project');
    $config = YamlMunge::parseFile($config_file);
    $config['project']['prefix'] = $answers['prefix'];
    $config['project']['machine_name'] = $answers['machine_name'];
    $config['project']['human_name'] = $answers['human_name'];
    $config['project']['profile']['name'] = $answers['profile'];
    // Hostname cannot contain underscores.
    $machine_name_safe = str_replace('_', '-', $answers['machine_name']);
    $config['project']['local']['hostname'] = str_replace('${project.machine_name}', $machine_name_safe, $config['project']['local']['hostname']);

    if (isset($answers['cm']['strategy'])) {
      $config['cm']['strategy'] = $answers['cm']['strategy'];
    }

    YamlMunge::writeFile($config_file, $config);
    $this->say("<info>$config_file updated.</info>");
  }
560899
public function vote(MembershipInterface $member, PollModelInterface $poll, array $answers): PodiumResponse
    {
        $voter = $this->getVoter();

        $voter->setMember($member);
        $voter->setPoll($poll);
        $voter->setAnswers($answers);

        return $voter->vote();
    }
409501
public function addResponse(FormResponse $response)
    {
        if ($this->responses->contains($response) === false) {
            $response->setForm($this);
            $this->responses->add($response);
        }

        return $this;
    }
1066093
private function addNode($answers, $node_type, $ask = '', array $attributes = [])
    {
        $node = Node::where(['type' => $node_type, 'pattern' => $ask])->first();

        if (is_null($node)) {
            $node = Node::create(array_merge([
                'type' => $node_type,
                'pattern' => $ask,
                'answers' => $answers,
            ], $attributes));
        } else {
            $node->answers = $answers;

            // Allows people set attributes
            foreach ($attributes as $key => $value) {
                if (!in_array($key, ['type', 'pattern', 'answers'])) {
                    $node->$key = $value;
                }
            }

            $node->save();
        }

        return $node;
    }
1043167
public function removeAnswer(\Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswer $answer)
    {
        $this->answers->removeElement($answer);
    }
654002
protected function add_question_question_answers($element) {
        // Check $element is one nested_backup_element
        if (! $element instanceof backup_nested_element) {
            throw new backup_step_exception('question_answers_bad_parent_element', $element);
        }

        // Define the elements
        $answers = new backup_nested_element('answers');
        $answer = new backup_nested_element('answer', array('id'), array(
            'answertext', 'answerformat', 'fraction', 'feedback',
            'feedbackformat'));

        // Build the tree
        $element->add_child($answers);
        $answers->add_child($answer);

        // Set the sources
        $answer->set_source_table('question_answers', array('question' => backup::VAR_PARENTID), 'id ASC');

        // Aliases
        $answer->set_source_alias('answer', 'answertext');

        // don't need to annotate ids nor files
    }
322314
public function addAnswerItem(\Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswerItem $answerItem)
    {
        $this->answerItems[] = $answerItem;

        return $this;
    }
242559
function giveAnswer(answeringPlayer, answer) {
    if(answeringPlayer === seller) return;
    if(answer <= currentBid) return;

    buyer = answeringPlayer;
    currentBid = answer;

    resetTimer();
    notify(false);
  }
334465
public function addAnswer(Answer $answer)
    {
        if (!$this->answers->contains($answer)) {
            $this->answers->add($answer);
            $answer->setPaper($this);
        }
    }
991491
public function addReply(\BisonLab\SakonninBundle\Entity\Message $replies)
    {
        $this->replies[] = $replies;

        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;
    }
1203112
public function correctAnswer(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();

        if (!is_null($answer)) {
            foreach ($answer as $holeAnswer) {
                $hole = $question->getHole($holeAnswer['holeId']);
                if ($hole) {
                    $keyword = $hole->getKeyword($holeAnswer['answerText']);
                    if (!empty($keyword)) {
                        if (0 < $keyword->getScore()) {
                            $corrected->addExpected($keyword);
                        } else {
                            $corrected->addUnexpected($keyword);
                        }
                    } else {
                        // Retrieve the best answer for the hole
                        $corrected->addMissing($this->findHoleExpectedAnswer($hole));
                    }
                }
            }
        } else {
            $holes = $question->getHoles();

            foreach ($holes as $hole) {
                $corrected->addMissing($this->findHoleExpectedAnswer($hole));
            }
        }

        return $corrected;
    }