From 947f21dc6090299146eb14ad0a69a22e58de17e2 Mon Sep 17 00:00:00 2001 From: Farhan Karmali Date: Tue, 14 Nov 2023 23:12:53 -0500 Subject: [PATCH] General fixes for issues in test pipeline --- classes/event/comments_viewed.php | 17 ------- classes/privacy/provider.php | 73 +++++++++++++++++++++++++++ lang/en/hotquestion.php | 3 ++ locallib.php | 4 +- mod_form.php | 2 + tests/behat/behat_mod_hotquestion.php | 10 +--- 6 files changed, 81 insertions(+), 28 deletions(-) diff --git a/classes/event/comments_viewed.php b/classes/event/comments_viewed.php index ebfcbb3..6e80660 100644 --- a/classes/event/comments_viewed.php +++ b/classes/event/comments_viewed.php @@ -55,23 +55,6 @@ public function get_description() { "'{$this->other['comment']}' for the hot question activity with course module id '$this->contextinstanceid'."; } - /** - * Return the legacy event log data. - * - * @return array - */ - protected function get_legacy_logdata() { - return( - [ - $this->courseid, - 'hotquestion', - 'comments', - 'comments.php?pageid=' . $this->objectid, - $this->objectid, $this->contextinstanceid, - ] - ); - } - /** * Get URL related to the action. * diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index c8d31aa..90b38ad 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -82,6 +82,15 @@ public static function get_metadata(collection $collection): collection { ], 'privacy:metadata:hotquestion_votes' ); + + $collection->add_database_table( + 'hotquestion_grades', + [ + 'userid' => 'privacy:metadata:hotquestion_grades:userid', + 'rawrating' => 'privacy:metadata:hotquestion_grades:rawrating', + ], + 'privacy:metadata:hotquestion_grades' + ); return $collection; } @@ -181,6 +190,24 @@ public static function get_users_in_context(userlist $userlist) { WHERE ctx.id = :contextid "; $userlist->add_from_sql('userid', $sql, $params); + + $sql = " + SELECT hqg.userid + FROM {hotquestion_grades} hqg + JOIN {hotquestion_questions} hq + ON hq.id = hqg.hotquestion + JOIN {hotquestion} h + ON h.id = hq.hotquestion + JOIN {course_modules} cm + ON cm.instance = h.id + AND cm.module = :modid + JOIN {context} ctx + ON ctx.instanceid = cm.id + AND ctx.contextlevel = :contextlevel + WHERE ctx.id = :contextid + "; + $userlist->add_from_sql('userid', $sql, $params); + } /** * Export personal data for the given approved_contextlist. User and context information is contained within the contextlist. @@ -287,6 +314,45 @@ public static function export_user_data(approved_contextlist $contextlist) { if ($itemdata) { self::export_hotquestion_data_for_user($itemdata, $lastcmid, $user); } + + // Export grades. + $user = $contextlist->get_user(); + list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED); + + $sql = "SELECT hqg.id AS id, + cm.id AS cmid, + hqg.hotquestion AS hotquestion, + hqg.id AS id, + hqg.userid AS userid, + hqg.rawrating as rating, + hqg.timemodified as timemodified + FROM {context} c + INNER JOIN {course_modules} cm + ON cm.id = c.instanceid + LEFT JOIN {hotquestion_questions} hq + ON hq.hotquestion = cm.instance + LEFT JOIN {hotquestion_grades} hqg + ON hqg.hotquestion = hq.id + WHERE c.id $contextsql + AND hqg.userid = :userid + ORDER BY cm.id, hq.id DESC"; + + $params = [ + 'userid' => $user->id, + ] + $contextparams; + + $records = $DB->get_records_sql($sql, $params); + foreach ($records as $record) { + $context = \context_module::instance($record->cmid); + $data = (object)[ + 'hotquestion' => $record->hotquestion, + 'grade' => $record->rating, + 'time' => transform::datetime($record->timemodified) + ]; + writer::with_context($context)->export_data([get_string('privacy:metadata:hotquestion_grades:path', + 'mod_hotquestion')], $data); + } + } @@ -390,6 +456,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { list($isql, $params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); $params['userid'] = $userid; $DB->delete_records_select('hotquestion_votes', "id $isql AND voter = :userid", $params); + $DB->delete_records_select('hotquestion_grades', "id $isql AND userid = :userid", $params); $params = ['instanceid' => $cm->instance, 'userid' => $userid]; $DB->delete_records_select('hotquestion_questions', 'hotquestion = :instanceid AND userid = :userid', $params); } @@ -434,5 +501,11 @@ public static function delete_data_for_users(approved_userlist $userlist) { "voter $insql AND id $itsql", array_merge($inparams, $itparams) ); + + // Delete hot questions grades. + $DB->delete_records_select('hotquestion_grades', + "userid $insql AND hotquestion $itsql", + array_merge($inparams, $itparams) + ); } } diff --git a/lang/en/hotquestion.php b/lang/en/hotquestion.php index 5b4aa5b..eb5a96b 100644 --- a/lang/en/hotquestion.php +++ b/lang/en/hotquestion.php @@ -176,6 +176,9 @@ 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['privacy:metadata:hotquestion_grades'] = 'Grading data for hotquestion instances'; +$string['privacy:metadata:hotquestion_grades:userid'] = 'The ID of the user that posted this grade.'; +$string['privacy:metadata:hotquestion_grades:rawrating'] = 'Raw rating'; $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?'; diff --git a/locallib.php b/locallib.php index 562456c..21ba907 100644 --- a/locallib.php +++ b/locallib.php @@ -568,7 +568,7 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; if (is_siteadmin($USER->id)) { // For an admin, we want every hotquestion activity. - $whichhqs = ('AND hq.hotquestion > 0'); + $whichhqs = ('AND hq.hotquestion IS NOT NULL'); $csv->filename = clean_filename(get_string('exportfilenamep1', 'hotquestion')); } else { // For a teacher, we want only the current hotquestion activity. @@ -662,7 +662,7 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; if ($hqs = $DB->get_records_sql($sql, $fields)) { $firstrowflag = 1; if (is_siteadmin($USER->id)) { - $currenthqhotquestion = $hqs[1]->hotquestion; + $currenthqhotquestion = !empty($hqs[1]->hotquestion) ? $hqs[1]->hotquestion : 'Hotquestion'; } else { $currenthqhotquestion = ''; } diff --git a/mod_form.php b/mod_form.php index d057a07..4e1bfa9 100644 --- a/mod_form.php +++ b/mod_form.php @@ -253,6 +253,7 @@ public function definition() { // Add standard buttons, common to all modules. $this->add_action_buttons(); + $this->_form->disable_form_change_checker(); } /** @@ -425,5 +426,6 @@ public function definition() { $mform->setType('anonymous', PARAM_BOOL); } $mform->addGroup($submitgroup); + $this->_form->disable_form_change_checker(); } } diff --git a/tests/behat/behat_mod_hotquestion.php b/tests/behat/behat_mod_hotquestion.php index 6c84477..606f9e5 100644 --- a/tests/behat/behat_mod_hotquestion.php +++ b/tests/behat/behat_mod_hotquestion.php @@ -40,7 +40,7 @@ class behat_mod_hotquestion extends behat_base { /** * Step to open current course or activity settings page (language string changed between 3.11 and 4.0) * - * @When /^I open course or activity settings page$/ + * @When /^I open course or activity (hotquestion) settings page$/ * @return void */ public function i_open_course_or_activity_settings_page(): void { @@ -118,12 +118,4 @@ protected function get_cm_by_hotquestion_name(string $name): stdClass { return get_coursemodule_from_instance('hotquestion', $hotquestion->id, $hotquestion->course); } - /** - * Wait for x seconds. - * - * @Then I wait :arg1 seconds - */ - public function iwaitseconds($arg1) { - throw new PendingException(); - } }