Skip to content

Commit

Permalink
CTP-4184 Enable staff only alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartlamour committed Dec 13, 2024
1 parent bb82223 commit fdf92b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
29 changes: 28 additions & 1 deletion block_alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,46 @@ public function get_content(): stdClass {
return $this->content;
}

/**
* Return if user has archetype editingteacher.
*
*/
public static function is_teacher(): bool {
global $DB, $USER;
// 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')) {
if (!self::is_teacher()) {
return []; // Don't ouput for learners.
}
}

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

// Get alert content.
$alert = new stdClass();
$alert->description = get_config('block_alerts', 'description');
$alert->staffonly = get_config('block_alerts', 'staffonly');
$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'] = "Staff only";
$string['title'] = 'Title';
13 changes: 10 additions & 3 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,
'140'
);
$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,
'140'
);
$settings->add($setting);

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

Expand Down

0 comments on commit fdf92b3

Please sign in to comment.