Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 namespace mod_data\output; 18 19 use moodle_url; 20 use templatable; 21 use renderable; 22 23 /** 24 * Renderable class for the action bar elements in the view pages in the database activity. 25 * 26 * @package mod_data 27 * @copyright 2021 Mihail Geshoski <mihail@moodle.com> 28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 */ 30 class view_action_bar implements templatable, renderable { 31 32 /** @var int $id The database module id. */ 33 private $id; 34 35 /** @var \url_select $urlselect The URL selector object. */ 36 private $urlselect; 37 38 /** @var bool $hasentries Whether entries exist. */ 39 private $hasentries; 40 41 /** 42 * The class constructor. 43 * 44 * @param int $id The database module id. 45 * @param \url_select $urlselect The URL selector object. 46 * @param bool $hasentries Whether entries exist. 47 */ 48 public function __construct(int $id, \url_select $urlselect, bool $hasentries) { 49 $this->id = $id; 50 $this->urlselect = $urlselect; 51 $this->hasentries = $hasentries; 52 } 53 54 /** 55 * Export the data for the mustache template. 56 * 57 * @param \renderer_base $output The renderer to be used to render the action bar elements. 58 * @return array 59 */ 60 public function export_for_template(\renderer_base $output): array { 61 global $PAGE, $DB; 62 63 $data = [ 64 'urlselect' => $this->urlselect->export_for_template($output), 65 ]; 66 67 $database = $DB->get_record('data', ['id' => $this->id]); 68 $cm = get_coursemodule_from_instance('data', $this->id); 69 $currentgroup = groups_get_activity_group($cm); 70 $groupmode = groups_get_activity_groupmode($cm); 71 72 if (data_user_can_add_entry($database, $currentgroup, $groupmode, $PAGE->context)) { 73 $addentrylink = new moodle_url('/mod/data/edit.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]); 74 $addentrybutton = new \single_button($addentrylink, get_string('add', 'mod_data'), 'get', true); 75 $data['addentrybutton'] = $addentrybutton->export_for_template($output); 76 } 77 78 if (has_capability('mod/data:manageentries', $PAGE->context)) { 79 $importentrieslink = new moodle_url('/mod/data/import.php', 80 ['d' => $this->id, 'backto' => $PAGE->url->out(false)]); 81 $importentriesbutton = new \single_button($importentrieslink, 82 get_string('importentries', 'mod_data'), 'get', false); 83 $data['importentriesbutton'] = $importentriesbutton->export_for_template($output); 84 } 85 86 if (has_capability(DATA_CAP_EXPORT, $PAGE->context) && $this->hasentries) { 87 $exportentrieslink = new moodle_url('/mod/data/export.php', 88 ['d' => $this->id, 'backto' => $PAGE->url->out(false)]); 89 $exportentriesbutton = new \single_button($exportentrieslink, get_string('exportentries', 'mod_data'), 90 'get', false); 91 $data['exportentriesbutton'] = $exportentriesbutton->export_for_template($output); 92 } 93 94 return $data; 95 } 96 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body