Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 * Provides {@link tool_policy\output\renderer} class. 19 * 20 * @package tool_policy 21 * @category output 22 * @copyright 2018 Sara Arjona <sara@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace tool_policy\output; 27 28 use moodle_exception; 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 require_once("$CFG->libdir/filelib.php"); 33 34 use context_system; 35 use moodle_url; 36 use renderable; 37 use renderer_base; 38 use single_button; 39 use templatable; 40 use tool_policy\api; 41 use tool_policy\policy_version; 42 43 /** 44 * Represents a page for showing all the policy documents with a current version. 45 * 46 * @copyright 2018 Sara Arjona <sara@moodle.com> 47 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 48 */ 49 class page_viewalldoc implements renderable, templatable { 50 51 /** @var string Return url */ 52 private $returnurl; 53 54 /** 55 * Prepare the page for rendering. 56 * 57 */ 58 public function __construct($returnurl) { 59 $this->returnurl = $returnurl; 60 $this->prepare_global_page_access(); 61 $this->prepare_policies(); 62 } 63 64 /** 65 * Loads the policy versions to display on the page. 66 * 67 */ 68 protected function prepare_policies() { 69 $this->policies = api::list_current_versions(); 70 } 71 72 /** 73 * Sets up the global $PAGE and performs the access checks. 74 */ 75 protected function prepare_global_page_access() { 76 global $PAGE, $SITE, $USER; 77 78 $myurl = new moodle_url('/admin/tool/policy/viewall.php', []); 79 80 // Disable notifications for new users, guests or users who haven't agreed to the policies. 81 if (isguestuser() || empty($USER->id) || !$USER->policyagreed) { 82 $PAGE->set_popup_notification_allowed(false); 83 } 84 85 $PAGE->set_context(context_system::instance()); 86 $PAGE->set_pagelayout('popup'); 87 $PAGE->set_url($myurl); 88 $PAGE->set_heading($SITE->fullname); 89 $PAGE->set_title(get_string('policiesagreements', 'tool_policy')); 90 } 91 92 /** 93 * Export the page data for the mustache template. 94 * 95 * @param renderer_base $output renderer to be used to render the page elements. 96 * @return stdClass 97 */ 98 public function export_for_template(renderer_base $output) { 99 100 $data = (object) [ 101 'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false), 102 ]; 103 104 $data->policies = array_values($this->policies); 105 if (!empty($this->returnurl)) { 106 $data->returnurl = $this->returnurl; 107 } 108 109 array_walk($data->policies, function($item, $key) { 110 $item->policytypestr = get_string('policydoctype'.$item->type, 'tool_policy'); 111 $item->policyaudiencestr = get_string('policydocaudience'.$item->audience, 'tool_policy'); 112 }); 113 114 return $data; 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body