From 2a9640b5a397d655646c9e01293b4da3710519d4 Mon Sep 17 00:00:00 2001 From: hieuvu Date: Wed, 20 Oct 2021 14:03:23 +0700 Subject: [PATCH] Fix error message when we have custom profile fields (#465) --- classes/certificate.php | 13 +++++++++---- tests/behat/view_issued_certificates.feature | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/classes/certificate.php b/classes/certificate.php index 7f4a09c..5a4071b 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -274,11 +274,16 @@ class certificate { $extrafields = \core_user\fields::for_identity($context)->get_required_fields(); $ufields = \core_user\fields::for_userpic()->including(...$extrafields); - $ufields = $ufields->get_sql('u', false, '', '', false)->selects; - $sql = "SELECT $ufields, ci.id as issueid, ci.code, ci.timecreated + [ + 'selects' => $userfieldsselects, + 'joins' => $userfieldsjoin, + 'params' => $userfieldsparams + ] = (array) $ufields->get_sql('u', true); + $allparams = array_merge($allparams, $userfieldsparams); + $sql = "SELECT ci.id as issueid, ci.code, ci.timecreated $userfieldsselects FROM {user} u - INNER JOIN {customcert_issues} ci - ON u.id = ci.userid + INNER JOIN {customcert_issues} ci ON u.id = ci.userid + $userfieldsjoin WHERE u.deleted = 0 AND ci.customcertid = :customcertid $conditionssql"; diff --git a/tests/behat/view_issued_certificates.feature b/tests/behat/view_issued_certificates.feature index f8cb0a5..c8ffd10 100644 --- a/tests/behat/view_issued_certificates.feature +++ b/tests/behat/view_issued_certificates.feature @@ -21,6 +21,8 @@ Feature: Being able to view the certificates that have been issued And the following "activities" exist: | activity | name | intro | course | idnumber | | customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | + And the following config values are set as admin: + | showuseridentity | username,email | Scenario: View the issued certificates And I log in as "student1" @@ -38,6 +40,12 @@ Feature: Being able to view the certificates that have been issued And I follow "Custom certificate 1" And I should see "Student 1" And I should see "Student 2" + And I should see "Email address" + And I should see "Username" + And "Student 1" row "Email address" column of "generaltable" table should contain "student1@example.com" + And "Student 1" row "Username" column of "generaltable" table should contain "student1" + And "Student 2" row "Email address" column of "generaltable" table should contain "student2@example.com" + And "Student 2" row "Username" column of "generaltable" table should contain "student2" Scenario: Delete an issued certificate And I log in as "student1"