public function test_set_post_date() { $r = self::factory()->response->create(); $response = new \WeBWorK\Server\Response($r); $new_date = '2015-05-05 05:05:05'; $response->set_post_date($new_date); $this->assertTrue($response->save()); $response2 = new \WeBWorK\Server\Response($r); $this->assertSame($new_date, $response2->get_post_date()); }
public function create_object($args) { $args['post_type'] = 'webwork_response'; $post_id = parent::create_object($args); if (!$post_id || is_wp_error($post_id)) { return $post_id; } $response = new \WeBWorK\Server\Response($post_id); $is_answer = isset($args['is_answer']) ? (bool) $args['is_answer'] : false; $response->set_is_answer($is_answer); $question_id = isset($args['question_id']) ? (int) $args['question_id'] : false; if ($question_id) { $response->set_question_id($question_id); } if (isset($args['post_date'])) { $response->set_post_date($args['post_date']); } $response->save(); return $post_id; }
public function update_item($request) { $retval = false; $params = $request->get_params(); if (isset($params['id']) && isset($params['is_answer'])) { $response = new \WeBWorK\Server\Response($params['id']); if ($response->exists()) { $response->set_is_answer($params['is_answer']); $retval = $response->save(); } } $response = rest_ensure_response($retval); if ($retval) { $response->set_status(200); } else { $response->set_status(500); } return $response; }
public function test_get_has_answer_cache_should_be_busted_after_response_save() { $q = self::factory()->question->create_and_get(); $r = new \WeBWorK\Server\Response(); $r->set_question_id($q->get_id()); $r->save(); $this->assertFalse($q->get_has_answer()); $r->set_is_answer(true); $r->save(); $this->assertTrue($q->get_has_answer()); }
public function update_item_permissions_check($request) { if (!is_user_logged_in()) { return false; } $params = $request->get_params(); if (!isset($params['id'])) { return false; } $response_id = $params['id']; $response = new \WeBWorK\Server\Response($response_id); if (!$response->exists()) { return false; } $question_id = $response->get_question_id(); if (!$question_id) { return false; } // @todo modeling $question = get_post($question_id); if (!$question) { return false; } $user_is_admin = current_user_can('edit_others_posts'); $user_is_admin = apply_filters('webwork_user_is_admin', $user_is_admin); return $user_is_admin || $question->post_author == get_current_user_id(); }