Skip to content

Commit

Permalink
Fix up new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-unikent committed Aug 26, 2015
1 parent 25db206 commit b0041d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
27 changes: 25 additions & 2 deletions classes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,38 @@ public function __construct($categoryid) {
$this->_categoryid = $categoryid;
}

/**
* Returns an item from the recycle bin.
*
* @param $item int Item ID to retrieve.
*/
public function get_item($itemid) {
global $DB;

$item = $DB->get_record('local_recyclebin_category', array(
'id' => $itemid
), '*', MUST_EXIST);

$item->name = get_course_display_name_for_list($item);

return $item;
}

/**
* Returns a list of items in the recycle bin for this course.
*/
public function get_items() {
global $DB;

return $DB->get_records('local_recyclebin_category', array(
$items = $DB->get_records('local_recyclebin_category', array(
'category' => $this->_categoryid
));

foreach ($items as $item) {
$item->name = get_course_display_name_for_list($item);
}

return $items;
}

/**
Expand Down Expand Up @@ -241,7 +264,7 @@ public function delete_item($item, $noevent = false) {
// Fire event.
$event = \local_recyclebin\event\course_purged::create(array(
'objectid' => $item->id,
'context' => \context_course::instance($item->course)
'context' => \context_coursecat::instance($item->category)
));
$event->add_record_snapshot('local_recyclebin_category', $item);
$event->trigger();
Expand Down
13 changes: 13 additions & 0 deletions classes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public function __construct($courseid) {
$this->_courseid = $courseid;
}

/**
* Returns an item from the recycle bin.
*
* @param $item int Item ID to retrieve.
*/
public function get_item($itemid) {
global $DB;

return $DB->get_record('local_recyclebin_course', array(
'id' => $itemid
), '*', MUST_EXIST);
}

/**
* Returns a list of items in the recycle bin for this course.
*/
Expand Down
9 changes: 8 additions & 1 deletion classes/recyclebin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@
abstract class recyclebin
{
/**
* Returns a list of items in the recycle bin for this course.
* Returns an item from the recycle bin.
*
* @param $item int Item ID to retrieve.
*/
public abstract function get_item($itemid);

/**
* Returns a list of items in the recycle bin.
*/
public abstract function get_items();

Expand Down
9 changes: 2 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@
$item = null;
if ($action == 'restore' || $action == 'delete') {
$itemid = required_param('itemid', PARAM_INT);
$item = $DB->get_record('local_recyclebin_course', array(
'id' => $itemid
), '*', MUST_EXIST);
$item = $recyclebin->get_item($itemid);
}

switch ($action) {
Expand Down Expand Up @@ -185,16 +183,13 @@
$row = array();

// Build item name.
$name = '';
$name = $item->name;
if ($context->contextlevel == \CONTEXT_COURSE) {
$name = $item->name;
if (isset($modules[$item->module])) {
$mod = $modules[$item->module];
$modname = get_string('modulename', $mod->name);
$name = '<img src="' . $OUTPUT->pix_url('icon', $mod->name) . '" class="icon" alt="' . $modname . '" /> ' . $name;
}
} else {
$name = get_course_display_name_for_list($item);
}

$row[] = $name;
Expand Down

0 comments on commit b0041d0

Please sign in to comment.