listteachers.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * enrol_teacherskey file description here.
  18. *
  19. * @package enrol_teacherskey
  20. * @copyright 2022 alex sidorov <alex.sidorof@ya.ru>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once(__DIR__ . '/../../config.php');
  24. require "$CFG->libdir/tablelib.php";
  25. $userid = optional_param('userid', 0, PARAM_INT);
  26. $download = optional_param('download', '', PARAM_ALPHA);
  27. $user = \core_user::get_user($userid ?: $USER->id, '*', MUST_EXIST);
  28. if(isset($_GET['courseid'])){
  29. $courseid = $_GET['courseid'];
  30. }else{
  31. redirect($CFG->wwwroot . "/my");
  32. }
  33. $context= \context_course::instance($courseid);
  34. $PAGE->set_context($context);
  35. $PAGE->set_url(new moodle_url('/enrol/teacherskey/listteachers.php'));
  36. $table = new \enrol_teacherskey\output\listteachers('teacherskey');
  37. $name_downloadfile = "listteachers-".date('Y-m-d');
  38. $table->is_downloading($download, $name_downloadfile, 'listteachers');
  39. //
  40. //echo breadcrumbs
  41. $course = get_course($courseid);
  42. if (!$table->is_downloading()){
  43. $PAGE->set_pagelayout('standard');
  44. $PAGE->set_title(get_string('teacherslist', 'enrol_teacherskey'));
  45. $PAGE->set_heading(get_string('teacherslist', 'enrol_teacherskey'));
  46. $PAGE->navbar->add(get_string('courses'), new moodle_url('/course/index.php'));
  47. $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', ['id' => $courseid]));
  48. $PAGE->navbar->add(get_string('teacherslist', 'enrol_teacherskey'), new moodle_url('/enrol/teacherskey/listteachers.php', ['courseid' => $courseid]));
  49. echo $OUTPUT->header(get_string('teacherslist', 'enrol_teacherskey'));
  50. }
  51. $fields = "mu.id, mtd.id mtdid, CONCAT(mu.lastname, ' ', mu.firstname, ' ', mu.middlename) as fiostudent, mc.fullname as coursename, mtd.fio";
  52. $from = "{teacherskey_data} mtd
  53. inner join {course} mc on mc.id = mtd.courseid
  54. inner join {user} mu on mu.id = mtd.userid";
  55. $where = 'mtd.courseid = :courseid';
  56. $params = array('courseid' => $courseid);
  57. $table->set_sql($fields, $from, $where, $params);
  58. $table->define_baseurl(new moodle_url("/enrol/teacherskey/listteachers.php", ['courseid' => $courseid]));
  59. $table->out(10, true);
  60. if (!$table->is_downloading()) {
  61. echo $OUTPUT->footer();
  62. }