Exemplo n.º 1
0
 /**
  * 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());
     }
 }