mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
91 stars 158 forks source link

Error thrown when we have custom profile fields for Moodle 3.11 #465

Closed vuvanhieu143 closed 2 years ago

vuvanhieu143 commented 2 years ago

Hi @mdjnelson , I found out there will be an error when we have custom fields in user profile This code should include the join and params for custom 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 FROM {user} u INNER JOIN {customcert_issues} ci ON u.id = ci.userid WHERE u.deleted = 0 AND ci.customcertid = :customcertid $conditionssql"; if ($sort) { $sql .= "ORDER BY " . $sort; } else { $sql .= "ORDER BY " . $DB->sql_fullname(); }

These are the code changes that will fix this issue.

$ufields = \core_user\fields::for_userpic()->including(...$extrafields); [ '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
                $userfieldsjoin
             WHERE u.deleted = 0
               AND ci.customcertid = :customcertid
                   $conditionssql";

Sorry, I can't submit a PR right now because I'm busy with my work. I will submit a PR later.

Could you please take a look and give me your thought on this issue.

mdjnelson commented 2 years ago

Thanks @vuvanhieu143. Looks like it works. This has been mentioned in the forums and in another issue but I could not replicate it so I appreciate you coming up with a solution and a PR.

vuvanhieu143 commented 2 years ago

Thanks, @mdjnelson ,I will submit a PR and behat scenario for this case later.

vuvanhieu143 commented 2 years ago

Hi @mdjnelson , I have submitted a PR

466

mdjnelson commented 2 years ago

Cherry-picked, thanks for your contribution!

codigo-iot commented 2 years ago

This problem has reappeared in version 4.0+