/** * Query the reader. Store results in the object for use by build_table. * * @param int $pagesize size of page for paginated displayed table. * @param bool $useinitialsbar do you want to use the initials bar. */ public function query_db($pagesize, $useinitialsbar = true) { $total = \enrol_lti\helper::count_lti_tools(array('courseid' => $this->courseid)); $this->pagesize($pagesize, $total); $tools = \enrol_lti\helper::get_lti_tools(array('courseid' => $this->courseid), $this->get_page_start(), $this->get_page_size()); $this->rawdata = $tools; // Set initial bars. if ($useinitialsbar) { $this->initialbars($total > $pagesize); } }
$ltiplugin->update_status($instance, ENROL_INSTANCE_DISABLED); redirect($PAGE->url); } } } else { if ($action === 'enable') { if ($ltiplugin->can_hide_show_instance($instance)) { if ($instance->status != ENROL_INSTANCE_ENABLED) { $ltiplugin->update_status($instance, ENROL_INSTANCE_ENABLED); redirect($PAGE->url); } } } } } } echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('toolsprovided', 'enrol_lti')); echo "<p>" . get_string('toolsprovided_help', 'enrol_lti') . "</p>"; if (\enrol_lti\helper::count_lti_tools(array('courseid' => $courseid)) > 0) { $table = new \enrol_lti\manage_table($courseid); $table->define_baseurl($pageurl); $table->out(50, false); } else { $notify = new \core\output\notification(get_string('notoolsprovided', 'enrol_lti'), \core\output\notification::NOTIFY_WARNING); echo $OUTPUT->render($notify); } if ($ltiplugin->can_add_instance($course->id)) { echo $OUTPUT->single_button(new moodle_url('/enrol/editinstance.php', array('type' => 'lti', 'courseid' => $course->id, 'returnurl' => new moodle_url('/enrol/lti/index.php', array('courseid' => $course->id)))), get_string('add')); } echo $OUTPUT->footer();
/** * Test returning the number of available tools. */ public function test_count_lti_tools() { // Create two tools belonging to the same course. $course1 = $this->getDataGenerator()->create_course(); $data = new stdClass(); $data->courseid = $course1->id; $this->create_tool($data); $this->create_tool($data); // Create two more tools in a separate course. $course2 = $this->getDataGenerator()->create_course(); $data = new stdClass(); $data->courseid = $course2->id; $this->create_tool($data); // Set the next tool to disabled. $data->status = ENROL_INSTANCE_DISABLED; $this->create_tool($data); // Count all the tools. $count = \enrol_lti\helper::count_lti_tools(); $this->assertEquals(4, $count); // Count all the tools in course 1. $count = \enrol_lti\helper::count_lti_tools(array('courseid' => $course1->id)); $this->assertEquals(2, $count); // Count all the tools in course 2 that are disabled. $count = \enrol_lti\helper::count_lti_tools(array('courseid' => $course2->id, 'status' => ENROL_INSTANCE_DISABLED)); $this->assertEquals(1, $count); // Count all the tools that are enabled. $count = \enrol_lti\helper::count_lti_tools(array('status' => ENROL_INSTANCE_ENABLED)); $this->assertEquals(3, $count); }