Topic instead of Course.name

Topic instead of Course.name

by Kennet Ståhl -
Number of replies: 21

Where do I change so that the certificate shows the name of the topic instead of the Course name? Version 2.0

Average of ratings: -
In reply to Kennet Ståhl

Re: Topic instead of Course.name

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

The certificate types (mod/certificate/type) are responsible for printing out the text on the certificate pdf. If you wanted to add the topic to the certificate, you would need to edit the certificate.php file in the type you are using for that certificate.

In reply to Mark Nelson

Svar: Re: Topic instead of Course.name

by Kennet Ståhl -

Thanks for your reply. Do you know how that line should look?

Guess it should be in this section but don´t know the string for the topic nor for the coursename.

// Add text
    $pdf->SetTextColor(0,0,120);
    cert_printtext($pdf, $x, $y, 'C', 'Helvetica', '', 30, get_string('title', 'certificate'));
    $pdf->SetTextColor(0,0,0);
    cert_printtext($pdf, $x, $y+20, 'C', 'Times', '', 20, get_string('certify', 'certificate'));
    cert_printtext($pdf, $x, $y+36, 'C', 'Helvetica', '', 30, $studentname);
    cert_printtext($pdf, $x, $y+55, 'C', 'Helvetica', '', 20, get_string('statement', 'certificate'));
    cert_printtext($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $classname);
    cert_printtext($pdf, $x, $y+92, 'C', 'Helvetica', '', 14, $certificatedate);
    cert_printtext($pdf, $x, $y+102, 'C', 'Times', '', 10, $grade);
    cert_printtext($pdf, $x, $y+112, 'C', 'Times', '', 10, $outcome);
    cert_printtext($pdf, $x, $y+122, 'C', 'Times', '', 10, $credithours);
    cert_printtext($pdf, $x, $codey, 'C', 'Times', '', 10, $code);

In reply to Kennet Ståhl

Re: Svar: Re: Topic instead of Course.name

by Jean-Michel Védrine -

Hello Kennet,

The line that is printing the course name is :

cert_printtext($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $classname);

But I am not sure of what you mean when you say "topic".

Do you mean the course's section name (each course is divided into sections and this sections are called topics if you have choosen the topics course format (see course formats documentation) but sections names can be something different from topics if you have choosen another course format. There even exists some course formats that aren't divided in sections.

If yes then the change to do is not a very simple one because you need some php code to retreive the section name for the section containing the certificate instance. This is not a simple "string for the topic" and I don't know if somebody has already done this code.

 
In reply to Jean-Michel Védrine

Svar: Re: Svar: Re: Topic instead of Course.name

by Kennet Ståhl -

Hi

Yes I´m using the topic course format and it is the name of the topic I want to print on the certificate. I do it that way to get the structure a bit more compact since I have 7 courses each containing between 7-15 tests instead of having around 70 courses.

It sounds like it is more complicated than I thought. Maybe it is better to put some effort to the gradebook and skip the certificate. A certificate is though very appreciated by the students taking courses.

Thanks for all your help.

In reply to Kennet Ståhl

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Jean-Michel Védrine -

Well I think I can help a little more wink

Replace the line

cert_printtext($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $classname);

With the lines :

    $usesections = course_format_uses_sections($course->format);
    if ($usesections) {
        $currentsection = $DB->get_record('course_sections', array('id'=>$cm->section));

        if ($currentsection) {
            $printsection = get_section_name($course, $currentsection);
            cert_printtext($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $printsection);

        }
    }

And see if it gives what you want.

Average of ratings: Useful (6)
In reply to Jean-Michel Védrine

Svar: Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Kennet Ståhl -

You are a genius!
Works like a dream

Thank you so very much. It saved me a lot of time. No I can continue building the structure.

Thank you once again

/Kennet

In reply to Jean-Michel Védrine

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Chris Collman -
Picture of Documentation writers

Very nice solution for  a problem I did not know I had!   Great question for this forum.   

One course that has 5 levels of certification, with each level having at least an exam and a certificate.   Each certificate uses the topic name, each level linked via conditional dependencies.   Compact!   

In reply to Chris Collman

Re: Topic instead of Course.name

by Stuart Mealor -

Shouldn't we just a totally flexible solution for this ?

In the Certificate settings page, have a dropdown to choose between the Course name, or Topic.

Even better, a tect field that allows us to name the Certificate whatever we want !  (I can't see why the name of the Certificate must be restricted to the Course name or any other value to be honest?)

Stu

In reply to Jean-Michel Védrine

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Great work Jean,

Thanks for doing my job! big grin

In reply to Jean-Michel Védrine

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Penny Mondani -

With every great solution comes another idea that "needs" a solution!  I would like to go the other way...and print the Category instead of the Course name, awarding the certificate in the final course of each category only.  I can't for the life of me figure out what the category variable name is.

I tried category, course_category, and category name, all in the line: cert_printtext($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $classname);

Is it this simple and if it is, what is the variable name?

Thanks!!

Penny

In reply to Penny Mondani

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Penny,

The category name has not been assigned a variable, simply using a variable with the same name as the attribute you want won't return it! big grin

You will need to add the following code to your type/<thetypeyouareusing>/certificate.php file -

$category = $DB->get_record('course_categories', array('id'=>$course->category));

You can then access the category name using $category->name

Regards,

Mark

In reply to Jean-Michel Védrine

Re: Svar: Re: Svar: Re: Topic instead of Course.name

by Duncan Croucher -

Thanks Jean-Michel, thats worked a treat.

 

Dunk

In reply to Kennet Ståhl

Re: Topic instead of Course.name

by Cyndy Pederson -

How does this work for version 2.3?  I can't seem to find the right certificate_print_text...

In reply to Cyndy Pederson

Re: Topic instead of Course.name

by Jean-Michel Védrine -

Hello Cindy

In the latest version of the certificate module the line that print the course name is something like :

certificate_print_text($pdf, $x, $y + 72, 'C', 'Helvetica', '', 20, $course->fullname);

In reply to Jean-Michel Védrine

Re: Topic instead of Course.name

by Cyndy Pederson -

Thanks, Jean-Michel.


I did find that line, I just wasn't sure what to change it to so it would print the topic correctly.

In reply to Jean-Michel Védrine

Re: Topic instead of Course.name

by Glenn Sisson -

Hi Jean,

I am using the latest version. I replace the line:

certificate_print_text($pdf, $x, $y + 72, 'C', 'Helvetica', '', 20, $course->fullname);

with your suggested code above but it does not work. I get a blank screen.

Should your suggested replacement text work with the latest version? If not, can you please help by advising what the replacement code should be.

In reply to Glenn Sisson

Re: Topic instead of Course.name

by Jean-Michel Védrine -

Hello,

I have given that code to help, but I don't use it myself so I don't really know if it works in 2.3.1+. Unfortunately I don't have my development computer with me, so I can't do any test.

My first idea is to replace cert_printtext with certificate_print_text in the code because this function has changed name in the certificate module.

$usesections = course_format_uses_sections($course->format);
    if ($usesections) {
        $currentsection = $DB->get_record('course_sections', array('id'=>$cm->section));

        if ($currentsection) {
            $printsection = get_section_name($course, $currentsection);
            certificate_print_text($pdf, $x, $y+72, 'C', 'Helvetica', '', 20, $printsection);

        }
    }

If this suggestion don't fix the problem I will be able to do some tests and suggest a corrected code in 1 day or 2.

In reply to Jean-Michel Védrine

Re: Topic instead of Course.name

by Glenn Sisson -

Works perfectly. Thanks a million.

In reply to Glenn Sisson

Re: Topic instead of Course.name

by Cath Trew -

Could someone tell me where I need to go to find this code?  I am very new to Moodle and know hardly anything about programming and other such techie stuff!!  Thank you!

In reply to Cath Trew

Re: Topic instead of Course.name

by Jean-Michel Védrine -

Hello Cath,

I understand you are new to Moodle but please instead of posting your question in an existing thread, it would be a lot better to create a new topic with a sensible name, because it will be a lot easier for other people coming with the same problem to find it and you will also see that it increase the chance that somebody answer your question smile

Questions buried in old threads are very uneasy to find when you search the forum.

That said, I will answer your question

When you create a new certificate, you choose a "certificate type" : something like A4 Embedded, A4 Non-Embedded, Letter Embedded, ...

For each certificate type there is a corresponding subfolder : for A4 Embedded it's mod/certificate/type/A4_embedded, and so on for the other types.

In each of these subfolders there is a file named certificate.php and this is the one you need to change to customize your certificate. But my advice is not to change one of the four standard certificates types installed when you install the certificate module, but to create a fifth one by copying one of the existing ones and changing the sub-folder name and to customize this one because it will be a lot easier to upgrade your certificate module in the future when a new version will be released without loosing all your changes.

A lot of informations are available here : https://docs.moodle.org/27/en/Certificate_customizing

In reply to Jean-Michel Védrine

Re: Topic instead of Course.name

by Erwin Ancheta -

Hi Jean,

It's been a long time, I hope you can still see my post.

I'm happy to see this post. You really help a lot of newbies in Moodle.

Just like me smile

I hope you can still give me advise on this.

I want to display (in pdf) all sections that i have in my course.

Is it possible?

I hope you can still receive my post.

Thanks in advance!


Kind Regards,

Erwin