Skip to content

Commit d54284e

Browse files
committed
Add admin page
1 parent 5206642 commit d54284e

File tree

5 files changed

+220
-66
lines changed

5 files changed

+220
-66
lines changed

classes/table/snippets_overview.php

+66-66
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@
4343
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4444
*/
4545
class snippets_overview extends \table_sql {
46-
// TODO:
4746
/**
48-
* @var int $count Flavours count.
47+
* @var int $count Snippets count.
4948
*/
5049
private $count;
5150

5251
/**
53-
* @var int $totalflavours Total flavours count.
52+
* @var int $totalsnippets Total snippets count.
5453
*/
55-
private $totalflavours;
54+
private $totalsnippets;
5655

5756
/**
5857
* Setup table.
@@ -63,17 +62,19 @@ public function __construct() {
6362
global $DB;
6463

6564
// Call parent constructor.
66-
parent::__construct('flavours');
65+
parent::__construct('snippets');
6766

6867
// Define the headers and columns.
69-
$headers[] = get_string('flavourstitle', 'theme_boost_union');
70-
$headers[] = get_string('flavoursdescription', 'theme_boost_union');
71-
$headers[] = get_string('flavoursappliesto', 'theme_boost_union');
68+
$headers[] = get_string('snippetstitle', 'theme_boost_union');
69+
$headers[] = get_string('snippetsdescription', 'theme_boost_union');
70+
$headers[] = get_string('snippetsscope', 'theme_boost_union');
71+
$headers[] = get_string('snippetsgoal', 'theme_boost_union');
7272
$headers[] = get_string('up') .'/'. get_string('down');
7373
$headers[] = get_string('actions');
7474
$columns[] = 'title';
7575
$columns[] = 'description';
76-
$columns[] = 'appliesto';
76+
$columns[] = 'scope';
77+
$columns[] = 'goal';
7778
$columns[] = 'updown';
7879
$columns[] = 'actions';
7980
$this->sortable(false); // Having a sortable table would be nice, but this would interfere with the up/down feature.
@@ -85,7 +86,7 @@ public function __construct() {
8586

8687
// Initialize values for the updown feature.
8788
$this->count = 0;
88-
$this->totalflavours = $DB->count_records('theme_boost_union_flavours');
89+
$this->totalsnippets = $DB->count_records('theme_boost_union_snippets');
8990
}
9091

9192
/**
@@ -98,74 +99,74 @@ public function col_updown($data) {
9899
global $OUTPUT;
99100

100101
// Prepare action URL.
101-
$actionurl = new \moodle_url('/theme/boost_union/flavours/overview.php');
102+
$actionurl = new \moodle_url('/theme/boost_union/snippets/overview.php');
102103

103104
// Initialize column value.
104105
$updown = '';
105106

106107
// Get spacer icon.
107108
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', ['class' => 'iconsmall']);
108109

109-
// If there is more than one flavour and we do not handle the first (number 0) flavour.
110+
// If there is more than one snippet and we do not handle the first (number 0) snippet.
110111
if ($this->count > 0) {
111112
// Add the up icon.
112113
$updown .= \html_writer::link($actionurl->out(false,
113114
['action' => 'up', 'id' => $data->id, 'sesskey' => sesskey()]),
114115
$OUTPUT->pix_icon('t/up', get_string('up'), 'moodle',
115-
['class' => 'iconsmall']), ['class' => 'sort-flavour-up-action']);
116+
['class' => 'iconsmall']), ['class' => 'sort-snippet-up-action']);
116117

117118
// Otherwise, just add a spacer.
118119
} else {
119120
$updown .= $spacer;
120121
}
121122

122-
// If there is more than one flavour and we do not handle the last flavour.
123-
if ($this->count < ($this->totalflavours - 1)) {
123+
// If there is more than one snippet and we do not handle the last snippet.
124+
if ($this->count < ($this->totalsnippets - 1)) {
124125
// Add the down icon.
125126
$updown .= '&nbsp;';
126127
$updown .= \html_writer::link($actionurl->out(false,
127128
['action' => 'down', 'id' => $data->id, 'sesskey' => sesskey()]),
128129
$OUTPUT->pix_icon('t/down', get_string('down'), 'moodle',
129-
['class' => 'iconsmall']), ['class' => 'sort-flavour-down-action']);
130+
['class' => 'iconsmall']), ['class' => 'sort-snippet-down-action']);
130131

131132
// Otherwise, just add a spacer.
132133
} else {
133134
$updown .= $spacer;
134135
}
135136

136-
// Increase the flavour counter.
137+
// Increase the snippet counter.
137138
$this->count++;
138139

139140
// Return the column value.
140141
return $updown;
141142
}
142143

143144
/**
144-
* Applies to column.
145+
* Scope column.
145146
*
146147
* @param \stdClass $data
147-
* @return string
148+
* @return mixed
148149
*/
149-
public function col_appliesto($data) {
150-
// Initialize the badges.
151-
$badges = [];
152-
153-
// If apply-to-categories is enabled, add a badge.
154-
if ($data->applytocategories == true) {
155-
$badges[] = \html_writer::tag('span',
156-
get_string('categories'),
157-
['class' => 'badge bg-primary text-light']);
158-
}
150+
public function col_scope($data) {
151+
// Get the string for the given scope from the language pack.
152+
$string = get_string('snippetsscope'.$data->scope, 'theme_boost_union');
159153

160-
// If apply-to-cohorts is enabled, add a badge.
161-
if ($data->applytocohorts == true) {
162-
$badges[] = \html_writer::tag('span',
163-
get_string('cohorts', 'cohort'),
164-
['class' => 'badge bg-primary text-light']);
165-
}
154+
// Output Bootstrap label.
155+
return \html_writer::tag('span', $string, ['class' => 'badge bg-primary text-light']);
156+
}
166157

167-
// Implode and return the badges.
168-
return implode(' ', $badges);
158+
/**
159+
* Goal column.
160+
*
161+
* @param \stdClass $data
162+
* @return mixed
163+
*/
164+
public function col_goal($data) {
165+
// Get the string for the given goal from the language pack.
166+
$string = get_string('snippetsgoal'.$data->goal, 'theme_boost_union');
167+
168+
// Output Bootstrap label.
169+
return \html_writer::tag('span', $string, ['class' => 'badge bg-primary text-light']);
169170
}
170171

171172
/**
@@ -182,28 +183,22 @@ public function col_actions($data) {
182183
// Initialize actions.
183184
$actions = [];
184185

185-
// Preview.
186-
$actions[] = [
187-
'url' => new \moodle_url('/theme/boost_union/flavours/preview.php', ['id' => $data->id]),
188-
'icon' => new \pix_icon('i/search', get_string('flavoursedit', 'theme_boost_union')),
189-
'attributes' => ['class' => 'action-preview'],
190-
];
191-
192-
// Edit.
193-
$actions[] = [
194-
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
195-
['action' => 'edit', 'id' => $data->id, 'sesskey' => sesskey()]),
196-
'icon' => new \pix_icon('t/edit', get_string('flavoursedit', 'theme_boost_union')),
197-
'attributes' => ['class' => 'action-edit'],
198-
];
199-
200-
// Delete.
201-
$actions[] = [
202-
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
203-
['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
204-
'icon' => new \pix_icon('t/delete', get_string('flavourspreview', 'theme_boost_union')),
205-
'attributes' => ['class' => 'action-delete'],
206-
];
186+
// Enable/Disable.
187+
if ($data->enabled == false) {
188+
$actions[] = [
189+
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php',
190+
['action' => 'enable', 'id' => $data->id, 'sesskey' => sesskey()]),
191+
'icon' => new \pix_icon('t/hide', get_string('snippetsenable', 'theme_boost_union')),
192+
'attributes' => ['class' => 'action-enable'],
193+
];
194+
} else {
195+
$actions[] = [
196+
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php',
197+
['action' => 'disable', 'id' => $data->id, 'sesskey' => sesskey()]),
198+
'icon' => new \pix_icon('t/show', get_string('snippetsdisable', 'theme_boost_union')),
199+
'attributes' => ['class' => 'action-disable'],
200+
];
201+
}
207202

208203
// Compose action icons for all actions.
209204
$actionshtml = [];
@@ -218,11 +213,11 @@ public function col_actions($data) {
218213
}
219214

220215
// Return all actions.
221-
return \html_writer::span(join('', $actionshtml), 'flavours-actions');
216+
return \html_writer::span(join('', $actionshtml), 'snippets-actions');
222217
}
223218

224219
/**
225-
* Get the flavours for the table.
220+
* Get the snippets for the table.
226221
*
227222
* @param int $pagesize
228223
* @param bool $useinitialsbar
@@ -233,13 +228,19 @@ public function query_db($pagesize, $useinitialsbar = true) {
233228

234229
// Compose SQL base query.
235230
$sql = 'SELECT *
236-
FROM {theme_boost_union_flavours} t
237-
ORDER BY sort';
231+
FROM {theme_boost_union_snippets} s
232+
ORDER BY sortorder';
238233

239234
// Get records.
240235
$data = $DB->get_recordset_sql($sql);
241236

242-
$this->rawdata = snippets::compose_snippets_data( $data );
237+
$this->rawdata = snippets::compose_snippets_data($data);
238+
239+
// TODO Demo content
240+
$this->rawdata = [['id' => 1, 'sortorder' => 1, 'title' => 'foo', 'description' => 'bar', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => true],
241+
['id' => 2, 'sortorder' => 2, 'title' => 'foofoo', 'description' => 'barbar', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => false],
242+
['id' => 3, 'sortorder' => 3, 'title' => 'barbar', 'description' => 'foofoo', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => true]];
243+
$this->totalsnippets = 3;
243244
}
244245

245246
/**
@@ -250,9 +251,8 @@ public function print_nothing_to_display() {
250251

251252
// Show notification as html element.
252253
$notification = new \core\output\notification(
253-
get_string('flavoursnothingtodisplay', 'theme_boost_union'), \core\output\notification::NOTIFY_INFO);
254+
get_string('snippetsnothingtodisplay', 'theme_boost_union'), \core\output\notification::NOTIFY_INFO);
254255
$notification->set_show_closebutton(false);
255256
echo $OUTPUT->render($notification);
256257
}
257-
258258
}

lang/en/theme_boost_union.php

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
$string['settingsoverview_content_desc'] = 'Settings for the global content of your Moodle site are located here: Footer, static pages, info banners, advertisement tiles and sliders.';
4646
$string['settingsoverview_functionality_desc'] = 'Settings for additional useful global or course-related functionality on your Moodle site are located here.';
4747
$string['settingsoverview_flavours_desc'] = 'With flavours, you can diversify the look of your Moodle site between cohorts and / or course categories.';
48+
$string['settingsoverview_snippets_desc'] = 'With CSS snippets, you can TODO.';
4849
$string['settingsoverview_smartmenus_desc'] = 'With smart menus, you can extend the navigation items of your Moodle site in the main menu and the user menus well as introduce a bottom menu or a top menu.';
4950
$string['settingsoverview_all'] = 'All settings on one page';
5051
$string['settingsoverview_all_desc'] = 'Here, you can open the standard Moodle category settings page for Boost Union that shows all settings on one page. But beware, it is really packed.';
@@ -1102,6 +1103,21 @@
11021103
$string['flavourstitle'] = 'Title';
11031104
$string['flavourstitle_help'] = 'The flavour\'s title is just used internally to allow you to document a particular flavour in the list of flavours.';
11041105

1106+
// Settings: CSS snippets page.
1107+
$string['configtitlesnippets'] = 'CSS snippets';
1108+
$string['snippetsdescription'] = 'Description';
1109+
$string['snippetsenable'] = 'Enable';
1110+
$string['snippetsdisable'] = 'Disable';
1111+
$string['snippetsscope'] = 'Scope';
1112+
$string['snippetsscopeglobal'] = 'Global';
1113+
$string['snippetsgoal'] = 'Goal';
1114+
$string['snippetsgoaleyecandy'] = 'Eye candy';
1115+
$string['snippetsgoalbugfix'] = 'Bugfix';
1116+
$string['snippetssnippets'] = 'CSS snippets';
1117+
$string['snippetsnothingtodisplay'] = 'There aren\'t any CSS snippets which can be used.';
1118+
$string['snippetsoverview_desc'] = '<p>Boost Union\'s CSS snippets offer a possibility to TODO.</p>';
1119+
$string['snippetstitle'] = 'Title';
1120+
11051121
// Settings: Smart menus page.
11061122
$string['smartmenus'] = 'Smart menus';
11071123
$string['error:smartmenusmenuitemnotfound'] = 'Smart menu item not found';

settings.php

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@
100100
'theme/boost_union:configure');
101101
$ADMIN->add('theme_boost_union', $flavourspage);
102102

103+
// Create CSS snippets settings page as external page
104+
// (and allow users with the theme/boost_union:configure capability to access it).
105+
$flavourspage = new admin_externalpage('theme_boost_union_snippets',
106+
get_string('configtitlesnippets', 'theme_boost_union', null, true),
107+
new moodle_url('/theme/boost_union/snippets/overview.php'),
108+
'theme/boost_union:configure');
109+
$ADMIN->add('theme_boost_union', $flavourspage);
110+
103111
// Create Smart Menus settings page as external page.
104112
// (and allow users with the theme/boost_union:configure capability to access it).
105113
$smartmenuspage = new admin_externalpage('theme_boost_union_smartmenus',

settings_overview.php

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
'btn' => 'primary',
8383
'url' => new \moodle_url('/theme/boost_union/flavours/overview.php'),
8484
];
85+
$templatecontext['cards'][] = [
86+
'label' => get_string('configtitlesnippets', 'theme_boost_union'),
87+
'desc' => get_string('settingsoverview_snippets_desc', 'theme_boost_union'),
88+
'btn' => 'primary',
89+
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php'),
90+
];
8591
$templatecontext['cards'][] = [
8692
'label' => get_string('smartmenus', 'theme_boost_union'),
8793
'desc' => get_string('settingsoverview_smartmenus_desc', 'theme_boost_union'),

0 commit comments

Comments
 (0)