Skip to content

Commit

Permalink
Update update_type function for marks transfer (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
aydevworks authored Sep 13, 2024
1 parent e44a463 commit 438fbab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
26 changes: 23 additions & 3 deletions classes/assess_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,29 @@ public static function is_locked(int $cmid): bool {
/**
* Update the assess type.
*
* @param int $cmid - The mod id.
* @param int $courseid - The course id.
* @param int $type - formative/summative/dummy.
* @param int $cmid - The mod id.
* @param int $gradeitemid - The grade item id.
* @param int $locked - Lock field.
*
* @throws \dml_exception
*/
public static function update_type(int $cmid, int $courseid, int $type, int $locked = 0): void {
public static function update_type(int $courseid, int $type, int $cmid = 0, int $gradeitemid = 0, int $locked = 0): void {
global $DB;
$table = 'local_assess_type';

// Prepare the record to write.
$record = (object) [
'type' => $type,
'cmid' => $cmid,
'gradeitemid' => $gradeitemid,
'courseid' => $courseid,
'locked' => $locked,
];

// Check if the record already exists.
$existingrecord = $DB->get_record($table, ['cmid' => $cmid], 'id, type, locked');
$existingrecord = $DB->get_record($table, ['cmid' => $cmid, 'gradeitemid' => $gradeitemid], 'id, type, locked');

// If the record exists and has changed, update it.
if ($existingrecord) {
Expand All @@ -151,4 +153,22 @@ public static function update_type(int $cmid, int $courseid, int $type, int $loc
$DB->insert_record($table, $record, false);
}
}

/**
* Get all assess type records by course id.
*
* @param int $courseid
* @param int|null $type
*
* @return array
* @throws \dml_exception
*/
public static function get_assess_type_records_by_courseid(int $courseid, ?int $type = null): array {
global $DB;
$params = ['courseid' => $courseid];
if ($type) {
$params['type'] = $type;
}
return $DB->get_records('local_assess_type', $params);
}
}
7 changes: 4 additions & 3 deletions db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="local/assess_type/db" VERSION="20240701" COMMENT="XMLDB file for UCL"
<XMLDB PATH="local/assess_type/db" VERSION="20240902" COMMENT="XMLDB file for UCL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -8,7 +8,8 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Foreign key of course id"/>
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Foreign key cm id"/>
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Foreign key cm id"/>
<FIELD NAME="gradeitemid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="The value of this datum"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Locked field"/>
</FIELDS>
Expand All @@ -17,4 +18,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function local_assess_type_coursemodule_edit_post_actions($data, $course): stdCl

// We have data, update the assessment type.
// N.B. Casting (int)assessment_type to stop core Behat error.
assess_type::update_type($data->coursemodule, $course->id, (int)$data->assessment_type);
assess_type::update_type($course->id, (int)$data->assessment_type, $data->coursemodule);

// Carry on with other form things.
return $data;
Expand Down

0 comments on commit 438fbab

Please sign in to comment.