示例#1
0
function addAnswer()
{
    $question = new Question($_POST);
    if ($question1 = Question::getAnswerByUserId($_SESSION['userId'], $question->question)) {
        $question->id = $question1->id;
        $question->update();
    } else {
        $question->insert();
    }
    header('main.php?action = login');
}
示例#2
0
 function test_update()
 {
     //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();
     $new_quest = "How tall are they?";
     $new_desc = "The height you want your character to be.";
     //Act
     $test_question->update($new_quest, $new_desc);
     //Assert
     $this->assertEquals(["How tall are they?", "The height you want your character to be."], [$test_question->getQuestion(), $test_question->getDescription()]);
 }
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "question.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini");
$question = new Question(null, 1, 2, "Huh?", null);
$question->insert($pdo);
$question->setQuestionText("What?");
$question->update($pdo);
$question->delete($pdo);
示例#4
0
 function init()
 {
     $question = new Question();
     $func = array_shift($this->param);
     if (is_numeric($func)) {
         $this->id = $func;
     } else {
         if ($func != '') {
             $_SERVER['REQUEST_METHOD'] = 'POST';
             $course_id = array_shift($this->param);
             Security::checkEditor($course_id);
             switch ($func) {
                 case 'save':
                     $data['course_id'] = $course_id;
                     $data['type_id'] = $_POST['type_id'];
                     $data['data'] = $_POST['data'];
                     $data['count'] = $_POST['count'];
                     $data['answer'] = $_POST['answer'];
                     $id = $_POST['id'];
                     try {
                         $question->update($id, $data);
                     } catch (Exception $e) {
                     }
                     header('Location: /admin_questions/' . $data['course_id']);
                     exit;
                     break;
                 case 'delete':
                     try {
                         $question_id = array_shift($this->param);
                         $question->delete($question_id);
                         echo "ok";
                     } catch (Exception $e) {
                         echo $e;
                     }
                     header('Location: /admin_questions/' . $course_id);
                     exit;
                     break;
                 case 'find':
                     try {
                         $data = array('course_id' => $course_id, 'type_id' => 0, 'data' => '', 'answer' => '');
                         $q_id = $question->add($data);
                         $data['id'] = $q_id;
                         echo json_encode($data);
                     } catch (Exception $e) {
                         echo $e;
                     }
                     exit;
                     break;
                 case 'load':
                     try {
                         $question_id = array_shift($this->param);
                         $data = $question->get(array('course_id' => $course_id, 'id' => $question_id));
                         echo json_encode($data);
                     } catch (Exception $e) {
                         echo $e;
                     }
                     exit;
                     break;
                 default:
             }
         } else {
             header('Location: /404');
             exit;
         }
     }
 }