element.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * certificateelement_teachersname file description here.
  18. *
  19. * @package certificateelement_teachersname
  20. * @copyright 2022 alex
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. namespace certificateelement_teachersname;
  24. class element extends \tool_certificate\element {
  25. public function render_form_elements($mform){
  26. global $USER, $DB;
  27. parent::render_form_elements($mform);
  28. }
  29. protected function get_fio($issue, $user){
  30. global $DB;
  31. if ($record = $DB->get_record('teacherskey_data', array('userid' => $user->id, 'courseid' => $issue->courseid))){
  32. return $record->fio;
  33. }else {
  34. return $user->profile['fio'];
  35. }
  36. }
  37. /**
  38. * Handles saving the form elements created by this element.
  39. * Can be overridden if more functionality is needed.
  40. *
  41. * @param \stdClass $data the form data or partial data to be updated (i.e. name, posx, etc.)
  42. */
  43. public function save_form_data(\stdClass $data) {
  44. $data->data = 'teacherskey';
  45. parent::save_form_data($data);
  46. }
  47. /**
  48. * Handles rendering the element on the pdf.
  49. *
  50. * @param \pdf $pdf the pdf object
  51. * @param bool $preview true if it is a preview, false otherwise
  52. * @param \stdClass $user the user we are rendering this for
  53. * @param \stdClass $issue the issue we are rendering
  54. */
  55. public function render($pdf, $preview, $user, $issue) {
  56. if ($preview) {
  57. $value = $user->profile['fio'];
  58. }else {
  59. $value = $this->get_fio($issue, $user);
  60. }
  61. $text = format_text($value, FORMAT_HTML, ['context' => \context_system::instance()]);
  62. \tool_certificate\element_helper::render_content($pdf, $this, $text);
  63. }
  64. /**
  65. * Render the element in html.
  66. *
  67. * This function is used to render the element when we are using the
  68. * drag and drop interface to position it.
  69. *
  70. * @return string the html
  71. */
  72. public function render_html() {
  73. $text = format_text($this->get_data(), FORMAT_HTML, ['context' => \context_system::instance()]);
  74. return \tool_certificate\element_helper::render_html_content($this, $text);
  75. }
  76. //
  77. // public function prepare_data_for_form() {
  78. // $record = parent::prepare_data_for_form();
  79. // if (!empty($this->get_data())) {
  80. // $dateinfo = json_decode($this->get_data());
  81. // $record->teachersname = $dateinfo->teachersnamel;
  82. // }
  83. // return $record;
  84. // }
  85. }