Skip to content

Commit

Permalink
CTP-3869 mod_coursework rename manual field
Browse files Browse the repository at this point in the history
  • Loading branch information
watson8 committed Oct 7, 2024
1 parent 83a1278 commit 2a4cada
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 46 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_coursework_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected function define_structure() {
[
"courseworkid",
"assessorid",
"manual",
"ismanual",
"moderator",
"timelocked",
"stage_identifier",
Expand Down
24 changes: 17 additions & 7 deletions backup/moodle2/restore_coursework_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,32 @@ protected function process_coursework_reminder($data) {
}

protected function process_coursework_allocation_pair($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;

$data->courseworkid = $this->get_new_parentid('coursework');
$data->assessorid = $this->get_mappingid('user', $data->assessorid);

// The "manual" field was renamed to "ismanual" - old backup may contain old name.
if (isset($data->manual)) {
$data->ismanual = $data->manual;
unset($data->manual);
}

$this->updatedate(['timelocked'], $data);

$this->fixallocatable($data);

$this->set_defaults(['assessorid' => 0,
'manual' => 0,
'moderator' => 0,
'timelocked' => time(),
'stage_identifier' => ''], $data);

global $DB;
$this->set_defaults([
'assessorid' => 0,
'ismanual' => 0,
'moderator' => 0,
'timelocked' => time(),
'stage_identifier' => '',
],
$data
);
$newitemid = $DB->insert_record('coursework_allocation_pairs', $data);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/allocation/auto_allocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function delete_all_ungraded_auto_allocations() {
SELECT *
FROM {coursework_allocation_pairs} p
WHERE courseworkid = ?
AND p.manual = 0
AND p.ismanual = 0
AND NOT EXISTS (
SELECT 1
FROM {coursework_submissions} s
Expand Down
4 changes: 2 additions & 2 deletions classes/allocation/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function add_allocation($assessorid, $stageidentifier, $allocatable) {
$addallocation->id = '';
$addallocation->courseworkid = $this->coursework->id;
$addallocation->assessorid = $assessorid;
$addallocation->manual = 1;
$addallocation->ismanual = 1;
$addallocation->stage_identifier = $stageidentifier;
$addallocation->allocatableid = $allocatable->id();
$addallocation->allocatabletype = $allocatable->type();
Expand All @@ -308,7 +308,7 @@ public function update_allocation($allocationid, $assessorid) {

$updateallocation = new \stdClass();
$updateallocation->id = $allocationid;
$updateallocation->manual = 1;
$updateallocation->ismanual = 1;
$updateallocation->assessorid = $assessorid;

$update = $DB->update_record('coursework_allocation_pairs', $updateallocation);
Expand Down
14 changes: 7 additions & 7 deletions classes/models/allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class allocation extends table_base {
/**
* @var int
*/
public $manual;
public $ismanual;

/**
* @var int UNIX timestamp for the point at which this started to be marked. If it's within a set timeframe, we prevent
Expand All @@ -87,7 +87,7 @@ class allocation extends table_base {
'courseworkid',
'assessorid',
'studentid',
'manual',
'ismanual',
'timelocked',
];

Expand Down Expand Up @@ -121,7 +121,7 @@ public function assessor_name() {
* @return bool
*/
public function is_pinned(): bool {
return (bool)$this->manual;
return (bool)$this->ismanual;
}

/**
Expand All @@ -135,17 +135,17 @@ public function set_assessor($assessor) {
*
*/
public function pin() {
if (empty($this->manual)) {
$this->update_attribute('manual', 1);
if (empty($this->ismanual)) {
$this->update_attribute('ismanual', 1);
}
}

/**
*
*/
public function unpin() {
if ($this->manual) {
$this->update_attribute('manual', 0);
if ($this->ismanual) {
$this->update_attribute('ismanual', 0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions classes/stages/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private function get_coursework_id() {
*/
public function make_manual_allocation($allocatable, $teacher) {
$allocation = $this->prepare_allocation_to_save($allocatable, $teacher);
$allocation->manual = 1;
$allocation->ismanual = 1;
$allocation->save();

allocation::fill_pool_coursework($this->get_coursework()->id());
Expand Down Expand Up @@ -280,7 +280,7 @@ public function allocation_is_manual($allocatable) {
'allocatableid-allocatabletype-stage_identifier',
[$allocatable->id(), $allocatable->type(), $this->identifier()]
);
if ($record && $record->manual == 1) {
if ($record && $record->ismanual == 1) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseworkid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="assessorid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="manual" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set to 1, this is an allocation expressly made by an admin, so we might want the auto-allocations to work around it."/>
<FIELD NAME="ismanual" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set to 1, this is an allocation expressly made by an admin, so we might want the auto-allocations to work around it."/>
<FIELD NAME="moderator" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Is this amoderator allocation?"/>
<FIELD NAME="timelocked" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="When someone starts to grade a piece of work, we want to lock their allocation so that automatic re-allocations will not remove it. This field holds a timestamp, which will prevent re-allocation if it's recent enough."/>
<FIELD NAME="stage_identifier" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
Expand Down
14 changes: 14 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,20 @@ function xmldb_coursework_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2020111602, 'coursework');
}

if ($oldversion < 2024100700) {
// CTP-3869 rename field manual on table coursework_allocation_pairs to ismanual.
$table = new xmldb_table('coursework_allocation_pairs');
$field = new xmldb_field(
'manual', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 0, 'assessorid'
);

// Launch rename field sourceid.
$dbman->rename_field($table, $field, 'ismanual');

// Coursework savepoint reached.
upgrade_mod_savepoint(true, 2024100700, 'coursework');
}

// Always needs to return true.
return true;
}
33 changes: 18 additions & 15 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1429,21 +1429,24 @@ function course_group_member_removed($eventdata) {
function can_delete_allocation($courseworkid, $allocatableid) {
global $DB;

// check if allocation is pinned or already graded by an assessor / 1st stage only!
$ungradedallocations = $DB->get_record_sql("SELECT *
FROM {coursework_allocation_pairs} p
WHERE courseworkid = :courseworkid
AND p.manual = 0
AND stage_identifier = 'assessor_1'
AND allocatableid = :allocatableid
AND NOT EXISTS (SELECT 1
FROM {coursework_submissions} s
INNER JOIN {coursework_feedbacks} f ON f.submissionid = s.id
WHERE s.allocatableid = p.allocatableid
AND s.allocatabletype = p.allocatabletype
AND s.courseworkid = p.courseworkid
AND f.stage_identifier = p.stage_identifier)",
['courseworkid' => $courseworkid, 'allocatableid' => $allocatableid]);
// Check if allocation is pinned or already graded by an assessor / 1st stage only!
$sql = "SELECT *
FROM {coursework_allocation_pairs} p
WHERE courseworkid = :courseworkid
AND p.ismanual = 0
AND stage_identifier = 'assessor_1'
AND allocatableid = :allocatableid
AND NOT EXISTS (
SELECT 1
FROM {coursework_submissions} s
INNER JOIN {coursework_feedbacks} f ON f.submissionid = s.id
WHERE s.allocatableid = p.allocatableid
AND s.allocatabletype = p.allocatabletype
AND s.courseworkid = p.courseworkid
AND f.stage_identifier = p.stage_identifier
)";

$ungradedallocations = $DB->get_record_sql($sql, ['courseworkid' => $courseworkid, 'allocatableid' => $allocatableid]);

return $ungradedallocations;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/behat_mod_coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ public function the_student_is_allocated_to_the_teacher($manual = false) {
$allocation->stage_identifier = 'assessor_1';
$allocation->courseworkid = $this->get_coursework()->id;
if ($manual) {
$allocation->manual = 1;
$allocation->ismanual = 1;
}
$generator->create_allocation($allocation);
}
Expand All @@ -1796,7 +1796,7 @@ public function the_student_is_allocated_to_the_teacher($manual = false) {
*/
public function the_manager_is_allocated_as_the_moderator_for_the_student() {
$allocation = new stdClass();
$allocation->manual = 1;
$allocation->ismanual = 1;
$allocation->courseworkid = $this->coursework->id;
$allocation->assessorid = $this->manager->id;
$allocation->allocatableid = $this->student->id();
Expand All @@ -1811,7 +1811,7 @@ public function the_manager_is_allocated_as_the_moderator_for_the_student() {
*/
public function the_manager_is_automatically_allocated_as_the_moderator_for_the_student() {
$allocation = new stdClass();
$allocation->manual = 0;
$allocation->ismanual = 0;
$allocation->courseworkid = $this->coursework->id;
$allocation->assessorid = $this->manager->id;
$allocation->allocatableid = $this->student->id();
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/allocation/auto_allocator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function test_process_allocations_does_not_alter_manual_allocations(): vo
'allocatableid' => $this->student->id,
'allocatabletype' => 'user',
'assessorid' => 555,
'manual' => 1,
'ismanual' => 1,
];
$otherallocation = \mod_coursework\models\allocation::build($params);
$otherallocation->save();
Expand Down
4 changes: 2 additions & 2 deletions tests/classes/allocation/form/table_processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function test_process_rows_makes_a_new_assessor_allocation(): void {
'courseworkid' => $this->coursework->id,
'allocatableid' => $this->student->id,
'allocatabletype' => 'user',
'manual' => 1,
'ismanual' => 1,
];
$allocations = $DB->get_records('coursework_allocation_pairs', $params);
$this->assertEquals(2, count($allocations));
Expand Down Expand Up @@ -115,7 +115,7 @@ public function test_process_rows_sets_the_stage_identifiers_for_new_assessor_al
'courseworkid' => $this->coursework->id,
'allocatableid' => $this->student->id,
'allocatabletype' => 'user',
'manual' => 1,
'ismanual' => 1,
'assessorid' => $this->teacher->id,
'stage_identifier' => 'assessor_1',
];
Expand Down
2 changes: 1 addition & 1 deletion tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function create_allocation($allocation) {
throw new coding_exception('Coursework generator needs an assessorid for a new allocation');
}
}
$allocation->manual = !empty($allocation->manual) ? 1 : 0;
$allocation->ismanual = !empty($allocation->ismanual) ? 1 : 0;
if (empty($allocation->allocatabletype)) {
$allocation->allocatabletype = 'user';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function test_create_allocation_default_assessor(): void {
$this->assertEquals(2, $allocation->assessorid);
$this->assertEquals(5, $allocation->allocatableid);
$this->assertEquals(65, $allocation->courseworkid);
$this->assertEquals(0, $allocation->manual);
$this->assertEquals(0, $allocation->ismanual);

}

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 @@

$plugin->component = 'mod_coursework';

$plugin->version = 2024091600; // If version == 0 then module will not be installed
$plugin->version = 2024100700; // If version == 0 then module will not be installed
$plugin->requires = 2023100400; // Requires this Moodle version

$plugin->cron = 300; // Period for cron to check this module (secs).
Expand Down
2 changes: 1 addition & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
$redirectdetail = new \stdClass();
$redirectdetail->percentage = $percentage_allocation_not_complete;
$redirectdetail->manual = $manual_allocation_not_complete;
$redirectdetail->ismanual = $manual_allocation_not_complete;
redirect($CFG->wwwroot.'/mod/coursework/actions/allocate.php?id='.$course_module_id, get_string('configuration_needed', 'coursework', $redirectdetail));
}
Expand Down

0 comments on commit 2a4cada

Please sign in to comment.