Пример #1
0
/**
 * Adds a recycle bin link to the course admin menu.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the tool
 * @param context $context The context of the course
 * @return void|null return null if we don't want to display the node.
 */
function tool_recyclebin_extend_navigation_course($navigation, $course, $context)
{
    global $PAGE;
    // Only add this settings item on non-site course pages.
    if (!$PAGE->course || $PAGE->course->id == SITEID || !\tool_recyclebin\course_bin::is_enabled()) {
        return null;
    }
    $coursebin = new \tool_recyclebin\course_bin($context->instanceid);
    // Check we can view the recycle bin.
    if (!$coursebin->can_view()) {
        return null;
    }
    $url = null;
    $settingnode = null;
    $url = new moodle_url('/admin/tool/recyclebin/index.php', array('contextid' => $context->id));
    // If we are set to auto-hide, check the number of items.
    $autohide = get_config('tool_recyclebin', 'autohide');
    if ($autohide) {
        $items = $coursebin->get_items();
        if (empty($items)) {
            return null;
        }
    }
    // Add the recyclebin link.
    $pluginname = get_string('pluginname', 'tool_recyclebin');
    $node = navigation_node::create($pluginname, $url, navigation_node::NODETYPE_LEAF, 'tool_recyclebin', 'tool_recyclebin', new pix_icon('trash', $pluginname, 'tool_recyclebin'));
    if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
        $node->make_active();
    }
    $navigation->add_node($node);
}
Пример #2
0
 /**
  * Test the cleanup task.
  */
 public function test_cleanup_task()
 {
     global $DB;
     set_config('coursebinexpiry', WEEKSECS, 'tool_recyclebin');
     // Delete the quiz.
     course_delete_module($this->quiz->cmid);
     // Now, run the course module deletion adhoc task.
     phpunit_util::run_all_adhoc_tasks();
     // Set deleted date to the distant past.
     $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
     foreach ($recyclebin->get_items() as $item) {
         $item->timecreated = time() - WEEKSECS;
         $DB->update_record('tool_recyclebin_course', $item);
     }
     // Create another module we are going to delete, but not alter the time it was placed in the recycle bin.
     $book = $this->getDataGenerator()->get_plugin_generator('mod_book')->create_instance(array('course' => $this->course->id));
     course_delete_module($book->cmid);
     // Now, run the course module deletion adhoc task.
     phpunit_util::run_all_adhoc_tasks();
     // Should have 2 items now.
     $this->assertEquals(2, count($recyclebin->get_items()));
     // Execute cleanup task.
     $this->expectOutputRegex("/\\[tool_recyclebin\\] Deleting item '\\d+' from the course recycle bin/");
     $task = new \tool_recyclebin\task\cleanup_course_bin();
     $task->execute();
     // Should only have the book as it was not due to be deleted.
     $items = $recyclebin->get_items();
     $this->assertEquals(1, count($items));
     $deletedbook = reset($items);
     $this->assertEquals($book->name, $deletedbook->name);
 }
Пример #3
0
 /**
  * Test the course bin item restored event.
  */
 public function test_course_bin_item_restored()
 {
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Create the assignment.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $instance = $generator->create_instance(array('course' => $course->id));
     course_delete_module($instance->cmid);
     // Get the item from the recycle bin.
     $rb = new \tool_recyclebin\course_bin($course->id);
     $items = $rb->get_items();
     $item = reset($items);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $rb->restore_item($item);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event contains the expected values.
     $this->assertInstanceOf('\\tooL_recyclebin\\event\\course_bin_item_restored', $event);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertEquals($item->id, $event->objectid);
     $this->assertEventContextNotUsed($event);
 }