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
89 stars 155 forks source link

Attempting to add Date feature to Verify Certificate #587

Closed terriroshell closed 4 months ago

terriroshell commented 8 months ago

I had to edit three files in the mod_customcert file. Special thanks to [Jeffrey Olivo], I followed his template on making the change.

The file locations are listed below to get this: However the date shown is the date the activity was created. I can't figure out how to get the user certificate timecreated to work. image

LOCATION: /home//public_html/lms/mod/customcert/verify_certificate.php

     $[sql](https://moodle.org/mod/glossary/showentry.php?eid=6851&displayformat=dictionary) = "SELECT ci.id, u.id as userid, $userfields, co.id as courseid,

               co.fullname as coursefullname, c.id as certificateid,

               c.name as certificatename, **FROM_UNIXTIME(c.timecreated,'%m-%d-%Y') as timecreated**, c.verifyany

          FROM {customcert} c

          JOIN {customcert_issues} ci

            ON c.id = ci.customcertid

          **JOIN {customcert} ct

            ON c.timecreated = c.timecreated**

          JOIN {course} co

            ON c.course = co.id

          JOIN {user} u

            ON ci.userid = u.id

         WHERE ci.code = :code";

LOCATION: /home//public_html/lms/mod/customcert/classes/output/verify_certificate_result.php

**/**

 * @var string Awarded on date.

 * /

public $timecreated;**

/**

 * Constructor.

 *

 * @param \stdClass $result

 */

public function __construct($result) {

    $cm = get_coursemodule_from_instance('customcert', $result->certificateid);

    $[context](https://moodle.org/mod/glossary/showentry.php?eid=9984&displayformat=dictionary) = \context_module::instance($cm->id);

    $this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid,

        'course' => $result->courseid));

    $this->userfullname = fullname($result);

    $this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid));

    $this->coursefullname = format_string($result->coursefullname, true, ['context' => $context]);

    $this->certificatename = format_string($result->certificatename, true, ['context' => $context]);

    **$this->timecreated = format_string($result->timecreated, true, ['context => $context']);**

}

/**

 * Function to export the renderer data in a format that is suitable for a mustache template.

 *

 * @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.

 * @return \stdClass|array

 */

public function export_for_template(\renderer_base $output) {

    $result = new \stdClass();

    $result->userprofileurl = $this->userprofileurl;

    $result->userfullname = $this->userfullname;

    $result->coursefullname = $this->coursefullname;

    $result->courseurl = $this->courseurl;

    $result->certificatename = $this->certificatename;

    **$result->timecreated = $this->timecreated;**

    return $result;

}

LOCATION: /home//public_html/lms/mod/customcert/templates/verify_certificate_result.mustache

terriroshell commented 8 months ago

I finally figured it out.
/mod/customcert/verify_certificate.php line 95 // Ok, now check if the code is valid. $userfields = \mod_customcert\helper::get_all_user_name_fields('u'); $sql = "SELECT ci.id, u.id as userid, $userfields, co.id as courseid, co.fullname as coursefullname, c.id as certificateid, c.name as certificatename,FROM_UNIXTIME(ci.timecreated,'%m-%d-%Y') as timecreated, c.verifyany FROM {customcert} c JOIN {customcert_issues} ci ON c.id = ci.customcertid JOIN {customcert_issues} ct ON ci.timecreated = ct.timecreated JOIN {course} co ON c.course = co.id JOIN {user} u ON ci.userid = u.id WHERE ci.code = :code";

mdjnelson commented 4 months ago

Glad you got this solved.