Esempio n. 1
0
 public function test_entry_deleted()
 {
     global $DB;
     // There is no proper API to call to trigger this event, so what we are
     // doing here is simply making sure that the events returns the right information.
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
     $context = context_module::instance($glossary->cmid);
     $prevmode = 'view';
     $hook = 'ALL';
     $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
     $entry = $glossarygenerator->create_content($glossary);
     $DB->delete_records('glossary_entries', array('id' => $entry->id));
     $eventparams = array('context' => $context, 'objectid' => $entry->id, 'other' => array('mode' => $prevmode, 'hook' => $hook, 'concept' => $entry->concept));
     $event = \mod_glossary\event\entry_deleted::create($eventparams);
     $event->add_record_snapshot('glossary_entries', $entry);
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_glossary\\event\\entry_deleted', $event);
     $this->assertEquals(CONTEXT_MODULE, $event->contextlevel);
     $this->assertEquals($glossary->cmid, $event->contextinstanceid);
     $expected = array($course->id, "glossary", "delete entry", "view.php?id={$glossary->cmid}&mode={$prevmode}&hook={$hook}", $entry->id, $glossary->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }
Esempio n. 2
0
        //delete glossary entry ratings
        require_once $CFG->dirroot . '/rating/lib.php';
        $delopt = new stdClass();
        $delopt->contextid = $context->id;
        $delopt->component = 'mod_glossary';
        $delopt->ratingarea = 'entry';
        $delopt->itemid = $entry->id;
        $rm = new rating_manager();
        $rm->delete_ratings($delopt);
    }
    // Delete cached RSS feeds.
    if (!empty($CFG->enablerssfeeds)) {
        require_once $CFG->dirroot . '/mod/glossary/rsslib.php';
        glossary_rss_delete_file($glossary);
    }
    $event = \mod_glossary\event\entry_deleted::create(array('context' => $context, 'objectid' => $origentry->id, 'other' => array('mode' => $prevmode, 'hook' => $hook, 'concept' => $origentry->concept)));
    $event->add_record_snapshot('glossary_entries', $origentry);
    $event->trigger();
    // Reset caches.
    if ($entry->usedynalink and $entry->approved) {
        \mod_glossary\local\concept_cache::reset_glossary($glossary);
    }
    redirect("view.php?id={$cm->id}&mode={$prevmode}&hook={$hook}");
} else {
    // the operation has not been confirmed yet so ask the user to do so
    $PAGE->navbar->add(get_string('delete'));
    $PAGE->set_title($glossary->name);
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
    $areyousure = "<b>" . format_string($entry->concept) . "</b><p>{$strareyousuredelete}</p>";
    $linkyes = 'deleteentry.php';