Skip to content

Commit

Permalink
ci cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartlamour committed Jul 3, 2024
1 parent 69712ea commit 5fffdec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="ass_type" COMMENT="Assessment type db table.">
<TABLE NAME="local_ass_type" COMMENT="Assessment type db table.">
<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"/>
Expand Down
41 changes: 23 additions & 18 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
/**
* Check if an activity is sits mapped.
*
* @param string $modtype The activity type.
*/
function sitsmapped($cmid) {
function local_ass_type_sitsmapped($cmid): bool {
global $DB;

$dbman = $DB->get_manager();
$table = 'local_sitsgradepush_mapping';
if ($dbman->table_exists($table)) {
if ($DB->get_record($table, array('sourceid' => $cmid), 'id')) {
if ($DB->get_record($table, ['sourceid' => $cmid], 'id')) {
return true;
}
}
Expand All @@ -43,8 +44,9 @@ function sitsmapped($cmid) {
/**
* Check if an activity can be summative.
*
* @param string $modtype The activity type e.g. quiz.
*/
function canbesummative($modtype) {
function local_ass_type_canbesummative($modtype): bool {
// Activites which can be marked summative.
$modarray = [
'assign',
Expand All @@ -62,13 +64,15 @@ function canbesummative($modtype) {
/**
* Add Formative or Summative select options to mods.
*
* @param moodleform $formwrapper
* @param MoodleQuickForm $mform
*/
function local_ass_type_coursemodule_standard_elements($formwrapper, $mform) {
global $DB, $PAGE, $CFG;
global $DB;

$cm = $formwrapper->get_current();
// Check list of mods where this is enabled.
if (!canbesummative($cm->modulename)) {
if (!local_ass_type_canbesummative($cm->modulename)) {
return; // Exit if not enabled.
}

Expand All @@ -80,7 +84,7 @@ function local_ass_type_coursemodule_standard_elements($formwrapper, $mform) {
// Flag if sits mapped.
$sitsmapped = false;
if ($cmid) {
$sitsmapped = sitsmapped($cmid);
$sitsmapped = local_ass_type_sitsmapped($cmid);
}

// Mform element.
Expand All @@ -95,7 +99,7 @@ function local_ass_type_coursemodule_standard_elements($formwrapper, $mform) {
if ($sitsmapped) {
$attributes['disabled'] = 'disabled';
}
$select = $mform->createElement('select', 'assessment_type', get_string('fieldlabel','local_ass_type'), $options, $attributes);
$select = $mform->createElement('select', 'assessment_type', get_string('fieldlabel', 'local_ass_type'), $options, $attributes);

// Set to summative when sits mapped.
if ($sitsmapped) {
Expand All @@ -104,17 +108,17 @@ function local_ass_type_coursemodule_standard_elements($formwrapper, $mform) {

// Set existing option from db (when not sits mapped or new).
if (!$sitsmapped && $cmid) {
$table = 'ass_type';
if ($record = $DB->get_record($table, array('cmid' => $cmid), 'type')) {
if ($record = $DB->get_record('local_ass_type', ['cmid' => $cmid], 'type')) {
$select->setSelected($record->type);
}
}

// Link to edit when cm exists.
// TODO - lang string.
$link = '';
if ($cmid) {
$url = new \moodle_url('/local/sitsgradepush/dashboard.php', ['id' => $cm->course]);
$link = '<br>
<a href="' . $CFG->wwwroot. '/local/sitsgradepush/dashboard.php?id=' .$cm->course. '" target="_blank">'
<a href="' . $url . '" target="_blank">'
. get_string('editinsits', 'local_ass_type') .
'</a>';
}
Expand All @@ -126,27 +130,28 @@ function local_ass_type_coursemodule_standard_elements($formwrapper, $mform) {
'</div>');

// Add form elements to the dom.
// TODO - check best place in the form to add?
$mform->insertElementBefore($select, 'introeditor');
$mform->insertElementBefore($info, 'introeditor');
}

/**
* Save Formative or Summative select options.
*
* @param stdClass $data Data from the form submission.
* @param stdClass $course The course.
*/
function local_ass_type_coursemodule_edit_post_actions($data, $course) {
global $DB, $PAGE;
$table = 'ass_type';
function local_ass_type_coursemodule_edit_post_actions($data, $course): stdClass {
global $DB;
$table = 'local_ass_type';

// Record for update/insert.
$r = new \stdClass();
$r->type = $data->type;
$r->cmid = $PAGE->cm->id;
$r->type = $data->assessment_type;
$r->cmid = $data->coursemodule;
$r->courseid = $course->id;

// If record exists.
if ( $record = $DB->get_record($table, array('cmid' => $r->cmid), 'id, type') ) {
if ( $record = $DB->get_record($table, ['cmid' => $r->cmid], 'id, type') ) {
// If record has changed.
if ($record->type != $r->type) {
$r->id = $record->id;
Expand Down

0 comments on commit 5fffdec

Please sign in to comment.