public function __construct($url) { $user_data = User::getUserData(['username', 'first_name', 'last_name', 'user_id', 'email', 'profile_pic'])[0]; $this->data['title'] = 'Question - NCube School'; $this->data['first_name'] = ucwords($user_data['first_name']); $this->data['last_name'] = ucwords($user_data['last_name']); $this->data['token'] = Token::generate(); $this->data['username'] = $user_data['username']; $this->data['side_active']['questions'] = ' active'; $this->data['profile_pic'] = User::getProfilePic($user_data['profile_pic']); $this->data['question'] = Question::getPublicQuestion($url[0])[0]; $this->data['q_user'] = User::getPublicUserData($this->data['question']['user_id'])[0]; $this->data['q_user']['profile_pic'] = User::getProfilePic($this->data['q_user']['profile_pic']); $this->data['question']['up_count'] = Question::getVoteUpCount($this->data['question']['q_id']); $this->data['question']['down_count'] = Question::getVoteDownCount($this->data['question']['q_id']); $this->data['question']['level'] = Question::getDifficultyLevel($this->data['question']['q_id']); $this->data['question']['answers_count'] = Question::getAnswersCount($this->data['question']['q_id']); $answers = Question::getAnswers($this->data['question']['q_id']); foreach ($answers as $key => $value) { $answers[$key]['user'] = User::getPublicUserData($value['user_id'])[0]; $answers[$key]['user']['profile_pic'] = User::getProfilePic($answers[$key]['user']['profile_pic']); } $this->data['answers'] = $answers; require_once 'include/header.php'; }
public function translateQuestions($old_slide_id, $new_slide_id, $source_arr, $language) { $questions_array = array(); $questions = array(); $translator = new LanguageTranslator('AIzaSyBlwXdmxJZ__ZNScwe4zq5r3qh3ebXb26k'); $questions_array = $this->dbQuery('SELECT * FROM questions INNER JOIN users on questions.user_id = users.id WHERE questions.based_on IS NULL AND questions.mark = "accepted" AND questions.item_id=' . $old_slide_id); if (count($questions_array)) { foreach ($questions_array as $row) { $question = new Question(); $question->createFromID($row['0']); $lastId = $question->getLastRevision(); $lastRevision = new Question(); $lastRevision->createFromID($lastId); $questions[] = $lastRevision; } } if (count($questions)) { $source = $source_arr['id']; $target_arr = explode('-', $language); $target = $target_arr[0]; foreach ($questions as $question) { $answers = array(); $answers = $question->getAnswers(); $q = $question->question; $question->question = $translator->translate($q, $target, $source); $question->item_id = $new_slide_id; $question->based_on = NULL; $question->user->id = $this->user->id; $question->id = $question->create(); if (count($answers)) { foreach ($answers as $answer) { $q = $answer['answer']; $answer['answer'] = $translator->translate($q, $target, $source); $q = $answer['explanation']; if ($q != '') { $answer['explanation'] = $translator->translate($q, $target, $source); } $question->addAnswer($answer['answer'], $answer['explanation'], $answer['is_right']); } } } } }
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]); }