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
Thank you. Rhonda
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.
It seems that I need to map to that data somehow. Which is out of my expertise. Rhonda
OK, I misunderstood your question. That's beyond my knowledge also. Sorry I couldn't help.
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
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
(I work for a Moodle Partner in NZ)
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 SectionThen, 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
Thank you again! Rhonda
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?
$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.
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
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.
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.
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;