Skip to content

CTP-4481: replaced is_teacher() with is_marker() #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 3, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 65 additions & 12 deletions block_my_feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
*/
class block_my_feedback extends block_base {

/**
* @var array array of roles a marker may have.
*/
private static array $markerroles;

/**
* @var bool marker status.
*/
private static bool $ismarker;

/**
* Initialises the block.
*
Expand All @@ -37,15 +47,37 @@ class block_my_feedback extends block_base {
public function init() {
global $USER;

self::$markerroles = self::get_marker_role_ids();
self::$ismarker = self::is_marker();

if (!isset($USER->firstname)) {
$this->title = get_string('pluginname', 'block_my_feedback');
} else if (self::is_teacher()) {
} else if (self::$ismarker) {
$this->title = get_string('markingfor', 'block_my_feedback').' '.$USER->firstname;
} else {
$this->title = get_string('feedbackfor', 'block_my_feedback').' '.$USER->firstname;
}
}

/**
* Get the marker role IDs.
*
* @return array
*/
private static function get_marker_role_ids(): array {
global $DB;

return $DB->get_fieldset_select('role', 'id',
'shortname IN (:role1, :role2, :role3, :role4)',
[
'role1' => 'ucltutor',
'role2' => 'uclnoneditingtutor',
'role3' => 'uclnoneditingtutor_noemail',
'role4' => 'uclleader',
]
);
}

/**
* Gets the block contents.
*
Expand All @@ -63,8 +95,8 @@ public function get_content(): stdClass {

$template = new stdClass();

if (self::is_teacher()) {
// Teacher content.
if (self::$ismarker) {
// Marker content.
$template->mods = self::fetch_marking($USER);
} else {
// Student content.
Expand All @@ -80,22 +112,38 @@ public function get_content(): stdClass {
}

/**
* Return if user has archetype editingteacher.
* Return if user has required marker role at all or optional in given course.
*
* @param stdClass|null $course
* @return bool
*/
public static function is_teacher(): bool {
private static function is_marker(stdClass|null $course = null): bool {
global $DB, $USER;
// Get id's from role where archetype is editingteacher.
$roles = $DB->get_fieldset('role', 'id', ['archetype' => 'editingteacher']);
$roles = self::$markerroles;

// 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
if ($course) {
// Check if user has expected role in the given course.
foreach ($roles as $role) {
if (user_has_role_assignment($USER->id, (int) $role, $course->ctxid)) {
return true;
}
}
return false;

} else {
if (!$roles) {
return false;
}

// 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);
return $DB->record_exists_sql($sql, $params);
}
}

/**
Expand All @@ -116,6 +164,11 @@ public static function fetch_marking(stdClass $user): ?array {
continue;
}

// Skip if user has no teacher role in the course.
if (!self::is_marker($course)) {
continue;
}

// Skip if no summative assessments.
if (!$summatives = assess_type::get_assess_type_records_by_courseid($course->id, assess_type::ASSESS_TYPE_SUMMATIVE)) {
continue;
Expand Down