function test_findById() { //Arrange $test_field = "Joe FindById"; $test_quest_id = 1; $test_answer = new Answer($test_field, $test_quest_id); $test_answer->save(); $test_field2 = "Red FindById"; $test_quest_id2 = 2; $test_answer2 = new Answer($test_field2, $test_quest_id2); $test_answer2->save(); //Act $result = Answer::findById($test_answer->getId()); //Assert $this->assertEquals($test_answer, $result); }
/** * * @param Answer $answer * @return int id of the Answer inserted in base. False if it didn't work. */ public static function flush($answer) { $answerId = $answer->getId(); $answerVar = $answer->getAnswer(); $answerDate = $answer->getAnswerDate(); $likert = $answer->getLikert()->getId(); $user = $answer->getUser()->getId(); $question = $answer->getQuestion()->getId(); if ($answerId > 0) { $sql = 'UPDATE answer a SET ' . 'a.answer = ?, ' . 'a.answer_date = ?, ' . 'a.LIKERT_id_likert = ?, ' . 'a.USER_id_user = ?, ' . 'a.QUESTION_id_question = ? ' . 'WHERE a.id_answer = ?'; $params = array('ssiiii', &$answerVar, &$answerDate, &$likert, &$user, &$question, &$answerId); } else { $sql = 'INSERT INTO answer ' . '(answer, answer_date, LIKERT_id_likert, USER_id_user, QUESTION_id_question) ' . 'VALUES(?, ?, ?, ?, ?)'; $params = array('ssiii', &$answerVar, &$answerDate, &$likert, &$user, &$question); } $idInsert = BaseSingleton::insertOrEdit($sql, $params); if ($idInsert !== false && $answerId > 0) { $idInsert = $answerId; } return $idInsert; }
$answer = new Answer(); $answer->get_from_db($answer_id); $vote = new Vote(); $vote_id = 0; $user_vote_by_answer = array(); $user_vote_by_answer = get_user_vote_by_answer($user_id, $answer_id); if (!empty($user_vote_by_answer)) { $vote_id = $user_vote_by_answer[0]; $vote->get_from_db($vote_id); } ?> <label for = "formSurvey<?php print_r($question->getId()); ?> Answer<?php print_r($answer->getId()); ?> "><?php print_r($answer->getValue()); ?> <small><?php print_r($answer->getDescription()); ?> </small> </label> <input id="formSurvey<?php print_r($question->getId()); ?> Answer<?php print_r($answer->getId());
function test_getAnswers() { //Arrange $test_field = "What is their name?"; $test_description = "What you want to call your character."; $test_question = new Question($test_field, $test_description); $test_question->save(); $test_field = "Joe GetAll"; $test_quest_id = $test_question->getId(); $test_answer = new Answer($test_field, $test_quest_id); $test_answer->save(); //Act $test_question->addAnswer($test_answer->getId()); //Assert $result = $test_question->getAnswers($test_answer->getId()); $this->assertEquals($test_answer, $result[0]); }
} }); // QUESTION.HTML.TWIG -- needs fixed -- if a question has been deleted, id # is skipped and // end_flag = true. Need to somehow loop through just the questions in promptr->getQuestions // the following pages of promptr run -- adding more answers $app->post("/promptr/{id}/question/{quid}", function ($id, $quid) use($app) { $promptr = Promptr::find($id); $end_flag = false; $answer_field = $_POST['answer']; $new_answer = new Answer($answer_field, $quid); $new_answer->save(); ++$quid; $question = Question::findTempById($quid); $questions = Question::getTempQuestions(); if ($question != null) { $question->addAnswer($new_answer->getId()); $last_question = end($questions); if ($question == $last_question) { $end_flag = true; } } return $app['twig']->render('question.html.twig', array('question' => $question, 'end' => $end_flag, 'promptr' => $promptr, 'questions' => $questions)); }); // DISPLAY.HTML.TWIG // DISPLAY FINISHED answers to promptr run //will show the concatted together display of the list $app->get("/promptr/{id}/display", function ($id) use($app) { $promptr = Promptr::find($id); $questions = Question::getTempQuestions(); Question::deleteTempQuestions(); return $app['twig']->render('display.html.twig', array('promptr' => $promptr, 'questions' => $questions));
method="POST"> <div class="ac"> <section class="clearfix prefix_2"> <?php $answers = get_survey_answers($question->getId()); if (!empty($answers)) { foreach ($answers as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); if ($answer->getType() == "text" || $answer->getType() == "radio" || $answer->getType() == "checkbox") { ?> <label for = "formSurvey<?php print_r($session_survey->getId()); ?> Answer<?php print_r($answer->getId()); ?> "><?php print_r($answer->getValue()); ?> <small><?php print_r($answer->getDescription()); ?> </small> </label> <input id="formSurvey<?php print_r($session_survey->getId()); ?> Answer<?php print_r($answer->getId()); ?>
$group_votes += $group_answer_votes; $txt = $group_answer_votes; $pdf->MultiCell($result_field_width, '', $txt, 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M'); $number_answer++; } $pdf->MultiCell(20, '', "{$group_votes}", 1, 'C', 1, 1, '', '', true, 0, false, true, 8, 'M'); $number_group++; } // set color for background $pdf->SetFillColor(225, 225, 225); $pdf->MultiCell(20, '', "Всички", 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M'); // set color for background $pdf->SetFillColor(255, 255, 255); foreach ($answers as $answer_id) { $answer = new Answer(); $answer->get_from_db($answer_id); $txt = count(get_votes_by_answer($answer->getId())); $pdf->MultiCell($result_field_width, '', $txt, 1, 'C', 1, 0, '', '', true, 0, false, true, 8, 'M'); } // set color for background $pdf->SetFillColor(240, 240, 240); $pdf->MultiCell(20, '', 'Общо', 1, 'C', 1, 1, '', '', true, 0, false, true, 8, 'M'); // --------------------------------------------------------- ob_end_clean(); // Close and output PDF document // This method has several options, check the source code documentation for more information. $pdf->Output('survey_print.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ unset($_SESSION['survey_id']);