Skip to content

Commit

Permalink
Add admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Sep 3, 2024
1 parent 5206642 commit d54284e
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 66 deletions.
132 changes: 66 additions & 66 deletions classes/table/snippets_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class snippets_overview extends \table_sql {
// TODO:
/**
* @var int $count Flavours count.
* @var int $count Snippets count.
*/
private $count;

/**
* @var int $totalflavours Total flavours count.
* @var int $totalsnippets Total snippets count.
*/
private $totalflavours;
private $totalsnippets;

/**
* Setup table.
Expand All @@ -63,17 +62,19 @@ public function __construct() {
global $DB;

// Call parent constructor.
parent::__construct('flavours');
parent::__construct('snippets');

// Define the headers and columns.
$headers[] = get_string('flavourstitle', 'theme_boost_union');
$headers[] = get_string('flavoursdescription', 'theme_boost_union');
$headers[] = get_string('flavoursappliesto', 'theme_boost_union');
$headers[] = get_string('snippetstitle', 'theme_boost_union');
$headers[] = get_string('snippetsdescription', 'theme_boost_union');
$headers[] = get_string('snippetsscope', 'theme_boost_union');
$headers[] = get_string('snippetsgoal', 'theme_boost_union');
$headers[] = get_string('up') .'/'. get_string('down');
$headers[] = get_string('actions');
$columns[] = 'title';
$columns[] = 'description';
$columns[] = 'appliesto';
$columns[] = 'scope';
$columns[] = 'goal';
$columns[] = 'updown';
$columns[] = 'actions';
$this->sortable(false); // Having a sortable table would be nice, but this would interfere with the up/down feature.
Expand All @@ -85,7 +86,7 @@ public function __construct() {

// Initialize values for the updown feature.
$this->count = 0;
$this->totalflavours = $DB->count_records('theme_boost_union_flavours');
$this->totalsnippets = $DB->count_records('theme_boost_union_snippets');
}

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

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/flavours/overview.php');
$actionurl = new \moodle_url('/theme/boost_union/snippets/overview.php');

// Initialize column value.
$updown = '';

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

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

// Otherwise, just add a spacer.
} else {
$updown .= $spacer;
}

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

// Otherwise, just add a spacer.
} else {
$updown .= $spacer;
}

// Increase the flavour counter.
// Increase the snippet counter.
$this->count++;

// Return the column value.
return $updown;
}

/**
* Applies to column.
* Scope column.
*
* @param \stdClass $data
* @return string
* @return mixed
*/
public function col_appliesto($data) {
// Initialize the badges.
$badges = [];

// If apply-to-categories is enabled, add a badge.
if ($data->applytocategories == true) {
$badges[] = \html_writer::tag('span',
get_string('categories'),
['class' => 'badge bg-primary text-light']);
}
public function col_scope($data) {
// Get the string for the given scope from the language pack.
$string = get_string('snippetsscope'.$data->scope, 'theme_boost_union');

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

// Implode and return the badges.
return implode(' ', $badges);
/**
* Goal column.
*
* @param \stdClass $data
* @return mixed
*/
public function col_goal($data) {
// Get the string for the given goal from the language pack.
$string = get_string('snippetsgoal'.$data->goal, 'theme_boost_union');

// Output Bootstrap label.
return \html_writer::tag('span', $string, ['class' => 'badge bg-primary text-light']);
}

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

// Preview.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/preview.php', ['id' => $data->id]),
'icon' => new \pix_icon('i/search', get_string('flavoursedit', 'theme_boost_union')),
'attributes' => ['class' => 'action-preview'],
];

// Edit.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
['action' => 'edit', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/edit', get_string('flavoursedit', 'theme_boost_union')),
'attributes' => ['class' => 'action-edit'],
];

// Delete.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/delete', get_string('flavourspreview', 'theme_boost_union')),
'attributes' => ['class' => 'action-delete'],
];
// Enable/Disable.
if ($data->enabled == false) {
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php',
['action' => 'enable', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/hide', get_string('snippetsenable', 'theme_boost_union')),
'attributes' => ['class' => 'action-enable'],
];
} else {
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php',
['action' => 'disable', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/show', get_string('snippetsdisable', 'theme_boost_union')),
'attributes' => ['class' => 'action-disable'],
];
}

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

// Return all actions.
return \html_writer::span(join('', $actionshtml), 'flavours-actions');
return \html_writer::span(join('', $actionshtml), 'snippets-actions');
}

/**
* Get the flavours for the table.
* Get the snippets for the table.
*
* @param int $pagesize
* @param bool $useinitialsbar
Expand All @@ -233,13 +228,19 @@ public function query_db($pagesize, $useinitialsbar = true) {

// Compose SQL base query.
$sql = 'SELECT *
FROM {theme_boost_union_flavours} t
ORDER BY sort';
FROM {theme_boost_union_snippets} s
ORDER BY sortorder';

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

$this->rawdata = snippets::compose_snippets_data( $data );
$this->rawdata = snippets::compose_snippets_data($data);

// TODO Demo content
$this->rawdata = [['id' => 1, 'sortorder' => 1, 'title' => 'foo', 'description' => 'bar', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => true],
['id' => 2, 'sortorder' => 2, 'title' => 'foofoo', 'description' => 'barbar', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => false],
['id' => 3, 'sortorder' => 3, 'title' => 'barbar', 'description' => 'foofoo', 'scope' => 'global', 'goal' => 'bugfix', 'enabled' => true]];
$this->totalsnippets = 3;
}

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

// Show notification as html element.
$notification = new \core\output\notification(
get_string('flavoursnothingtodisplay', 'theme_boost_union'), \core\output\notification::NOTIFY_INFO);
get_string('snippetsnothingtodisplay', 'theme_boost_union'), \core\output\notification::NOTIFY_INFO);
$notification->set_show_closebutton(false);
echo $OUTPUT->render($notification);
}

}
16 changes: 16 additions & 0 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$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.';
$string['settingsoverview_functionality_desc'] = 'Settings for additional useful global or course-related functionality on your Moodle site are located here.';
$string['settingsoverview_flavours_desc'] = 'With flavours, you can diversify the look of your Moodle site between cohorts and / or course categories.';
$string['settingsoverview_snippets_desc'] = 'With CSS snippets, you can TODO.';
$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.';
$string['settingsoverview_all'] = 'All settings on one page';
$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.';
Expand Down Expand Up @@ -1102,6 +1103,21 @@
$string['flavourstitle'] = 'Title';
$string['flavourstitle_help'] = 'The flavour\'s title is just used internally to allow you to document a particular flavour in the list of flavours.';

// Settings: CSS snippets page.
$string['configtitlesnippets'] = 'CSS snippets';
$string['snippetsdescription'] = 'Description';
$string['snippetsenable'] = 'Enable';
$string['snippetsdisable'] = 'Disable';
$string['snippetsscope'] = 'Scope';
$string['snippetsscopeglobal'] = 'Global';
$string['snippetsgoal'] = 'Goal';
$string['snippetsgoaleyecandy'] = 'Eye candy';
$string['snippetsgoalbugfix'] = 'Bugfix';
$string['snippetssnippets'] = 'CSS snippets';
$string['snippetsnothingtodisplay'] = 'There aren\'t any CSS snippets which can be used.';
$string['snippetsoverview_desc'] = '<p>Boost Union\'s CSS snippets offer a possibility to TODO.</p>';
$string['snippetstitle'] = 'Title';

// Settings: Smart menus page.
$string['smartmenus'] = 'Smart menus';
$string['error:smartmenusmenuitemnotfound'] = 'Smart menu item not found';
Expand Down
8 changes: 8 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
'theme/boost_union:configure');
$ADMIN->add('theme_boost_union', $flavourspage);

// Create CSS snippets settings page as external page
// (and allow users with the theme/boost_union:configure capability to access it).
$flavourspage = new admin_externalpage('theme_boost_union_snippets',
get_string('configtitlesnippets', 'theme_boost_union', null, true),
new moodle_url('/theme/boost_union/snippets/overview.php'),
'theme/boost_union:configure');
$ADMIN->add('theme_boost_union', $flavourspage);

// Create Smart Menus settings page as external page.
// (and allow users with the theme/boost_union:configure capability to access it).
$smartmenuspage = new admin_externalpage('theme_boost_union_smartmenus',
Expand Down
6 changes: 6 additions & 0 deletions settings_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
'btn' => 'primary',
'url' => new \moodle_url('/theme/boost_union/flavours/overview.php'),
];
$templatecontext['cards'][] = [
'label' => get_string('configtitlesnippets', 'theme_boost_union'),
'desc' => get_string('settingsoverview_snippets_desc', 'theme_boost_union'),
'btn' => 'primary',
'url' => new \moodle_url('/theme/boost_union/snippets/overview.php'),
];
$templatecontext['cards'][] = [
'label' => get_string('smartmenus', 'theme_boost_union'),
'desc' => get_string('settingsoverview_smartmenus_desc', 'theme_boost_union'),
Expand Down
Loading

0 comments on commit d54284e

Please sign in to comment.