{"id":115,"date":"2016-03-11T10:00:10","date_gmt":"2016-03-11T15:00:10","guid":{"rendered":"http:\/\/razonartificial.com\/themes\/openmind\/wordpress\/?p=115"},"modified":"2021-12-06T11:44:39","modified_gmt":"2021-12-06T16:44:39","slug":"como-anadir-campos-personalizados-en-un-certificado-de-moodle","status":"publish","type":"post","link":"https:\/\/www.apdi.co\/blog\/como-anadir-campos-personalizados-en-un-certificado-de-moodle\/","title":{"rendered":"\u00bfC\u00f3mo a\u00f1adir campos personalizados en un certificado de Moodle?"},"content":{"rendered":"<p>En muchas ocasiones requerimos que en el certificado aparezca informaci\u00f3n adicional a la que comunmente trae por defecto moodle, por ejemplo podemos requerir que se muestre en el certificado, la ciudad y el n\u00famero de documento que tiene el estudiante, para a\u00f1adir estos campos debemos de ingresar a:<\/p>\n<p>miMoodle\/mod\/certificate\/type\/miCertificado\/certificate.php<\/p>\n<p>y a\u00f1adir las siguientes lineas de c\u00f3digo:<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">global $USER;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">\/\/Traer N\u00famero de documento, campo personalizado creado en el formulario del perfil de los usuarios<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$value = $DB-&gt;get_record_sql(&quot;SELECT * FROM mdl_user_info_data WHERE fieldid='1' AND userid='$USER-&gt;id'&quot;); \/\/query db y selecciono el id del campo personalizado que deseo traer, en este caso 1<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">if ($value) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$value = $value-&gt;data; \/\/ selecciono el campo donde se encuentra el campo personalizado<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">} else {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$value = '';<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">}<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$numeroDoc = &quot;Con c\u00e9dula de ciudadan\u00eda N\u00b0 &quot; . $value; \/\/ Igualo la variable con texto adicional<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">certificate_print_text($pdf, $x, $y + 48, 'C', 'courierI', '', 22, $numeroDoc); \/\/ imprimo n\u00famero de documento en el certificado<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Otra manera de hacerlo m\u00e1s f\u00e1cil y r\u00e1pido es adicionando la siguiente l\u00ednea de c\u00f3digo en al archivo certificate.php en donde CC corresponde al nombre corte del campo adicional que inclu\u00ed en el formulario.<\/p>\n<div id=\"ig-sh-2\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">certificate_print_text($pdf, $x, $y + 60, 'C', 'freesans', 'b', 20, $USER-&gt;profile['CC']);<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Si deseamos agregar el campo ciudad debemos de adicionar las siguientes l\u00edneas de c\u00f3digo<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">\/\/Muestro Ciudad<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$ciudad = $DB-&gt;get_record_sql(&quot;SELECT city FROM mdl_user WHERE id='$USER-&gt;id'&quot;); \/\/query db y selecciono el campo del usuario que deseo mostrar<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">if ($ciudad) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$ciudad = $ciudad-&gt;city; \/\/ selecciono el campo que voy a mostrar<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">} else {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">$ciudad = '';<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">}<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">certificate_print_text($pdf, $x, $y + 98, 'C', 'Helvetica', '', 14, $ciudad); \/\/ Imprimo la Ciudad<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Si deseamos adicionar el campo ciudad y este concatenarlo con la fecha para que se visualice algo como \u00abBogot\u00e1 11 marzo 2016\u00bb debemos de modificar el archivo mod\/certificate\/ locallib.php y modificar el m\u00e9todo certificate_get_date adicionando el par\u00e1metro $ciudad y posteriormente concatenarlo con el formado de fecha de tal manera que quede asi:<\/p>\n<div id=\"ig-sh-4\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">function certificate_get_date($certificate, $certrecord, $course, $ciudad, $userid = null) { \/\/ linea 849 Moodle 3.0.2<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">if ($certificate-&gt;printdate &gt; 0) { \/\/l\u00ednea 875<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; if ($certificate-&gt;datefmt == 1) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.' '.userdate($date, '%B %d, %Y');<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 2) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $suffix = certificate_get_ordinal_number_suffix(userdate($date, '%d'));<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.' '.userdate($date, '%B %d' . $suffix . ', %Y');<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 3) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.' '.userdate($date, '%d %B %Y');<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 4) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = ciudad.' '.userdate($date, '%B %Y');<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 5) {<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.' '.userdate($date, get_string('strftimedate', 'langconfig'));<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; }<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; return $certificatedate;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; }<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Una vez realizado esto, debemos de ir a nuestro archivo certificate.php (miMoodle\/mod\/certificate\/type\/miCertificado\/certificate.php) y a\u00f1adir la siguiente l\u00ednea de c\u00f3digo<\/p>\n<div id=\"ig-sh-5\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">certificate_print_text($pdf, $x, $y + 105, 'C', 'Times', '', 20, certificate_get_date($certificate, $certrecord, $course, $ciudad)); \/\/Fecha del Curso con la ciudad<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Lo anterior se trabajo para la versi\u00f3n de Moodle 3.0.2 y versi\u00f3n del modulo certificado 2015111601<\/p>\n","protected":false},"excerpt":{"rendered":"<p>En muchas ocasiones requerimos que en el certificado aparezca informaci\u00f3n adicional a la que comunmente trae por defecto moodle, por ejemplo podemos requerir que se muestre en el certificado, la ciudad y el n\u00famero de documento que tiene el estudiante, para a\u00f1adir estos campos debemos de ingresar a: miMoodle\/mod\/certificate\/type\/miCertificado\/certificate.php y a\u00f1adir las siguientes lineas de c\u00f3digo: &lt; View plain text &gt; code global $USER; \/\/Traer N\u00famero de documento, campo personalizado creado en el formulario del perfil de los usuarios $value = $DB-&gt;get_record_sql(&quot;SELECT * FROM mdl_user_info_data WHERE fieldid=&#8217;1&#8242; AND userid=&#8217;$USER-&gt;id&#8217;&quot;); \/\/query db y selecciono el id del campo personalizado que deseo traer, en este caso 1 &nbsp; if ($value) { $value = $value-&gt;data; \/\/ selecciono el campo donde se encuentra el campo personalizado } else { $value = \u00bb; } $numeroDoc = &quot;Con c\u00e9dula de ciudadan\u00eda N\u00b0 &quot; . $value; \/\/ Igualo la variable con texto adicional &nbsp; certificate_print_text($pdf, $x, $y + 48, &#8216;C&#8217;, &#8216;courierI&#8217;, \u00bb, 22, $numeroDoc); \/\/ imprimo n\u00famero de documento en el certificado Otra manera de hacerlo m\u00e1s f\u00e1cil y r\u00e1pido es adicionando la siguiente l\u00ednea de c\u00f3digo en al archivo certificate.php en donde CC corresponde al nombre corte del campo adicional que inclu\u00ed en el formulario. &lt; View plain text &gt; code certificate_print_text($pdf, $x, $y + 60, &#8216;C&#8217;, &#8216;freesans&#8217;, &#8216;b&#8217;, 20, $USER-&gt;profile[&#8216;CC&#8217;]); Si deseamos agregar el campo ciudad debemos de adicionar las siguientes l\u00edneas de c\u00f3digo &lt; View plain text &gt; code \/\/Muestro Ciudad $ciudad = $DB-&gt;get_record_sql(&quot;SELECT city FROM mdl_user WHERE id=&#8217;$USER-&gt;id&#8217;&quot;); \/\/query db y selecciono el campo del usuario que deseo mostrar &nbsp; if ($ciudad) { $ciudad = $ciudad-&gt;city; \/\/ selecciono el campo que voy a mostrar } else { $ciudad = \u00bb; } certificate_print_text($pdf, $x, $y + 98, &#8216;C&#8217;, &#8216;Helvetica&#8217;, \u00bb, 14, $ciudad); \/\/ Imprimo la Ciudad Si deseamos adicionar el campo ciudad y este concatenarlo con la fecha para que se visualice algo como \u00abBogot\u00e1 11 marzo 2016\u00bb debemos de modificar el archivo mod\/certificate\/ locallib.php y modificar el m\u00e9todo certificate_get_date adicionando el par\u00e1metro $ciudad y posteriormente concatenarlo con el formado de fecha de tal manera que quede asi: &lt; View plain text &gt; code function certificate_get_date($certificate, $certrecord, $course, $ciudad, $userid = null) { \/\/ linea 849 Moodle 3.0.2 &nbsp; if ($certificate-&gt;printdate &gt; 0) { \/\/l\u00ednea 875 &nbsp; &nbsp; &nbsp; &nbsp; if ($certificate-&gt;datefmt == 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.&#8217; &#8216;.userdate($date, &#8216;%B %d, %Y&#8217;); &nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 2) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $suffix = certificate_get_ordinal_number_suffix(userdate($date, &#8216;%d&#8217;)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.&#8217; &#8216;.userdate($date, &#8216;%B %d&#8217; . $suffix . &#8216;, %Y&#8217;); &nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 3) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.&#8217; &#8216;.userdate($date, &#8216;%d %B %Y&#8217;); &nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 4) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = ciudad.&#8217; &#8216;.userdate($date, &#8216;%B %Y&#8217;); &nbsp; &nbsp; &nbsp; &nbsp; } else if ($certificate-&gt;datefmt == 5) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $certificatedate = $ciudad.&#8217; &#8216;.userdate($date, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":843,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-moodle"],"_links":{"self":[{"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":1,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":822,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions\/822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/media\/843"}],"wp:attachment":[{"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.apdi.co\/blog\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}