/** * Execute the request for this resource. * * @param mod_lti\local\ltiservice\response $response Response object for this request. */ public function execute($response) { global $CFG, $DB; $params = $this->parse_template(); $role = optional_param('role', '', PARAM_TEXT); $limitnum = optional_param('limit', 0, PARAM_INT); $limitfrom = optional_param('from', 0, PARAM_INT); if ($limitnum <= 0) { $limitfrom = 0; } try { if (!$this->get_service()->check_tool_proxy($params['product_code'])) { throw new \Exception(null, 401); } if (!($course = $DB->get_record('course', array('id' => $params['context_id']), 'id', IGNORE_MISSING))) { throw new \Exception(null, 404); } if (!($context = \context_course::instance($course->id))) { throw new \Exception(null, 404); } if (!($tool = $DB->get_record('lti_types', array('id' => $params['tool_code']), 'toolproxyid,enabledcapability,parameter', IGNORE_MISSING))) { throw new \Exception(null, 404); } $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $tool->toolproxyid), 'guid', IGNORE_MISSING); if (!$toolproxy || $toolproxy->guid !== $this->get_service()->get_tool_proxy()->guid) { throw new \Exception(null, 400); } $json = memberships::get_users_json($this, $context, $course->id, $tool, $role, $limitfrom, $limitnum, null, null); $response->set_content_type($this->formats[0]); $response->set_body($json); } catch (\Exception $e) { $response->set_code($e->getCode()); } }
/** * Execute the request for this resource. * * @param mod_lti\local\ltiservice\response $response Response object for this request. */ public function execute($response) { global $CFG, $DB; $params = $this->parse_template(); $linkid = $params['link_id']; $role = optional_param('role', '', PARAM_TEXT); $limitnum = optional_param('limit', 0, PARAM_INT); $limitfrom = optional_param('from', 0, PARAM_INT); if ($limitnum <= 0) { $limitfrom = 0; } try { if (empty($linkid)) { throw new \Exception(null, 404); } if (!($lti = $DB->get_record('lti', array('id' => $linkid), 'id,course,typeid,servicesalt', IGNORE_MISSING))) { throw new \Exception(null, 404); } $tool = $DB->get_record('lti_types', array('id' => $lti->typeid)); $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $tool->toolproxyid)); if (!$this->check_tool_proxy($toolproxy->guid, $response->get_request_data())) { throw new \Exception(null, 401); } if (!($course = $DB->get_record('course', array('id' => $lti->course), 'id', IGNORE_MISSING))) { throw new \Exception(null, 404); } if (!($context = \context_course::instance($lti->course))) { throw new \Exception(null, 404); } $modinfo = get_fast_modinfo($course); $cm = get_coursemodule_from_instance('lti', $linkid, $lti->course, false, MUST_EXIST); $cm = $modinfo->get_cm($cm->id); $info = new info_module($cm); if ($info->is_available_for_all()) { $info = null; } $json = memberships::get_users_json($this, $context, $lti->course, $tool, $role, $limitfrom, $limitnum, $lti, $info); $response->set_content_type($this->formats[0]); $response->set_body($json); } catch (\Exception $e) { $response->set_code($e->getCode()); } }