Skip to content
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

EC & SORA #74

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
moodle-branch: 'MOODLE_405_STABLE'
database: 'mariadb'

steps:
Expand Down
69 changes: 67 additions & 2 deletions classes/assessment/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace local_sitsgradepush\assessment;

use core\context\module;
use grade_item;
use local_sitsgradepush\manager;

Expand All @@ -32,8 +33,8 @@ abstract class activity extends assessment {
/** @var \stdClass Course module object */
public \stdClass $coursemodule;

/** @var \stdClass Context object */
public \context_module $context;
/** @var module Context object */
public module $context;

/**
* Constructor.
Expand Down Expand Up @@ -107,6 +108,15 @@ public function get_module_name(): string {
return $this->coursemodule->modname;
}

/**
* Get the module context.
*
* @return module
*/
public function get_module_context(): module {
return $this->context;
}

/**
* Get the course module id.
*
Expand Down Expand Up @@ -163,6 +173,28 @@ public function get_grade_items(): array {
return !(empty($gradeitems)) ? $gradeitems : [];
}

/**
* Delete all SORA overrides for the assessment.
*
* @return void
* @throws \coding_exception
* @throws \dml_exception
*/
public function delete_all_sora_overrides(): void {
global $CFG;
require_once($CFG->dirroot . '/group/lib.php');

// Find all the sora group overrides for the assessment.
$overrides = $this->get_assessment_sora_overrides();

// Delete all sora groups of that assessment from the course.
if (!empty($overrides)) {
foreach ($overrides as $override) {
groups_delete_group($override->groupid);
}
}
}

/**
* Set the module instance.
* @return void
Expand Down Expand Up @@ -211,4 +243,37 @@ protected function get_gradeable_enrolled_users_with_capability(string $capabili
return in_array($u->id, $gradeableids);
});
}

/**
* Remove user from previous SORA groups of the assessment.
* When a user is added to a new group, they should be removed from all other SORA groups of the assessment.
*
* @param int $userid User ID.
* @param int|null $excludedgroupid Group ID to exclude. This is the group that the user is being added to.
* @return void
*/
protected function remove_user_from_previous_sora_groups(int $userid, ?int $excludedgroupid = null): void {
// Get all the sora group overrides.
$overrides = $this->get_assessment_sora_overrides();

// No overrides to remove.
if (empty($overrides)) {
return;
}

foreach ($overrides as $override) {
// Skip the excluded group.
if ($excludedgroupid && $override->groupid == $excludedgroupid) {
continue;
}

// Remove the user from the previous SORA group.
groups_remove_member($override->groupid, $userid);

// Delete the group if it is empty.
if (empty(groups_get_members($override->groupid))) {
groups_delete_group($override->groupid);
}
}
}
}
94 changes: 93 additions & 1 deletion classes/assessment/assessment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

namespace local_sitsgradepush\assessment;

use local_sitsgradepush\extension\ec;
use local_sitsgradepush\extension\extension;
use local_sitsgradepush\extension\sora;
use local_sitsgradepush\manager;

/**
Expand Down Expand Up @@ -55,6 +58,38 @@ public function __construct(string $sourcetype, int $sourceid) {
$this->set_instance();
}

/**
* Apply extension to the assessment.
*
* @param extension $extension
* @return void
* @throws \moodle_exception
*/
public function apply_extension(extension $extension): void {
$check = $this->is_valid_for_extension();
if (!$check->valid) {
throw new \moodle_exception($check->errorcode, 'local_sitsgradepush');
}

// Do extension base on the extension type.
if ($extension instanceof ec) {
$this->apply_ec_extension($extension);
} else if ($extension instanceof sora) {
// Skip SORA overrides if the end date of the assessment is in the past.
if ($this->get_end_date() < time()) {
return;
}

// Remove user from all SORA groups in this assessment.
if ($extension->get_time_extension() == 0) {
$this->remove_user_from_previous_sora_groups($extension->get_userid());
return;
}

$this->apply_sora_extension($extension);
}
}

/**
* Get the source id.
*
Expand Down Expand Up @@ -166,6 +201,15 @@ public function get_end_date(): ?int {
return null;
}

/**
* Get module name. Return empty string if not applicable.
*
* @return string
*/
public function get_module_name(): string {
return '';
}

/**
* Check if the assessment is valid for marks transfer.
*
Expand Down Expand Up @@ -199,6 +243,31 @@ public function check_assessment_validity(): \stdClass {
return $result;
}

/**
* Check if the assessment is valid for EC or SORA extension.
*
* @return \stdClass
*/
public function is_valid_for_extension(): \stdClass {
if ($this->get_start_date() === null || $this->get_end_date() === null) {
return $this->set_validity_result(false, 'error:assessmentdatesnotset');
}

return $this->set_validity_result(true);
}

/**
* Delete all SORA override for a Moodle assessment.
* It is used to delete all SORA overrides for an assessment when the mapping is removed.
*
* @return void
* @throws \moodle_exception
*/
public function delete_all_sora_overrides(): void {
// Default not supported. Override in child class if needed.
throw new \moodle_exception('error:soraextensionnotsupported', 'local_sitsgradepush');
}

/**
* Set validity result.
*
Expand Down Expand Up @@ -227,11 +296,34 @@ protected function get_equivalent_grade_from_mark(float $marks): ?string {
return $equivalentgrade;
}

/**
* Apply EC extension.
*
* @param ec $ec
* @return void
* @throws \moodle_exception
*/
protected function apply_ec_extension(ec $ec): void {
// Default not supported. Override in child class if needed.
throw new \moodle_exception('error:ecextensionnotsupported', 'local_sitsgradepush');
}

/**
* Apply SORA extension.
*
* @param sora $sora
* @return void
* @throws \moodle_exception
*/
protected function apply_sora_extension(sora $sora): void {
// Default not supported. Override in child class if needed.
throw new \moodle_exception('error:soraextensionnotsupported', 'local_sitsgradepush');
}

/**
* Get all participants for the assessment.
*
* @return array
*/
abstract public function get_all_participants(): array;

}
Loading
Loading