Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Contains class core_tag_manage_table 19 * 20 * @package core_tag 21 * @copyright 2015 Marina Glancy 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once($CFG->libdir . '/tablelib.php'); 28 29 /** 30 * Class core_tag_manage_table 31 * 32 * @package core 33 * @copyright 2015 Marina Glancy 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class core_tag_manage_table extends table_sql { 37 38 /** @var int stores the total number of found tags */ 39 public $totalcount = null; 40 41 /** @var int */ 42 protected $tagcollid; 43 44 /** 45 * Constructor 46 * 47 * @param int $tagcollid 48 */ 49 public function __construct($tagcollid) { 50 global $USER, $CFG, $PAGE; 51 parent::__construct('tag-management-list-'.$USER->id); 52 53 $this->tagcollid = $tagcollid; 54 55 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); 56 $page = optional_param('page', 0, PARAM_INT); 57 $filter = optional_param('filter', '', PARAM_NOTAGS); 58 $baseurl = new moodle_url('/tag/manage.php', array('tc' => $tagcollid, 59 'perpage' => $perpage, 'page' => $page, 'filter' => $filter)); 60 61 $tablecolumns = array('select', 'name', 'fullname', 'count', 'flag', 'timemodified', 'isstandard', 'controls'); 62 $tableheaders = array(get_string('select', 'tag'), 63 get_string('name', 'tag'), 64 get_string('owner', 'tag'), 65 get_string('count', 'tag'), 66 get_string('flag', 'tag'), 67 get_string('timemodified', 'tag'), 68 get_string('standardtag', 'tag'), 69 ''); 70 71 $this->define_columns($tablecolumns); 72 $this->define_headers($tableheaders); 73 $this->define_baseurl($baseurl); 74 75 $this->column_class('select', 'mdl-align col-select'); 76 $this->column_class('name', 'col-name'); 77 $this->column_class('owner', 'col-owner'); 78 $this->column_class('count', 'mdl-align col-count'); 79 $this->column_class('flag', 'mdl-align col-flag'); 80 $this->column_class('timemodified', 'col-timemodified'); 81 $this->column_class('isstandard', 'mdl-align col-isstandard'); 82 $this->column_class('controls', 'mdl-align col-controls'); 83 84 $this->sortable(true, 'flag', SORT_DESC); 85 $this->no_sorting('select'); 86 $this->no_sorting('controls'); 87 88 $this->set_attribute('cellspacing', '0'); 89 $this->set_attribute('id', 'tag-management-list'); 90 $this->set_attribute('class', 'admintable generaltable tag-management-table'); 91 92 $totalcount = "SELECT COUNT(tg.id) 93 FROM {tag} tg 94 WHERE tg.tagcollid = :tagcollid"; 95 $params = array('tagcollid' => $this->tagcollid); 96 97 $this->set_count_sql($totalcount, $params); 98 99 $this->set_sql('', '', '', $params); 100 101 $this->collapsible(true); 102 103 $PAGE->requires->js_call_amd('core/tag', 'initManagePage', array()); 104 105 } 106 107 /** 108 * @return string sql to add to where statement. 109 */ 110 function get_sql_where() { 111 $filter = optional_param('filter', '', PARAM_NOTAGS); 112 list($wsql, $wparams) = parent::get_sql_where(); 113 if ($filter !== '') { 114 $wsql .= ($wsql ? ' AND ' : '') . 'tg.name LIKE :tagfilter'; 115 $wparams['tagfilter'] = '%' . $filter . '%'; 116 } 117 return array($wsql, $wparams); 118 } 119 120 /** 121 * Query the db. Store results in the table object for use by build_table. 122 * 123 * @param int $pagesize size of page for paginated displayed table. 124 * @param bool $useinitialsbar do you want to use the initials bar. Bar 125 * will only be used if there is a fullname column defined for the table. 126 */ 127 public function query_db($pagesize, $useinitialsbar = true) { 128 global $DB; 129 $where = ''; 130 if (!$this->is_downloading()) { 131 $grandtotal = $DB->count_records_sql($this->countsql, $this->countparams); 132 133 list($wsql, $wparams) = $this->get_sql_where(); 134 if ($wsql) { 135 $this->countsql .= ' AND '.$wsql; 136 $this->countparams = array_merge($this->countparams, $wparams); 137 138 $where .= ' AND '.$wsql; 139 $this->sql->params = array_merge($this->sql->params, $wparams); 140 141 $total = $DB->count_records_sql($this->countsql, $this->countparams); 142 } else { 143 $total = $grandtotal; 144 } 145 146 $this->pagesize(min($pagesize, $total), $total); 147 $this->totalcount = $total; 148 } 149 150 // Fetch the attempts. 151 $sort = $this->get_sql_sort(); 152 if ($sort) { 153 $sort .= ", tg.name"; 154 } else { 155 $sort = "tg.name"; 156 } 157 158 $allusernames = get_all_user_name_fields(true, 'u'); 159 $sql = " 160 SELECT tg.id, tg.name, tg.rawname, tg.isstandard, tg.flag, tg.timemodified, 161 u.id AS owner, $allusernames, 162 COUNT(ti.id) AS count, tg.tagcollid 163 FROM {tag} tg 164 LEFT JOIN {tag_instance} ti ON ti.tagid = tg.id 165 LEFT JOIN {user} u ON u.id = tg.userid 166 WHERE tagcollid = :tagcollid $where 167 GROUP BY tg.id, tg.name, tg.rawname, tg.isstandard, tg.flag, tg.timemodified, 168 u.id, $allusernames, tg.tagcollid 169 ORDER BY $sort"; 170 171 if (!$this->is_downloading()) { 172 $this->rawdata = $DB->get_records_sql($sql, $this->sql->params, $this->get_page_start(), $this->get_page_size()); 173 } else { 174 $this->rawdata = $DB->get_records_sql($sql, $this->sql->params); 175 } 176 } 177 178 /** 179 * Get any extra classes names to add to this row in the HTML 180 * 181 * @param stdClass $row array the data for this row. 182 * @return string added to the class="" attribute of the tr. 183 */ 184 public function get_row_class($row) { 185 return $row->flag ? 'flagged-tag' : ''; 186 } 187 188 /** 189 * Column name 190 * 191 * @param stdClass $tag 192 * @return string 193 */ 194 public function col_name($tag) { 195 global $OUTPUT; 196 $tagoutput = new core_tag\output\tagname($tag); 197 return $tagoutput->render($OUTPUT); 198 } 199 200 /** 201 * Column flag 202 * 203 * @param stdClass $tag 204 * @return string 205 */ 206 public function col_flag($tag) { 207 global $OUTPUT; 208 $tagoutput = new core_tag\output\tagflag($tag); 209 return $tagoutput->render($OUTPUT); 210 } 211 212 /** 213 * Column fullname (user name) 214 * 215 * @param stdClass $tag 216 * @return string 217 */ 218 public function col_fullname($tag) { 219 $params = array('id' => $tag->owner); 220 $ownerlink = new moodle_url('/user/view.php', $params); 221 $owner = html_writer::link($ownerlink, fullname($tag)); 222 return $owner; 223 } 224 225 /** 226 * Column time modified 227 * 228 * @param stdClass $tag 229 * @return string 230 */ 231 public function col_timemodified($tag) { 232 return format_time(time() - $tag->timemodified); 233 } 234 235 /** 236 * Column tag type 237 * 238 * @param stdClass $tag 239 * @return string 240 */ 241 public function col_isstandard($tag) { 242 global $OUTPUT; 243 $tagoutput = new core_tag\output\tagisstandard($tag); 244 return $tagoutput->render($OUTPUT); 245 } 246 247 /** 248 * Column select 249 * 250 * @param stdClass $tag 251 * @return string 252 */ 253 public function col_select($tag) { 254 $id = "tagselect" . $tag->id; 255 return html_writer::label(get_string('selecttag', 'tag', $tag->rawname), $id, 256 false, array('class' => 'accesshide')). 257 html_writer::empty_tag('input', array('type' => 'checkbox', 258 'name' => 'tagschecked[]', 'value' => $tag->id, 'id' => $id)); 259 } 260 261 /** 262 * Column controls 263 * 264 * @param stdClass $tag 265 * @return string 266 */ 267 public function col_controls($tag) { 268 global $OUTPUT, $PAGE; 269 $o = ''; 270 // Edit. 271 $url = new moodle_url('/tag/edit.php', array('id' => $tag->id, 'returnurl' => $PAGE->url->out_as_local_url())); 272 $o .= $OUTPUT->action_icon($url, new pix_icon('t/edit', get_string('edittag', 'tag'))); 273 // Delete. 274 $url = new moodle_url($this->baseurl, array('action' => 'delete', 275 'tagid' => $tag->id, 'sesskey' => sesskey())); 276 $o .= $OUTPUT->action_icon($url, new pix_icon('t/delete', get_string('delete', 'tag')), 277 null, array('class' => 'action-icon tagdelete')); 278 return $o; 279 } 280 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body