Skip to content

Commit

Permalink
CTP-4184 Enable staff only alerts (#14)
Browse files Browse the repository at this point in the history
* CTP-4184 Enable staff only alerts
  • Loading branch information
stuartlamour authored Jan 27, 2025
1 parent bb82223 commit 99ffbbd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand Down
34 changes: 33 additions & 1 deletion block_alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,51 @@ public function get_content(): stdClass {
return $this->content;
}

/**
* Return if user has archetype editingteacher or system manager/coursecreator role.
*
*/
public static function is_teacher(): bool {
global $DB, $USER;

// Check for manager or coursecreator role.
foreach (get_user_roles(context_system::instance()) as $role) {
if ($role->shortname === 'manager' || $role->shortname === 'coursecreator') {
return true;
}
}

// Get id's from role where archetype is editingteacher.
$roles = $DB->get_fieldset('role', 'id', ['archetype' => 'editingteacher']);

// Check if user has editingteacher role on any courses.
list($roles, $params) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED);
$params['userid'] = $USER->id;
$sql = "SELECT id
FROM {role_assignments}
WHERE userid = :userid
AND roleid $roles";
return $DB->record_exists_sql($sql, $params);
}

/**
* Get the alerts.
*
* @return array alerts items.
*/
public function fetch_alert(): array {
// Staff only check.
if (get_config('block_alerts', 'staffonly') && !self::is_teacher()) {
return [];
}

// Template data for mustache.
$template = new stdClass();

// Get alert content.
$alert = new stdClass();
$alert->description = get_config('block_alerts', 'description');
$alert->title = get_config('block_alerts', 'title');
$alert->description = get_config('block_alerts', 'description');
$alert->link = get_config('block_alerts', 'link');
$alert->linktext = get_config('block_alerts', 'linktext');

Expand Down
1 change: 1 addition & 0 deletions lang/en/block_alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
$string['linktext_help'] = 'A meaningful link title. Do not use inaccessible link text such as "click here" or "read more".';
$string['pluginname'] = 'Alerts';
$string['privacy:metadata'] = 'Alerts does not store any personal data.';
$string['staffonly'] = "Only visible to staff";
$string['title'] = 'Title';
17 changes: 13 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@

$default = '';

// Staff only.
$setting = new admin_setting_configcheckbox('block_alerts/staffonly',
get_string('staffonly', 'block_alerts'), '', 0);
$settings->add($setting);

// Title.
$setting = new admin_setting_configtext('block_alerts/title',
get_string('title', 'block_alerts'),
'',
$default,
PARAM_RAW
PARAM_RAW,
'60'
);
$settings->add($setting);

Expand All @@ -43,7 +49,8 @@
get_string('description', 'block_alerts'),
get_string('description_help', 'block_alerts'),
$default,
PARAM_RAW
PARAM_RAW,
'60'
);
$settings->add($setting);

Expand All @@ -52,7 +59,8 @@
get_string('link', 'block_alerts'),
get_string('link_help', 'block_alerts'),
$default,
PARAM_RAW
PARAM_RAW,
'60'
);
$settings->add($setting);

Expand All @@ -61,7 +69,8 @@
get_string('linktext', 'block_alerts'),
get_string('linktext_help', 'block_alerts'),
$default,
PARAM_RAW
PARAM_RAW,
'60'
);
$settings->add($setting);

Expand Down
2 changes: 1 addition & 1 deletion templates/content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}}

<div role="alert" class="alert alert-info px-2 border-info d-flex align-items-center"
style="border: none; border-left: .5rem solid;" >
style="border: none; border-left: .3rem solid;" >
<!-- Alert icon. -->
<i class="fa-solid fa-triangle-exclamation fa-2xl text-primary ml-2"></i>
<!-- Alert content. -->
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023062600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024121200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0';
$plugin->maturity = MATURITY_ALPHA;
$plugin->requires = 2019051100; // Requires this Moodle version.
Expand Down

0 comments on commit 99ffbbd

Please sign in to comment.