Exemplo n.º 1
0
 public function test_successful_save_for_new_item()
 {
     $response = new \WeBWorK\Server\Response();
     $response->set_content('foo');
     $response->set_question_id(20);
     $response->set_is_answer(false);
     $saved = $response->save();
     $this->assertTrue($saved);
     $new_response = new \WeBWorK\Server\Response($response->get_id());
     $this->assertSame('foo', $new_response->get_content());
     $this->assertSame(20, $new_response->get_question_id());
     $this->assertFalse($new_response->get_is_answer());
 }
Exemplo n.º 2
0
 public function create_item($request)
 {
     $params = $request->get_params();
     $question_id = $params['question_id'];
     $value = $params['value'];
     $response = new \WeBWorK\Server\Response();
     $response->set_author_id(get_current_user_id());
     $response->set_content($value);
     $response->set_question_id($question_id);
     if ($response->save()) {
         $retval = array('responseId' => $response->get_id(), 'content' => $response->get_content(), 'authorAvatar' => $response->get_author_avatar(), 'authorName' => $response->get_author_name());
         $r = rest_ensure_response($retval);
         $r->set_status(201);
     } else {
         $r = rest_ensure_response(false);
         $r->set_status(500);
     }
     return $r;
 }