Пример #1
0
 /**
  * Generates html to display one file validation results
  *
  * @param string $filename
  * @param local_moodlecheck_file $file
  * @param string $format display format: html, xml, text
  * @return string
  */
 public function display_file_validation($filename, local_moodlecheck_file $file, $format = 'html')
 {
     $output = '';
     $errors = $file->validate();
     if ($format == 'html') {
         $output .= html_writer::start_tag('li', array('class' => 'file'));
         $output .= html_writer::tag('span', $filename, array('class' => 'filename'));
         $output .= html_writer::start_tag('ul', array('class' => 'file'));
     } else {
         if ($format == 'xml') {
             $output .= html_writer::start_tag('file', array('name' => $filename)) . "\n";
         } else {
             if ($format == 'text') {
                 $output .= $filename . "\n";
             }
         }
     }
     foreach ($errors as $error) {
         if (($format == 'html' || $format == 'text') && isset($error['line']) && strlen($error['line'])) {
             $error['message'] = get_string('linenum', 'local_moodlecheck', $error['line']) . $error['message'];
         }
         if ($format == 'html') {
             $output .= html_writer::tag('li', $error['message'], array('class' => 'errorline'));
         } else {
             $error['message'] = strip_tags($error['message']);
             if ($format == 'text') {
                 $output .= "    " . $error['message'] . "\n";
             } else {
                 if ($format == 'xml') {
                     $output .= '  ' . html_writer::empty_tag('error', $error) . "\n";
                 }
             }
         }
     }
     if ($format == 'html') {
         $output .= html_writer::end_tag('ul');
         $output .= html_writer::end_tag('li');
     } else {
         if ($format == 'xml') {
             $output .= html_writer::end_tag('file') . "\n";
         }
     }
     return $output;
 }