Skip to content

Commit

Permalink
Completion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drachels committed Jul 1, 2024
1 parent 0871ddf commit f4b98f1
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 73 deletions.
45 changes: 33 additions & 12 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,59 @@ public function get_state(string $rule): int {
global $DB;

$this->validate_rule($rule);

$userid = $this->userid;
$hotquestionid = $this->cm->instance;

if (!$hotquestion = $DB->get_record('hotquestion', ['id' => $hotquestionid])) {
throw new moodle_exception(get_string('incorrectmodule', 'hotquestion'));

}

$status = COMPLETION_INCOMPLETE;
$questioncountparams = ['userid' => $userid, 'hotquestionid' => $hotquestionid];
$questionvoteparams = ['userid' => $userid, 'hotquestionid' => $hotquestionid];

$questionpostsql = "SELECT COUNT(hqq.id)
FROM {hotquestion_questions} hqq
WHERE hqq.hotquestion = :hotquestionid
AND hqq.userid = :userid";

$questionvotesql = "SELECT COUNT(hv.id)
FROM {hotquestion_votes} hv
JOIN {hotquestion_questions} hq ON hq.id = hv.question
WHERE hq.hotquestion = :hotquestionid
JOIN {hotquestion_questions} hqq ON hqq.id = hv.question
WHERE hqq.hotquestion = :hotquestionid
AND hv.voter = :userid";

$questiongradesql = "SELECT *
FROM {hotquestion_grades} hqg
JOIN {hotquestion_questions} hqq ON hqg.hotquestion = hqq.id
JOIN {hotquestion} hq ON hq.id = hqg.hotquestion
WHERE hqg.userid = :userid
AND hqq.id = :hotquestionid";

if ($rule == 'completionpost') {
$status = $hotquestion->completionpost <=
$DB->count_records('hotquestion_questions', ['hotquestion' => $hotquestionid, 'userid' => $userid]);

if ($status = $hotquestion->completionpost <=
$DB->get_field_sql($questionpostsql, $questioncountparams)) {
$status = $hotquestion->completionpost = 1;
} else {
$status = $hotquestion->completionpost = 0;
}
} else if ($rule == 'completionvote') {
$status = $hotquestion->completionvote <=
$DB->get_field_sql($questionvotesql, $questionvoteparams);
if ($status = $hotquestion->completionvote <=
$DB->get_field_sql($questionvotesql, $questionvoteparams)) {
$status = $hotquestion->completionvote = 1;
} else {
$status = $hotquestion->completionvote = 0;
}
} else if ($rule == 'completionpass') {
$status = $hotquestion->completionpass <=
if ($status = $hotquestion->completionpass <=
$DB->get_field_sql($questioncountsql.
' AND hqg.userid = $userid AND hqg.rawrating >= hqqcompletionpass',
$questioncountparams);
//' AND hqg.userid = $userid AND hqg.rawrating >= hqqcompletionpass',
' AND hqg.userid = $userid AND hqg.rawrating >= hqgrade',
$questioncountparams)) {
$status = $hotquestion->completionpass = 1;
} else {
$status = $hotquestion->completionpass = 0;
}
}
return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}
Expand All @@ -91,6 +108,7 @@ public static function get_defined_custom_rules(): array {
return [
'completionpost',
'completionvote',
'completionpass',
];
}

Expand All @@ -102,9 +120,11 @@ public static function get_defined_custom_rules(): array {
public function get_custom_rule_descriptions(): array {
$completionpost = $this->cm->customdata['customcompletionrules']['completionpost'] ?? 0;
$completionvote = $this->cm->customdata['customcompletionrules']['completionvote'] ?? 0;
$completionpass = $this->cm->customdata['customcompletionrules']['completionpass'] ?? 0;
return [
'completionpost' => get_string('completiondetail:post', 'hotquestion', $completionpost),
'completionvote' => get_string('completiondetail:vote', 'hotquestion', $completionvote),
'completionpass' => get_string('completiondetail:pass', 'hotquestion', $completionpass),
];
}

Expand All @@ -118,6 +138,7 @@ public function get_sort_order(): array {
'completionview',
'completionpost',
'completionvote',
'completionpass',
'completionusegrade',
'completionpassgrade',
];
Expand Down
4 changes: 2 additions & 2 deletions classes/event/update_vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has just voted for a question in the hotquestion activity with the course module ".
" id '$this->contextinstanceid'.";
return "The user with id '$this->userid' has just voted for a question in the hotquestion activity with the course module id
'$this->contextinstanceid'.";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class provider implements \core_privacy\local\metadata\provider,
* @param collection $collection The initialised collection to add items to.
* @return collection The updated collection of metadata items.
*/
public static function get_metadata(collection $collection): collection {
public static function get_metadata(collection $collection) : collection {
$collection->add_database_table(
'hotquestion_questions',
[
Expand Down Expand Up @@ -107,7 +107,7 @@ private static function get_modid() {
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
public static function get_contexts_for_userid(int $userid) : contextlist {
$contextlist = new contextlist();
$modid = self::get_modid();
if (!$modid) {
Expand Down
84 changes: 41 additions & 43 deletions lang/en/hotquestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@

$string['ago'] = '{$a} ago';
$string['allowanonymouspost'] = 'Allow post question as anonymous';
$string['allowanonymouspost_descr'] = 'If enabled, questions can be posted anonomously, and if approved for viewing heat votes can be made by everyone.';
$string['allowanonymouspost_help'] = 'If enabled, questions can be posted anonomously, and if approved for viewing heat votes can be made by everyone.';
$string['allowanonymouspost_descr'] = 'If enabled, questions can be posted anonomously, and if approved for viewing heat votes can be made by everyone.';
$string['allowauthorinfohide'] = 'Allow authors name to be hidden';
$string['allowauthorinfohide_descr'] = 'If enabled, the name of the questions author can be visible to teachers but hidden from students.';
$string['allowauthorinfohide_help'] = 'If enabled, the name of the questions author can be visible to teachers but hidden from students.';
$string['allowauthorinfohide_descr'] = 'If enabled, the name of the questions author can be visible to teachers but hidden from students.';
$string['allowcomments'] = 'Allow comments on entries';
$string['allowcomments_help'] = 'If enabled, all participants with permission to create comments will be able to add comments to hot question entries.';
$string['alwaysshowdescription'] = 'Always show description';
$string['alwaysshowdescription_help'] = 'If disabled, the Hot Question Description will not be visible to students.';
$string['anonymous'] = 'Anonymous';
$string['approvallabel'] = 'Approval required column label';
$string['approvallabel_descr'] = 'Enter a default label for the Approved column.';
$string['approvedno'] = 'Not approved';
$string['approvedyes'] = 'Approved';
$string['approvedno'] = 'Not approved';
$string['authorinfo'] = 'Posted by {$a->user} at {$a->time}';
$string['authorinfohide'] = 'Posted {$a->time}';
$string['calendarend'] = '{$a} closes';
$string['calendarstart'] = '{$a} opens';
$string['cnfallowcomments'] = 'Define if a hot question will accept comments on entries by default';
$string['completiondetail:pass'] = 'Passing grade: {$a}';
$string['completiondetail:post'] = 'Post questions: {$a}';
$string['completiondetail:vote'] = 'Give heat: {$a}';
$string['completionpass'] = 'Student must pass:';
$string['completiondetail:pass'] = 'Passing grade: {$a}';
$string['completionpostdesc'] = 'Student must create at least {$a} questions(s)';
$string['completionvotedesc'] = 'Student must vote/give heat to {$a} question(s) or post(s)';
$string['completionpassdesc'] = 'Student must receive passing grade of {$a}';
$string['completionpostgroup'] = 'Require questions';
$string['completionvotegroup'] = 'Require heat:';
$string['completionpassgroup'] = 'Require pass:';
$string['completionpost'] = 'Student must add questions:';
$string['completionpostdesc'] = 'Student must create at least {$a} questions(s)';
$string['completionpostgroup'] = 'Require questions';
$string['completionvote'] = 'Student must add heat:';
$string['completionvotedesc'] = 'Student must vote/give heat to {$a} question(s) or post(s)';
$string['completionvotegroup'] = 'Require heat:';
$string['completionpass'] = 'Student must pass:';
$string['connectionerror'] = 'Connection error';
$string['content'] = 'Content';
$string['csvexport'] = 'Export to .csv';
Expand Down Expand Up @@ -115,9 +115,15 @@
$string['heatlimit_help'] = 'Enter a default for the number of times you can apply heat/vote, per round. Zero hides the heat column.';
$string['heatreceived'] = 'Heat received';
$string['heatvisibility'] = 'Heat column visibility';
$string['heatvisibility_descr'] = 'If enabled, the Heat column is visible, otherwise it is hidden.';
$string['heatvisibility_help'] = 'If enabled, the Heat column is visible.';
$string['heatvisibility_descr'] = 'If enabled, the Heat column is visible, otherwise it is hidden.';
$string['hotquestion'] = 'Hotquestion';
$string['hotquestionclosed'] = 'This activity closed on {$a}.';
$string['hotquestionclosetime'] = 'Close time';
$string['hotquestionintro'] = 'Topic';
$string['hotquestionname'] = 'Activity Name';
$string['hotquestionopentime'] = 'Open time';
$string['hotquestionopen'] = 'This activity will be open on {$a}.';
$string['hotquestion:addinstance'] = 'Can add new Hot Question';
$string['hotquestion:ask'] = 'Ask questions';
$string['hotquestion:comment'] = 'Write comments';
Expand All @@ -126,96 +132,88 @@
$string['hotquestion:rate'] = 'Rate questions';
$string['hotquestion:view'] = 'View questions';
$string['hotquestion:vote'] = 'Vote on questions';
$string['hotquestionclosed'] = 'This activity closed on {$a}.';
$string['hotquestionclosetime'] = 'Close time';
$string['hotquestionintro'] = 'Topic';
$string['hotquestionname'] = 'Activity Name';
$string['hotquestionopen'] = 'This activity will be open on {$a}.';
$string['hotquestionopentime'] = 'Open time';
$string['id'] = 'ID';
$string['improperuseviewgradesclass'] = 'Improper use of the viewgrades class. Cannot load the grade item.';
$string['incorrectmodule'] = 'Course Module ID was incorrect';
$string['inputapprovallabel'] = 'Approved';
$string['inputapprovallabel_descr'] = 'Change the Approved column name to what you want it to be.';
$string['inputapprovallabel_help'] = 'Change the Approved column name to better fit the use of this activity.';
$string['inputheatlabel'] = 'Heat';
$string['inputheatlabel_descr'] = 'Change the Heat column name to what you want it to be.';
$string['inputheatlabel_help'] = 'Change the Heat column name to better fit the use of this activity.';
$string['id'] = 'ID';
$string['inputquestion'] = 'Submit your question here:';
$string['inputquestion_descr'] = 'Change submit directions to what you want them to be.';
$string['inputquestion_help'] = 'Change the submit directions to what you want them to be.';
$string['inputquestionlabel'] = 'Questions';
$string['inputquestionlabel_descr'] = 'Change the Questions column name to what you want it to be.';
$string['inputquestionlabel_help'] = 'Change the Questions column name to better fit the use of this activity.';
$string['inputremovelabel'] = 'Remove';
$string['inputremovelabel_descr'] = 'Change the Remove column name to what you want it to be.';
$string['inputremovelabel_help'] = 'Change the remove column name to better fit the use of this activity.';
$string['inputteacherprioritylabel'] = 'Priority';
$string['inputteacherprioritylabel_descr'] = 'Change the Priority column name to what you want it to be.';
$string['inputteacherprioritylabel_help'] = 'Change the Priority column name to better fit the use of this activity.';
$string['inputheatlabel'] = 'Heat';
$string['inputheatlabel_descr'] = 'Change the Heat column name to what you want it to be.';
$string['inputheatlabel_help'] = 'Change the Heat column name to better fit the use of this activity.';
$string['inputremovelabel'] = 'Remove';
$string['inputremovelabel_descr'] = 'Change the Remove column name to what you want it to be.';
$string['inputremovelabel_help'] = 'Change the remove column name to better fit the use of this activity.';
$string['inputapprovallabel'] = 'Approved';
$string['inputapprovallabel_descr'] = 'Change the Approved column name to what you want it to be.';
$string['inputapprovallabel_help'] = 'Change the Approved column name to better fit the use of this activity.';
$string['invalidquestion'] = 'Empty questions are ignored.';
$string['modulename'] = 'Hot Question';
$string['modulename_help'] = 'A Hot Question activity enables students to post and vote on posts, in response to questions asked by course teachers.';
$string['modulename_link'] = 'mod/hotquestion/view';
$string['modulenameplural'] = 'Hot Questions';
$string['newround'] = 'Open a new round';
$string['newroundconfirm'] = 'Confirm you want to start a new round? (Existing questions and votes will be archived and can not be added to!)';
$string['newroundsuccess'] = 'You have successfully opened a new round.';
$string['newroundconfirm'] = 'Confirm you want to start a new round? (Existing questions and votes will be archived and can not be added to!)';
$string['nextround'] = 'Next round';
$string['noquestions'] = 'No entries yet.';
$string['notapproved'] = '<b>This entry is not currently approved for viewing.<br></b>';
$string['notavailable'] = '<b>Not currently available!<br></b>';
$string['notapproved'] = '<b>This entry is not currently approved for viewing.<br></b>';
$string['pluginadministration'] = 'Hot question administration';
$string['pluginname'] = 'Hot Question';
$string['previousround'] = 'Previous round';
$string['postbutton'] = 'Click to post';
$string['postmaxgrade'] = 'Questions for max grading';
$string['postmaxgrade_help'] = 'The number of questions required to obtain the maximum score.
This is nominally a count of questions, but the value attained by a user may be improved by heat factor (questions with greater heat count more)
and by voting on other questions (a user may improve the grade by participating in voting for questions by other students).';
$string['previousround'] = 'Previous round';
$string['prioritydown'] = 'Priority down';
$string['priorityup'] = 'Priority up';
$string['privacy:metadata:hotquestion_questions'] = "Information about the user's entries for a given Hot Question activity. ";
$string['privacy:metadata:hotquestion_questions:anonymous'] = 'Is the entry posted as anonymous?';
$string['privacy:metadata:hotquestion_questions:approved'] = 'Is the question approved for general viewing?';
$string['privacy:metadata:hotquestion_questions:content'] = 'The content of the question.';
$string['privacy:metadata:hotquestion_questions:userid'] = 'The ID of the user that posted this entry.';
$string['privacy:metadata:hotquestion_questions:hotquestion'] = 'The ID of the Hot Question activity in which the content was posted.';
$string['privacy:metadata:hotquestion_questions:id'] = 'ID of the entry.';
$string['privacy:metadata:hotquestion_questions:content'] = 'The content of the question.';
$string['privacy:metadata:hotquestion_questions:time'] = 'Time the question was posted.';
$string['privacy:metadata:hotquestion_questions:id'] = 'ID of the entry.';
$string['privacy:metadata:hotquestion_questions:anonymous'] = 'Is the entry posted as anonymous?';
$string['privacy:metadata:hotquestion_questions:approved'] = 'Is the question approved for general viewing?';
$string['privacy:metadata:hotquestion_questions:tpriority'] = 'Has the teacher given a priority for this entry?';
$string['privacy:metadata:hotquestion_questions:userid'] = 'The ID of the user that posted this entry.';
$string['privacy:metadata:hotquestion_votes'] = 'Information about votes on questions.';
$string['privacy:metadata:hotquestion_votes:id'] = 'ID of the entry.';
$string['privacy:metadata:hotquestion_votes:question'] = 'The ID of the entry for this vote';
$string['privacy:metadata:hotquestion_votes:voter'] = 'User ID who voted.';
$string['teacherprioritylabel'] = 'Priority column label';
$string['teacherprioritylabel_descr'] = 'Enter a default label for the Priority column.';
$string['question'] = 'Question';
$string['questions'] = 'Questions';
$string['questionlabel'] = 'Questions column label';
$string['questionlabel_descr'] = 'Enter a default label for the Questions column.';
$string['questionsubmitted'] = 'Your post has been submitted successfully.';
$string['questionremove'] = 'Remove';
$string['questionremovesuccess'] = 'You have successfully removed that question.';
$string['questions'] = 'Questions';
$string['questionsubmitted'] = 'Your post has been submitted successfully.';
$string['rawgrade'] = 'Raw grade {$a->rawgrade} / {$a->max}';
$string['removedround'] = 'You have successfully removed this round.';
$string['removelabel'] = 'Remove column label';
$string['removelabel_descr'] = 'Enter a default label for the Remove column.';
$string['removeround'] = 'Remove this round';
$string['removedround'] = 'You have successfully removed this round.';
$string['removevote'] = 'Remove my vote';
$string['requireapproval'] = 'Approval required';
$string['requireapproval_descr'] = 'If enabled, questions require approval by a teacher before they are viewable by everyone.';
$string['requireapproval_help'] = 'If enabled, questions require approval by a teacher before they are viewable by everyone.';
$string['requireapproval_descr'] = 'If enabled, questions require approval by a teacher before they are viewable by everyone.';
$string['resethotquestion'] = 'Delete all questions and votes';
$string['returnto'] = 'Return to {$a}';
$string['round'] = 'Round {$a}';
$string['showrecentactivity'] = 'Show recent activity';
$string['showrecentactivityconfig'] = 'Everyone can see notifications in recent activity reports.';
$string['teacherpriority'] = 'Priority';
$string['teacherprioritylabel'] = 'Priority column label';
$string['teacherprioritylabel_descr'] = 'Enter a default label for the Priority column.';
$string['teacherpriorityvisibility'] = 'Teacher priority column visibility';
$string['teacherpriorityvisibility_descr'] = 'If enabled, the Teacher priority column is visible, otherwise it is hidden.';
$string['teacherpriorityvisibility_help'] = 'If enabled, the Teacher priority column is visible.';
$string['teacherpriorityvisibility_descr'] = 'If enabled, the Teacher priority column is visible, otherwise it is hidden.';
$string['time'] = 'Time';
$string['totalcomments'] = 'Total comments';
$string['unapprovedquestionhide'] = 'Hide unapproved questions';
Expand Down
Loading

0 comments on commit f4b98f1

Please sign in to comment.