Skip to content

Commit 74a851a

Browse files
committed
wip2
1 parent 8614a91 commit 74a851a

File tree

2 files changed

+294
-0
lines changed

2 files changed

+294
-0
lines changed

classes/table/snippets_overview.php

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
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+
* Theme Boost Union - CSS snippets overview table
19+
*
20+
* @package theme_boost_union
21+
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]>
22+
* @copyright 2024 André Menrath, University of Graz <[email protected]>
23+
* @copyright 2024 Bart den Hoed, Avetica <[email protected]>
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
27+
namespace theme_boost_union\table;
28+
29+
defined('MOODLE_INTERNAL') || die();
30+
31+
// Require table library.
32+
require_once($CFG->libdir.'/tablelib.php');
33+
34+
/**
35+
* List of CSS snippets.
36+
*
37+
* @package theme_boost_union
38+
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]>
39+
* @copyright 2024 André Menrath, University of Graz <[email protected]>
40+
* @copyright 2024 Bart den Hoed, Avetica <[email protected]>
41+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42+
*/
43+
class snippets_overview extends \table_sql {
44+
// TODO:
45+
/**
46+
* @var int $count Flavours count.
47+
*/
48+
private $count;
49+
50+
/**
51+
* @var int $totalflavours Total flavours count.
52+
*/
53+
private $totalflavours;
54+
55+
/**
56+
* Setup table.
57+
*
58+
* @throws \coding_exception
59+
*/
60+
public function __construct() {
61+
global $DB;
62+
63+
// Call parent constructor.
64+
parent::__construct('flavours');
65+
66+
// Define the headers and columns.
67+
$headers[] = get_string('flavourstitle', 'theme_boost_union');
68+
$headers[] = get_string('flavoursdescription', 'theme_boost_union');
69+
$headers[] = get_string('flavoursappliesto', 'theme_boost_union');
70+
$headers[] = get_string('up') .'/'. get_string('down');
71+
$headers[] = get_string('actions');
72+
$columns[] = 'title';
73+
$columns[] = 'description';
74+
$columns[] = 'appliesto';
75+
$columns[] = 'updown';
76+
$columns[] = 'actions';
77+
$this->sortable(false); // Having a sortable table would be nice, but this would interfere with the up/down feature.
78+
$this->collapsible(false);
79+
$this->pageable(false); // Having a pageable table would be nice, but we will keep it simple for now.
80+
$this->define_columns($columns);
81+
$this->define_headers($headers);
82+
$this->define_header_column('title');
83+
84+
// Initialize values for the updown feature.
85+
$this->count = 0;
86+
$this->totalflavours = $DB->count_records('theme_boost_union_flavours');
87+
}
88+
89+
/**
90+
* Updown column.
91+
*
92+
* @param \stdClass $data
93+
* @return mixed
94+
*/
95+
public function col_updown($data) {
96+
global $OUTPUT;
97+
98+
// Prepare action URL.
99+
$actionurl = new \moodle_url('/theme/boost_union/flavours/overview.php');
100+
101+
// Initialize column value.
102+
$updown = '';
103+
104+
// Get spacer icon.
105+
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', ['class' => 'iconsmall']);
106+
107+
// If there is more than one flavour and we do not handle the first (number 0) flavour.
108+
if ($this->count > 0) {
109+
// Add the up icon.
110+
$updown .= \html_writer::link($actionurl->out(false,
111+
['action' => 'up', 'id' => $data->id, 'sesskey' => sesskey()]),
112+
$OUTPUT->pix_icon('t/up', get_string('up'), 'moodle',
113+
['class' => 'iconsmall']), ['class' => 'sort-flavour-up-action']);
114+
115+
// Otherwise, just add a spacer.
116+
} else {
117+
$updown .= $spacer;
118+
}
119+
120+
// If there is more than one flavour and we do not handle the last flavour.
121+
if ($this->count < ($this->totalflavours - 1)) {
122+
// Add the down icon.
123+
$updown .= '&nbsp;';
124+
$updown .= \html_writer::link($actionurl->out(false,
125+
['action' => 'down', 'id' => $data->id, 'sesskey' => sesskey()]),
126+
$OUTPUT->pix_icon('t/down', get_string('down'), 'moodle',
127+
['class' => 'iconsmall']), ['class' => 'sort-flavour-down-action']);
128+
129+
// Otherwise, just add a spacer.
130+
} else {
131+
$updown .= $spacer;
132+
}
133+
134+
// Increase the flavour counter.
135+
$this->count++;
136+
137+
// Return the column value.
138+
return $updown;
139+
}
140+
141+
/**
142+
* Applies to column.
143+
*
144+
* @param \stdClass $data
145+
* @return string
146+
*/
147+
public function col_appliesto($data) {
148+
// Initialize the badges.
149+
$badges = [];
150+
151+
// If apply-to-categories is enabled, add a badge.
152+
if ($data->applytocategories == true) {
153+
$badges[] = \html_writer::tag('span',
154+
get_string('categories'),
155+
['class' => 'badge bg-primary text-light']);
156+
}
157+
158+
// If apply-to-cohorts is enabled, add a badge.
159+
if ($data->applytocohorts == true) {
160+
$badges[] = \html_writer::tag('span',
161+
get_string('cohorts', 'cohort'),
162+
['class' => 'badge bg-primary text-light']);
163+
}
164+
165+
// Implode and return the badges.
166+
return implode(' ', $badges);
167+
}
168+
169+
/**
170+
* Actions column.
171+
*
172+
* @param \stdClass $data
173+
* @return string
174+
* @throws \coding_exception
175+
* @throws \moodle_exception
176+
*/
177+
public function col_actions($data) {
178+
global $OUTPUT;
179+
180+
// Initialize actions.
181+
$actions = [];
182+
183+
// Preview.
184+
$actions[] = [
185+
'url' => new \moodle_url('/theme/boost_union/flavours/preview.php', ['id' => $data->id]),
186+
'icon' => new \pix_icon('i/search', get_string('flavoursedit', 'theme_boost_union')),
187+
'attributes' => ['class' => 'action-preview'],
188+
];
189+
190+
// Edit.
191+
$actions[] = [
192+
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
193+
['action' => 'edit', 'id' => $data->id, 'sesskey' => sesskey()]),
194+
'icon' => new \pix_icon('t/edit', get_string('flavoursedit', 'theme_boost_union')),
195+
'attributes' => ['class' => 'action-edit'],
196+
];
197+
198+
// Delete.
199+
$actions[] = [
200+
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
201+
['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
202+
'icon' => new \pix_icon('t/delete', get_string('flavourspreview', 'theme_boost_union')),
203+
'attributes' => ['class' => 'action-delete'],
204+
];
205+
206+
// Compose action icons for all actions.
207+
$actionshtml = [];
208+
foreach ($actions as $action) {
209+
$action['attributes']['role'] = 'button';
210+
$actionshtml[] = $OUTPUT->action_icon(
211+
$action['url'],
212+
$action['icon'],
213+
($action['confirm'] ?? null),
214+
$action['attributes']
215+
);
216+
}
217+
218+
// Return all actions.
219+
return \html_writer::span(join('', $actionshtml), 'flavours-actions');
220+
}
221+
222+
/**
223+
* Get the flavours for the table.
224+
*
225+
* @param int $pagesize
226+
* @param bool $useinitialsbar
227+
* @throws \dml_exception
228+
*/
229+
public function query_db($pagesize, $useinitialsbar = true) {
230+
global $DB;
231+
232+
// Compose SQL base query.
233+
$sql = 'SELECT *
234+
FROM {theme_boost_union_flavours} t
235+
ORDER BY sort';
236+
237+
// Get records.
238+
$this->rawdata = $DB->get_recordset_sql($sql);
239+
}
240+
241+
/**
242+
* Override the message if the table contains no entries.
243+
*/
244+
public function print_nothing_to_display() {
245+
global $OUTPUT;
246+
247+
// Show notification as html element.
248+
$notification = new \core\output\notification(
249+
get_string('flavoursnothingtodisplay', 'theme_boost_union'), \core\output\notification::NOTIFY_INFO);
250+
$notification->set_show_closebutton(false);
251+
echo $OUTPUT->render($notification);
252+
}
253+
254+
}

snippets/builtin/fix_border.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* CSS Snippet for fixing the borders.
19+
*
20+
* @package theme_boost_union
21+
* @copyright 2024 University of Graz
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
class Fix_Border {
26+
27+
public $source;
28+
29+
public $domain;
30+
31+
public $key;
32+
33+
public $title;
34+
35+
public $description;
36+
37+
public $css;
38+
39+
public $enabled;
40+
}

0 commit comments

Comments
 (0)