[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 before we delete a course. 157 * 158 * @param \stdClass $course The course record. 159 */ 160 function tool_recyclebin_pre_course_delete($course) { 161 // It is possible that the course deletion which triggered this hook 162 // was from an in progress course restore. In that case we do not want 163 // it in the recycle bin. 164 if (isset($course->deletesource) && $course->deletesource == 'restore') { 165 return; 166 } 167 // Delete all the items in the course recycle bin, regardless if it enabled or not. 168 // It may have been enabled, then disabled later on, so may still have content. 169 $coursebin = new \tool_recyclebin\course_bin($course->id); 170 $coursebin->delete_all_items(); 171 172 if (\tool_recyclebin\category_bin::is_enabled()) { 173 $categorybin = new \tool_recyclebin\category_bin($course->category); 174 $categorybin->store_item($course); 175 } 176 } 177 178 /** 179 * Hook called before we delete a category. 180 * 181 * @param \stdClass $category The category record. 182 */ 183 function tool_recyclebin_pre_course_category_delete($category) { 184 // Delete all the items in the category recycle bin, regardless if it enabled or not. 185 // It may have been enabled, then disabled later on, so may still have content. 186 $categorybin = new \tool_recyclebin\category_bin($category->id); 187 $categorybin->delete_all_items(); 188 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |