See Release Notes
Long Term Support Release
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 namespace qbank_managecategories; 18 19 use moodle_url; 20 21 /** 22 * An item in a list of question categories. 23 * 24 * @package qbank_managecategories 25 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 class question_category_list_item extends \list_item { 29 30 /** 31 * Override set_icon_html function. 32 * 33 * @param bool $first Is the first on the list. 34 * @param bool $last Is the last on the list. 35 * @param \list_item $lastitem Last item. 36 */ 37 public function set_icon_html($first, $last, $lastitem) : void { 38 global $CFG; 39 $category = $this->item; 40 $url = new moodle_url('/question/bank/managecategories/category.php', 41 ($this->parentlist->pageurl->params() + ['edit' => $category->id])); 42 $this->icons['edit'] = $this->image_icon(get_string('editthiscategory', 'question'), $url, 'edit'); 43 parent::set_icon_html($first, $last, $lastitem); 44 $toplevel = ($this->parentlist->parentitem === null);// This is a top level item. 45 if (($this->parentlist->nextlist !== null) && $last && $toplevel && (count($this->parentlist->items) > 1)) { 46 $url = new moodle_url($this->parentlist->pageurl, 47 [ 48 'movedowncontext' => $this->id, 49 'tocontext' => $this->parentlist->nextlist->context->id, 50 'sesskey' => sesskey() 51 ] 52 ); 53 $this->icons['down'] = $this->image_icon( 54 get_string('shareincontext', 'question', 55 $this->parentlist->nextlist->context->get_context_name()), $url, 'down'); 56 } 57 if (($this->parentlist->lastlist !== null) && $first && $toplevel && (count($this->parentlist->items) > 1)) { 58 $url = new moodle_url($this->parentlist->pageurl, 59 [ 60 'moveupcontext' => $this->id, 61 'tocontext' => $this->parentlist->lastlist->context->id, 62 'sesskey' => sesskey() 63 ] 64 ); 65 $this->icons['up'] = $this->image_icon( 66 get_string('shareincontext', 'question', 67 $this->parentlist->lastlist->context->get_context_name()), $url, 'up'); 68 } 69 } 70 71 /** 72 * Override item_html function. 73 * 74 * @param array $extraargs 75 * @return string Item html. 76 * @throws \moodle_exception 77 */ 78 public function item_html($extraargs = []) : string { 79 global $PAGE, $OUTPUT; 80 $str = $extraargs['str']; 81 $category = $this->item; 82 83 // Each section adds html to be displayed as part of this list item. 84 $nodeparent = $PAGE->settingsnav->find('questionbank', \navigation_node::TYPE_CONTAINER); 85 86 // The category URL is based on the node action. 87 $questionbankurl = new moodle_url($nodeparent->action->out_omit_querystring(), 88 $this->parentlist->pageurl->params()); 89 $questionbankurl->param('cat', $category->id . ',' . $category->contextid); 90 91 $categoryname = format_string($category->name, true, ['context' => $this->parentlist->context]); 92 $idnumber = null; 93 if ($category->idnumber !== null && $category->idnumber !== '') { 94 $idnumber = $category->idnumber; 95 } 96 $questioncount = ' (' . $category->questioncount . ')'; 97 $categorydesc = format_text($category->info, $category->infoformat, 98 ['context' => $this->parentlist->context, 'noclean' => true]); 99 100 // Don't allow delete if this is the top category, or the last editable category in this context. 101 $deleteurl = null; 102 if ($category->parent && !helper::question_is_only_child_of_top_category_in_context($category->id)) { 103 $deleteurl = new moodle_url($this->parentlist->pageurl, ['delete' => $this->id, 'sesskey' => sesskey()]); 104 } 105 106 // Render each question category. 107 $data = 108 [ 109 'questionbankurl' => $questionbankurl, 110 'categoryname' => $categoryname, 111 'idnumber' => $idnumber, 112 'questioncount' => $questioncount, 113 'categorydesc' => $categorydesc, 114 'deleteurl' => $deleteurl, 115 'deletetitle' => $str->delete 116 ]; 117 118 return $OUTPUT->render_from_template(helper::PLUGINNAME . '/listitem', $data); 119 } 120 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body