Exemplo n.º 1
0
 public function edit($step)
 {
     $obj = new Answer();
     if (!$_POST) {
         $data = $this->_get_test();
         $topics = $data['topics'];
         $topic_id = $topics[$step - 1]['id'];
         $condition = array('user_id' => $this->_user->id, 'topic_id' => $topic_id);
         $obj->where($condition)->get();
         $json = array_merge($obj->to_array(), $this->_get_test());
         $json['aChoose'] = $json['aChoose'] ? explode(',', $json['aChoose']) : array();
         echo json_encode($this->_filter($json));
     } else {
         if (isset($_POST['model']) and $model = $_POST['model']) {
             $data = json_decode($model);
             $get = $this->_save($data);
             if (isset($get['error'])) {
                 json_encode($get);
             } else {
                 $get['aChoose'] = explode(',', $get['aChoose']);
                 echo json_encode($this->_filter($get));
             }
         } else {
             if (isset($_POST['_method']) and $_POST['_method'] === 'DELETE') {
                 $obj->delete();
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function delete($id)
 {
     $db = Connection::getInstance();
     // delete answer
     require_once ROOT . DS . 'application' . DS . 'model' . DS . 'class.answer.php';
     Answer::delete($id);
     // delete thread
     $sql = "DELETE FROM sse_thread WHERE thread_id = :id";
     $statement = $db->prepare($sql);
     $statement->execute(array(':id' => $id));
 }
Exemplo n.º 3
0
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "answer.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini");
$answer = new Answer(null, 1, 2, "The answer", null);
$answer->insert($pdo);
$answer->setAnswerText("A better answer");
$answer->update($pdo);
$answer->delete($pdo);
Exemplo n.º 4
0
 function test_delete()
 {
     //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
     $test_answer->delete();
     $result = Answer::getAll();
     //Assert
     $this->assertEquals($test_answer2, $result[0]);
 }