public function get_items($request) { $params = $request->get_params(); $keys = array('orderby', 'order', 'answered', 'course', 'section'); $args = array(); foreach ($keys as $k) { if (isset($params[$k])) { $args[$k] = $params[$k]; } } // Programming if (isset($params['problemSet'])) { $args['problem_set'] = $params['problemSet']; } // More programming if (isset($args['answered'])) { if ('all' === $args['answered']) { $args['answered'] = null; } elseif ('answered' === $args['answered']) { $args['answered'] = true; } elseif ('unanswered' === $args['answered']) { $args['answered'] = false; } } $q = new Query($args); $questions = $q->get_for_endpoint(); $retval = array('filterOptions' => $q->get_all_filter_options(), 'questionIds' => array_keys($questions), 'questions' => $questions); $response = rest_ensure_response($retval); return $response; }