Ejemplo n.º 1
0
$PAGE->set_url('/admin/tool/recyclebin/index.php', array('contextid' => $contextid));
$PAGE->set_title(get_string('pluginname', 'tool_recyclebin'));
// If we are doing anything, we need a sesskey!
if (!empty($action)) {
    raise_memory_limit(MEMORY_EXTRA);
    require_sesskey();
    $item = null;
    if ($action == 'restore' || $action == 'delete') {
        $itemid = required_param('itemid', PARAM_INT);
        $item = $recyclebin->get_item($itemid);
    }
    switch ($action) {
        // Restore it.
        case 'restore':
            if ($recyclebin->can_restore()) {
                $recyclebin->restore_item($item);
                redirect($PAGE->url, get_string('alertrestored', 'tool_recyclebin', $item), 2);
            } else {
                print_error('nopermissions', 'error');
            }
            break;
            // Delete it.
        // Delete it.
        case 'delete':
            if ($recyclebin->can_delete()) {
                $recyclebin->delete_item($item);
                redirect($PAGE->url, get_string('alertdeleted', 'tool_recyclebin', $item), 2);
            } else {
                print_error('nopermissions', 'error');
            }
            break;
Ejemplo n.º 2
0
 /**
  * Test that we can restore recycle bin items.
  */
 public function test_restore()
 {
     global $DB;
     delete_course($this->course, false);
     $recyclebin = new \tool_recyclebin\category_bin($this->course->category);
     foreach ($recyclebin->get_items() as $item) {
         $recyclebin->restore_item($item);
     }
     // Check that it was restored and removed from the recycle bin.
     $this->assertEquals(2, $DB->count_records('course'));
     // Site course and the course we restored.
     $this->assertEquals(0, count($recyclebin->get_items()));
 }
Ejemplo n.º 3
0
 /**
  * Test the category bin item restored event.
  */
 public function test_category_bin_item_restored()
 {
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Delete the course.
     delete_course($course, false);
     // Get the item from the recycle bin.
     $rb = new \tool_recyclebin\category_bin($course->category);
     $items = $rb->get_items();
     $item = reset($items);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $rb->restore_item($item);
     $events = $sink->get_events();
     $event = $events[6];
     // Check that the event contains the expected values.
     $this->assertInstanceOf('\\tooL_recyclebin\\event\\category_bin_item_restored', $event);
     $this->assertEquals(context_coursecat::instance($course->category), $event->get_context());
     $this->assertEquals($item->id, $event->objectid);
     $this->assertEventContextNotUsed($event);
 }