/admin/tool/brickfield/classes/local/htmlchecker/reporters/report_xml.php

https://github.com/markn86/moodle · PHP · 67 lines · 38 code · 4 blank · 25 comment · 3 complexity · 82675028092860c3db516c172bd3cd9d MD5 · raw file

  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. namespace tool_brickfield\local\htmlchecker\reporters;
  17. use tool_brickfield\local\htmlchecker\brickfield_accessibility_reporter;
  18. /**
  19. * Returns an ATOM feed of all the issues - useful to run this as a web service
  20. *
  21. * @package tool_brickfield
  22. * @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. class report_xml extends brickfield_accessibility_reporter {
  26. /**
  27. * Generates an ATOM feed of accessibility problems
  28. * @return string|null A nested array of tests and problems with Report Item objects
  29. */
  30. public function get_report() {
  31. $output = "<?xml version='1.0' encoding='utf-8'?>
  32. <feed xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  33. xsi:htmlchecker='https://www.brickfield.ie/htmlcheckerxml/2020.xsd'>";
  34. $results = $this->guideline->getReport();
  35. if (!is_array($results)) {
  36. return null;
  37. }
  38. foreach ($results as $testname => $test) {
  39. $translation = $this->guideline->get_translation($testname);
  40. $output .= "\n\t<htmlchecker:test htmlchecker:testname='$testname' htmlchecker:severity='".
  41. $this->guideline->get_severity($testname) ."'>
  42. <updated>". date('c') ."</updated>";
  43. $output .= "\n\t<htmlchecker:title>". $translation['title'] ."</htmlchecker:title>";
  44. $output .= "\n\t<htmlchecker:description><![CDATA[". $translation['description'] ."]]></htmlchecker:description>";
  45. $output .= "\n\t<htmlchecker:problems>";
  46. foreach ($test as $problem) {
  47. if (is_object($problem)) {
  48. $output .= "\n\t<htmlchecker:entities><![CDATA[" . htmlentities($problem->get_html()) .
  49. "]]></htmlchecker:entities>";
  50. $output .= "\n\t<htmlchecker:line>". $problem->get_line() ."</htmlchecker:line>";
  51. if ($problem->message) {
  52. $output .= "\n\t<htmlchecker:message>$problem->message</htmlchecker:message>";
  53. }
  54. $output .= "\n\t<htmlchecker:pass>$problem->pass</htmlchecker:pass>";
  55. }
  56. }
  57. $output .= "\n\t</htmlchecker:problems>";
  58. $output .= "</htmlchecker:test>";
  59. }
  60. $output .= "</feed>";
  61. return $output;
  62. }
  63. }