Commit | Line | Data |
---|---|---|
9ac2e865 RW |
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 | * Class containing data for my overview block. | |
19 | * | |
20 | * @package block_myoverview | |
21 | * @copyright 2017 Ryan Wyllie <ryan@moodle.com> | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | namespace block_myoverview\output; | |
25 | defined('MOODLE_INTERNAL') || die(); | |
26 | ||
27 | use renderable; | |
28 | use renderer_base; | |
29 | use templatable; | |
3f0c421b | 30 | |
3cfff885 | 31 | require_once($CFG->dirroot . '/blocks/myoverview/lib.php'); |
c5515a34 | 32 | |
9ac2e865 RW |
33 | /** |
34 | * Class containing data for my overview block. | |
35 | * | |
e4b4b9e7 | 36 | * @copyright 2018 Bas Brands <bas@moodle.com> |
9ac2e865 RW |
37 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
38 | */ | |
39 | class main implements renderable, templatable { | |
3cfff885 BB |
40 | |
41 | /** | |
42 | * Store the grouping preference | |
43 | * | |
44 | * @var string String matching the grouping constants defined in myoverview/lib.php | |
45 | */ | |
46 | private $grouping; | |
47 | ||
48 | /** | |
49 | * Store the sort preference | |
50 | * | |
51 | * @var string String matching the sort constants defined in myoverview/lib.php | |
52 | */ | |
53 | private $sort; | |
54 | ||
55 | /** | |
56 | * Store the view preference | |
57 | * | |
58 | * @var string String matching the view/display constants defined in myoverview/lib.php | |
59 | */ | |
60 | private $view; | |
61 | ||
11988d74 P |
62 | /** |
63 | * Store the paging preference | |
64 | * | |
65 | * @var string String matching the paging constants defined in myoverview/lib.php | |
66 | */ | |
67 | private $paging; | |
68 | ||
3cfff885 BB |
69 | /** |
70 | * main constructor. | |
71 | * Initialize the user preferences | |
72 | * | |
73 | * @param string $grouping Grouping user preference | |
74 | * @param string $sort Sort user preference | |
75 | * @param string $view Display user preference | |
76 | */ | |
11988d74 | 77 | public function __construct($grouping, $sort, $view, $paging) { |
3cfff885 BB |
78 | $this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL; |
79 | $this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE; | |
80 | $this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD; | |
11988d74 | 81 | $this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12; |
3cfff885 BB |
82 | } |
83 | ||
84 | /** | |
85 | * Get the user preferences as an array to figure out what has been selected | |
86 | * | |
87 | * @return array $preferences Array with the pref as key and value set to true | |
88 | */ | |
89 | public function get_preferences_as_booleans() { | |
90 | $preferences = []; | |
91 | $preferences[$this->view] = true; | |
92 | $preferences[$this->sort] = true; | |
93 | $preferences[$this->grouping] = true; | |
94 | ||
95 | return $preferences; | |
96 | } | |
97 | ||
9ac2e865 RW |
98 | /** |
99 | * Export this data so it can be used as the context for a mustache template. | |
100 | * | |
101 | * @param \renderer_base $output | |
3cfff885 | 102 | * @return array Context variables for the template |
9ac2e865 RW |
103 | */ |
104 | public function export_for_template(renderer_base $output) { | |
4a995a1f | 105 | |
01a95b86 | 106 | $nocoursesurl = $output->image_url('courses', 'block_myoverview')->out(); |
9ac2e865 | 107 | |
3cfff885 BB |
108 | $defaultvariables = [ |
109 | 'nocoursesimg' => $nocoursesurl, | |
110 | 'grouping' => $this->grouping, | |
111 | 'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc', | |
11988d74 P |
112 | 'view' => $this->view, |
113 | 'paging' => $this->paging | |
9ac2e865 | 114 | ]; |
3cfff885 BB |
115 | |
116 | $preferences = $this->get_preferences_as_booleans(); | |
117 | return array_merge($defaultvariables, $preferences); | |
118 | ||
9ac2e865 | 119 | } |
3cfff885 | 120 | } |