Beispiel #1
0
        print_error('coursemisconf');
    }
    if (!($cm = get_coursemodule_from_instance('data', $data->id, $course->id))) {
        print_error('invalidcoursemodule');
    }
}
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/data:managetemplates', $context);
if (!$DB->count_records('data_fields', array('dataid' => $data->id))) {
    // Brand new database!
    redirect($CFG->wwwroot . '/mod/data/field.php?d=' . $data->id);
    // Redirect to field entry
}
// Trigger an event for viewing templates.
$event = \mod_data\event\template_viewed::create(array('context' => $context, 'courseid' => $course->id, 'other' => array('dataid' => $data->id)));
$event->add_record_snapshot('data', $data);
$event->trigger();
/// Print the page header
$strdata = get_string('modulenameplural', 'data');
// For the javascript for inserting template tags: initialise the default textarea to
// 'edit_template' - it is always present in all different possible views.
if ($mode == 'singletemplate') {
    $PAGE->navbar->add(get_string($mode, 'data'));
}
$PAGE->requires->js('/mod/data/data.js');
$PAGE->set_title($data->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('admin');
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($data->name), 2);
Beispiel #2
0
 /**
  * Test the template viewed event.
  *
  * There is no external API for viewing templates, so the unit test will simply create
  * and trigger the event and ensure the legacy log data is returned as expected.
  */
 public function test_template_viewed()
 {
     // Create a course we are going to add a data module to.
     $course = $this->getDataGenerator()->create_course();
     // The generator used to create a data module.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_data');
     // Create a data module.
     $data = $generator->create_instance(array('course' => $course->id));
     // Trigger an event for updating this record.
     $event = \mod_data\event\template_viewed::create(array('context' => context_module::instance($data->cmid), 'courseid' => $course->id, 'other' => array('dataid' => $data->id)));
     // Trigger and capture the event for updating the data record.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\mod_data\\event\\template_viewed', $event);
     $this->assertEquals(context_module::instance($data->cmid), $event->get_context());
     $expected = array($course->id, 'data', 'templates view', 'templates.php?id=' . $data->cmid . '&d=' . $data->id, $data->id, $data->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $url = new moodle_url('/mod/data/templates.php', array('d' => $data->id));
     $this->assertEquals($url, $event->get_url());
 }