User Profile Fileds in Certificate

User Profile Fileds in Certificate

by Rhonda Goetz -
Number of replies: 15
Hello,
I hope someone will be able to help me with this. I've managed to modify my certificate quite nicely with all the documentation, except for this one area:

I am trying to figure out how to get the State filed and a License field that I created in the User Profile to show up on the certificate. It is in a category called Licensing Information. I am using 1.9.3 and am having no luck.

This data resides in the user_info_fields table and I cannot figure out how to get it to show up in the Certificate.

Any suggestions or a nudge in the right direction would be appreciated.

Rhonda
Average of ratings: -
In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Rhonda Goetz -
Ok - I see no one has an answer - well is there someone I can pay that can do this for me? Can someone direct me to someone who does these modifications? I need to get two user-profile fields to show up on my certificate.

Thank you. Rhonda
In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Brett Hallongren -

Rhonda:

I added some fields to my certs and it wasn't too hard. There are directions on how to do it in the certificate documentation.  I'm only in 1.8.x but this should also work for 1.9 I would think.  Hope this helps.

Printing Info from a Profile Field:

You can easily add additional personal student information to print on a certificate.

1. Choose one of the user profile fields for your info, good choices are: ID Number, Institution or Department.

2. Same as step 2 from 'Adding a New Line of Text' above.

3. Add a new line below that to print your info like this:

cert_printtext(170, 350, 'C', 'Times', , 10, utf8_decode($USER->idnumber));

Or, change idnumber to institution, or department.

4. Same as step 4 from 'Adding a New Line of Text' above.

In reply to Brett Hallongren

Re: User Profile Fileds in Certificate

by Rhonda Goetz -
Thank you, I can get the profile field information into the certificate, what I can't get is the optional fields that reside in the User_info_data table in the database. I created a license and a state parameter under a category called Licensing Information and need those two fields to come up.

It seems that I need to map to that data somehow. Which is out of my expertise. Rhonda
In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Brett Hallongren -

OK, I misunderstood your question.  That's beyond my knowledge also.  Sorry I couldn't help.

In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Remi Smith -
Rhonda,

I have been working on this also, and may have something in a week or so. I'll post it here when I do.

Do you have a time that you need to have this implemented by?

Thanks

Remi
In reply to Remi Smith

Re: User Profile Fileds in Certificate

by Rhonda Goetz -
Thank you Remi,

I need it as soon as you can get it. Thanks for that! The extra profile fields were such a great addition, but now I need to do more with them! Thanks! Rhonda
In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
I see Remi has already offered to do this work which is great! - Rhonda if there's anything else you get stuck with, and you don't get much help in the forums, you can also contact your local Moodle Partner who should be able to help with any modifications you might need.

(I work for a Moodle Partner in NZ)
In reply to Dan Marsden

Re: User Profile Fileds in Certificate

by Remi Smith -
Hi Rhonda,

Ok, this took me much longer than expected, mostly because of my pesky day job.

Here's what I have...it essentially creates an associative array of your user profile fields, so you can later call them in your certificate file...on my wishlist, would be to create a custom user data object, so we could refer to the fields like $userfields->Cardnumber (so its the same as the $certdata obj). Maybe this weekend I can get to that, but just wanted to put this out there as soon as I figured something out.

In view.php, add the following lines after line 67 ($certrecord = get_record('certificate_issues', 'certificateid', $certificateid, 'userid', $USER->id);):

 // Custom Query For User Profile Fields
 $sql = "SELECT f.shortname, d.data FROM `".$CFG->prefix."user_info_data` d, `".$CFG->prefix."user_info_field` f WHERE f.id=d.fieldid AND userid = ".$USER->id.";";
 $result = get_records_sql($sql);
 if ($result) {
 foreach($result as $key=>$value) {
 $extended_user_data[$value->shortname]=$value->data;
 }
 }
 // End Custom Query Section
Then, add lines such as the following to your certificate.php file:
cert_printtext(150, 150, 'C', 'Times', '', 30, utf8_decode("TEST: ".$extended_user_data['<YourFieldHere>']));
The <YourFieldHere> part is replaced by the shortname of the custom field you need displayed.

I have put the view.php file on here as an attachment, though I can't promise that what I have is the latest and greatest...sometime soon I need to figure out CVS! Let me know if you want that...or drop me a line or post here for any other questions you have on this.

Hope this helps!!

Remi
Average of ratings: Useful (1)
In reply to Remi Smith

Re: User Profile Fileds in Certificate

by Rhonda Goetz -
This worked so beautifully! You are my hero and I bet quite a few others as well! Thank you!!! Chardelle, we need to incorporate this into the stable version.

Thank you again! Rhonda
In reply to Rhonda Goetz

Re: User Profile Fileds in Certificate

by Remi Smith -
Glad I was able to help!

Chardelle, I have gotten into the read only CVS and retrieved the latest code. There are a few other things that I have done to the certificate that I would like to pass on, should I go through you or get my own account?
In reply to Remi Smith

Re: User Profile Fileds in Certificate

by Chardelle Busch -
Picture of Core developers
I haven't tried this, but an easier way might be to add this to a custom certificate type file (so you don't have to hack core certificate files):

$customfield = get_record_select("user_info_data", "fieldid='3' AND userid='$USER->userid'");

$customfieldinfo = $customfield->data;

Where the '3' is your custom field id (you'll see this in the link to your custom field). Then go ahead and add the print text line for $customfieldinfo.

If this works, you might want to add it to the certificate customization docs.

Average of ratings: Useful (2)
In reply to Chardelle Busch

Re: User Profile Fileds in Certificate

by Alice Mello -
Hi Chardelle and Remi,

I had the same issue as Rhonda and tried Chardelle solution, but it did not work. Reni's solutions worked fine.
Now my question is: how do I populate the data field? There is a topic 0 which has several questions and one of those contains the "data" I want to use to ppulate the data field at the user_info_data table. In this topic 0 the student enters name, e-mail, etc.
I am new in Moodle and I never defined a course or anything like that, but I am trying to create different types of certificates with dependencies.
Thank you for answering my question,
Alice
In reply to Chardelle Busch

Re: User Profile Fileds in Certificate

by Lester Cunningham -
Chardelle,

This works really well. Thank you. However, if anyone else is trying this there is a small typo in your code and should read:

$customfield = get_record_select("user_info_data", "fieldid='3' AND userid='$USER->id'");

$customfieldinfo = $customfield->data;

Where the '3' is your custom field id (you'll see this in the link to your custom field). Then go ahead and add the print text line for $customfieldinfo.

Cheers.
Average of ratings: Useful (2)
In reply to Lester Cunningham

Re: User Profile Fileds in Certificate

by Donna Smith -

I'm trying to do the same thing but have been unsuccessful. I'm sure it's placement. Where in the certificate.php did you place:

$customfield = get_record_select("user_info_data", "fieldid='3' AND userid='$USER->id'");

$customfieldinfo = $customfield->data;

Thanks for any help.

In reply to Donna Smith

Re: User Profile Fileds in Certificate

by Buck William -

Correction for this to work with Moodle 2.0+, there is a global $DB object that we need to reference,

$customfield = $DB->get_record_select("user_info_data", "fieldid='3' AND userid='$USER->id'");
$customfieldinfo = $customfield->data;

Average of ratings: Useful (1)