Add a custom user field to the certificate

Re: Add a custom user field to the certificate

by Daniel Dubbeldam -
Number of replies: 5

when adding a custom rule to a certificate, I want to add a custom profile field to my certificate. 
it's the "date of birth" (geboortedatum) of the user.

I've added the following rule: 

certificate_print_text($pdf, $x + 55, $y + 53, 'L', 'freesans', '', 14, $USER->profile['geboortedatum']);


However, the date that is printed on my certificate is now in a unix timestamp instead of human readable format..

How do I now convert this unix timestamp to the normal format in my certificate?????

thnx!

In reply to Daniel Dubbeldam

Re: Add a custom user field to the certificate

by Daniel Dubbeldam -

is there someone that knows this answer? it's kinda strange to give out a certificate with "born on 446338800" on it ;) surely there must be someone that knows how to convert this on the  certificate?

In reply to Daniel Dubbeldam

Re: Add a custom user field to the certificate

by Jean-Michel Védrine -

Hello Daniel,

Something like

certificate_print_text($pdf, $x + 55, $y + 53, 'L', 'freesans', '', 14, userdate($USER->profile['geboortedatum'], '%B %d, %Y'));

should do the trick.

If the date is not formatted as you want, you must modify the '%B %d, %Y' for instance '%d %B %Y' may suit your needs better.

To learn all the formats available for dates, you can read https://php.net/manual/en/function.strftime.php

In reply to Jean-Michel Védrine

Re: Add a custom user field to the certificate

by Wendi Daniels -

fow whatever reason, I am not able to call a piece of data from the database in quiz_attempts. How the hell do I do this? I have been able to program 2 columns in this table, and they are called "certificate" and "certid". If they pass the test, then "certificate" will equal "1" (otherwise, it is "0").

 

ONLY IF it "certificate" equals "1", then I need the certificate to recall the "certid" that is associated with that individual attempt.

    

I added this to the beginning of the certificate.php file:

*************************************************************************************

  

require_once($CFG->dirroot.'/user/profile/lib.php');

profile_load_data($USER); 

  

***************************************************************************************

 

and I have tried these lines....

******************************************************************************************

 

certificate_print_text($pdf, $x, $y + 210, 'C', $fontserif, '', 30, 'Certificate # ' . $USER->profile['certid']);

certificate_print_text($pdf, $x, $y + 210, 'C', $fontserif, '', 30, 'Certificate # ' . $USER->'certid');

certificate_print_text($pdf, $x, $y + 210, 'C', $fontserif, '', 30, 'Certificate # ' . $attempts->['certid']);

certificate_print_text($pdf, $x, $y + 210, 'C', $fontserif, '', 30, 'Certificate # ' . $attempts->certid);

certificate_print_text($pdf, $x, $y + 210, 'C', $fontserif, '', 30, 'Certificate # ' . $USER->attempts['certid']);


...and several others. I'm at the end of my rope. Can anyone guide me? I am only following examples and going by trial and error. I don't know how to do this sort of thing.


Please help...

In reply to Wendi Daniels

Re: Add a custom user field to the certificate

by Wendi Daniels -

Jean-Michel, do you have an idea? You usually have wonderful ideas and I would love your insights.

In reply to Wendi Daniels

Re: Add a custom user field to the certificate

by Wendi Daniels -
I see my error...I have added a column to the table quiz_attempts, and I want to add the value of that column to the certificate. This value is an id number that I automatically receive from another entity (the student passes the test, the API automatically sends the information to the state and receives a confirmation number, that number is stored in a column in quiz_attempts).
 
  
So, what I need to know is how to I either shift that value to a user profile field in user_info_fields, or how do I recall that data from a column in quiz_attempts?
 
 
A programmer who made the API a while ago created lines similar to this line in the api, and I added this and created the column in quiz_attempts:

$DB->set_field('quiz_attempts', 'certid', (result from the entity), array('id' => $attemptid));
 
 
Seeing my error, I added a user profile field, made it invisible, and added this line in the api, but it is not working:
 
$DB->set_field('user_info_field', 'certidnew', (result from the entity), array('id' => $attemptid));
 
 
I am thinking that "field" refers to the column, but what would refer to a student's value in one particular column, and how would I properly program that?