1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Local lib code 19 * 20 * @package tool_recyclebin 21 * @copyright 2015 Skylar Kelty <S.Kelty@kent.ac.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die; 26 27 /** 28 * Adds a recycle bin link to the course admin menu. 29 * 30 * @param navigation_node $navigation The navigation node to extend 31 * @param stdClass $course The course to object for the tool 32 * @param context $context The context of the course 33 * @return void|null return null if we don't want to display the node. 34 */ 35 function tool_recyclebin_extend_navigation_course($navigation, $course, $context) { 36 global $PAGE; 37 38 // Only add this settings item on non-site course pages. 39 if (!$PAGE->course || $PAGE->course->id == SITEID || !\tool_recyclebin\course_bin::is_enabled()) { 40 return null; 41 } 42 43 $coursebin = new \tool_recyclebin\course_bin($context->instanceid); 44 45 // Check we can view the recycle bin. 46 if (!$coursebin->can_view()) { 47 return null; 48 } 49 50 $url = null; 51 $settingnode = null; 52 53 $url = new moodle_url('/admin/tool/recyclebin/index.php', array( 54 'contextid' => $context->id 55 )); 56 57 // If we are set to auto-hide, check the number of items. 58 $autohide = get_config('tool_recyclebin', 'autohide'); 59 if ($autohide) { 60 $items = $coursebin->get_items(); 61 if (empty($items)) { 62 return null; 63 } 64 } 65 66 // Add the recyclebin link. 67 $pluginname = get_string('pluginname', 'tool_recyclebin'); 68 69 $node = navigation_node::create( 70 $pluginname, 71 $url, 72 navigation_node::NODETYPE_LEAF, 73 'tool_recyclebin', 74 'tool_recyclebin', 75 new pix_icon('trash', $pluginname, 'tool_recyclebin') 76 ); 77 78 if ($PAGE->url->compare($url, URL_MATCH_BASE)) { 79 $node->make_active(); 80 } 81 82 $navigation->add_node($node); 83 } 84 85 /** 86 * Adds a recycle bin link to the course admin menu. 87 * 88 * @param navigation_node $navigation The navigation node to extend 89 * @param context $context The context of the course 90 * @return void|null return null if we don't want to display the node. 91 */ 92 function tool_recyclebin_extend_navigation_category_settings($navigation, $context) { 93 global $PAGE; 94 95 // Check if it is enabled. 96 if (!\tool_recyclebin\category_bin::is_enabled()) { 97 return null; 98 } 99 100 $categorybin = new \tool_recyclebin\category_bin($context->instanceid); 101 102 // Check we can view the recycle bin. 103 if (!$categorybin->can_view()) { 104 return null; 105 } 106 107 $url = null; 108 $settingnode = null; 109 110 // Add a link to the category recyclebin. 111 $url = new moodle_url('/admin/tool/recyclebin/index.php', array( 112 'contextid' => $context->id 113 )); 114 115 // If we are set to auto-hide, check the number of items. 116 $autohide = get_config('tool_recyclebin', 'autohide'); 117 if ($autohide) { 118 $items = $categorybin->get_items(); 119 if (empty($items)) { 120 return null; 121 } 122 } 123 124 // Add the recyclebin link. 125 $pluginname = get_string('pluginname', 'tool_recyclebin'); 126 127 $node = navigation_node::create( 128 $pluginname, 129 $url, 130 navigation_node::NODETYPE_LEAF, 131 'tool_recyclebin', 132 'tool_recyclebin', 133 new pix_icon('trash', $pluginname, 'tool_recyclebin') 134 ); 135 136 if ($PAGE->url->compare($url, URL_MATCH_BASE)) { 137 $node->make_active(); 138 } 139 140 $navigation->add_node($node); 141 } 142 143 /** 144 * Hook called before we delete a course module. 145 * 146 * @param \stdClass $cm The course module record. 147 */ 148 function tool_recyclebin_pre_course_module_delete($cm) { 149 if (\tool_recyclebin\course_bin::is_enabled()) { 150 $coursebin = new \tool_recyclebin\course_bin($cm->course); 151 $coursebin->store_item($cm); 152 } 153 } 154 155 /** 156 * Hook called to check whether async course module deletion should be performed or not. 157 * 158 * @return true if background deletion is required (is the recyclebin is enabled), false otherwise. 159 */ 160 function tool_recyclebin_course_module_background_deletion_recommended() { 161 if (\tool_recyclebin\course_bin::is_enabled()) { 162 return true; 163 } 164 } 165 166 /** 167 * Hook called before we delete a course. 168 * 169 * @param \stdClass $course The course record. 170 */ 171 function tool_recyclebin_pre_course_delete($course) { 172 // It is possible that the course deletion which triggered this hook 173 // was from an in progress course restore. In that case we do not want 174 // it in the recycle bin. 175 if (isset($course->deletesource) && $course->deletesource == 'restore') { 176 return; 177 } 178 // Delete all the items in the course recycle bin, regardless if it enabled or not. 179 // It may have been enabled, then disabled later on, so may still have content. 180 $coursebin = new \tool_recyclebin\course_bin($course->id); 181 $coursebin->delete_all_items(); 182 183 if (\tool_recyclebin\category_bin::is_enabled()) { 184 $categorybin = new \tool_recyclebin\category_bin($course->category); 185 $categorybin->store_item($course); 186 } 187 } 188 189 /** 190 * Hook called before we delete a category. 191 * 192 * @param \stdClass $category The category record. 193 */ 194 function tool_recyclebin_pre_course_category_delete($category) { 195 // Delete all the items in the category recycle bin, regardless if it enabled or not. 196 // It may have been enabled, then disabled later on, so may still have content. 197 $categorybin = new \tool_recyclebin\category_bin($category->id); 198 $categorybin->delete_all_items(); 199 } 200 201 /** 202 * Map icons for font-awesome themes. 203 */ 204 function tool_recyclebin_get_fontawesome_icon_map() { 205 return [ 206 'tool_recyclebin:trash' => 'fa-trash' 207 ]; 208 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body