Ejemplo n.º 1
0
 public function create_object($args)
 {
     $args['post_type'] = 'webwork_question';
     $post_id = parent::create_object($args);
     if (!$post_id || is_wp_error($post_id)) {
         return $post_id;
     }
     $question = new \WeBWorK\Server\Question($post_id);
     $clean_question = clone $question;
     $problem_id = isset($args['problem_id']) ? (int) $args['problem_id'] : false;
     if ($problem_id) {
         $question->set_problem_id($problem_id);
     }
     $content = isset($args['content']) ? $args['content'] : '';
     $question->set_content($content);
     $tried = isset($args['tried']) ? $args['tried'] : '';
     $question->set_tried($tried);
     if (isset($args['post_date'])) {
         $question->set_post_date($args['post_date']);
     }
     if ($clean_question != $question) {
         $question->save();
     }
     return $post_id;
 }
Ejemplo n.º 2
0
 public function create_item($request)
 {
     $params = $request->get_params();
     $problem_id = $params['problem_id'];
     $content = $params['content'];
     $tried = $params['tried'];
     $problem_data = null;
     if (isset($params['post_data_key'])) {
         $post_data_key = $params['post_data_key'];
         $problem_data = get_option($post_data_key);
         // Don't ever keep this data around.
         delete_option($post_data_key);
     }
     // Try fetching another question from the same problem.
     if (!$problem_data) {
         $query = new Query(array('problem_id' => $problem_id));
         $questions = $query->get();
         foreach ($questions as $q) {
             if ($q->get_problem_text()) {
                 $problem_data = array('problem_id' => $q->get_problem_id(), 'problem_set' => $q->get_problem_set(), 'course' => $q->get_course(), 'section' => $q->get_section(), 'problem_text' => $q->get_problem_text());
                 break;
             }
         }
     }
     $question = new \WeBWorK\Server\Question();
     $question->set_author_id(get_current_user_id());
     $question->set_content($content);
     $question->set_tried($tried);
     $question->set_problem_id($problem_data['problem_id']);
     $question->set_problem_set($problem_data['problem_set']);
     $question->set_course($problem_data['course']);
     $question->set_section($problem_data['section']);
     $question->set_problem_text($problem_data['problem_text']);
     if ($question->save()) {
         $query = new Query(array('question_id' => $question->get_id()));
         $results = $query->get_for_endpoint();
         // @todo not found?
         $retval = reset($results);
         $r = rest_ensure_response($retval);
         $r->set_status(201);
     } else {
         $r = rest_ensure_response(false);
         $r->set_status(500);
     }
     return $r;
 }
Ejemplo n.º 3
0
 public function test_set_section()
 {
     $q = self::factory()->question->create();
     $question = new \WeBWorK\Server\Question($q);
     $section = 'foo';
     $question->set_section($section);
     $this->assertTrue($question->save());
     $question2 = new \WeBWorK\Server\Question($q);
     $this->assertSame($section, $question2->get_section());
 }
Ejemplo n.º 4
0
 public function create_item($request)
 {
     $params = $request->get_params();
     $problem_id = $params['problem_id'];
     $content = $params['content'];
     $tried = $params['tried'];
     $question = new \WeBWorK\Server\Question();
     $question->set_author_id(get_current_user_id());
     $question->set_content($content);
     $question->set_tried($tried);
     $question->set_problem_id($problem_id);
     if ($question->save()) {
         $retval = array('questionId' => $question->get_id(), 'content' => $question->get_content(), 'tried' => $question->get_tried(), 'authorAvatar' => $question->get_author_avatar(), 'authorName' => $question->get_author_name());
         $r = rest_ensure_response($retval);
         $r->set_status(201);
     } else {
         $r = rest_ensure_response(false);
         $r->set_status(500);
     }
     return $r;
 }