Display submitted images instead of titles of Images on the review page for the quiz.

Display submitted images instead of titles of Images on the review page for the quiz.

by Liberty IT -
Number of replies: 2

I want to share my experience regarding display submitted images on the review page for the quiz if there is any submission (Specifically auto grade essay question or could be used on regular essay question as well)

we are using version 3.5.7 moodle installed on cpanel for your information.


you need to change this file called "renderer.php" under Moodle/question/type/essayautograde(or essay)


Before


    public function files_read_only(question_attempt $qa, question_display_options $options) {

        $files = $qa->get_last_qt_files('attachments', $options->context->id);

        $output = array();


        foreach ($files as $file) {

            $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),

                    $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),

                    'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));

        }

        return implode($output);

    }


After


  public function files_read_only(question_attempt $qa, question_display_options $options) {

        $files = $qa->get_last_qt_files('attachments', $options->context->id);

        $output = array();


        foreach ($files as $file) {

           

         $type=get_mimetype_description($file);   

         $extensions=array('Image (JPEG)','Image (PNG)','Image (BMP)','Image (GIF)','Image (PICT)','Image (SVG+XML)','Image (TIFF)');

   

            if(in_array($type, $extensions)){

            

                $output[] = html_writer::link($qa->get_response_file_url($file), 

                        '<img src="'.$qa->get_response_file_url($file).'/>');

            }

   

                $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),

                     $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),

                     'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));

        }

       

        return implode($output);

    }



Result


Before

xxxxx.jpg

xxxx.jpeg

xxxxxx.png

xxxxxx.docx


After

Displayed images
xxxxx.jpg

Displayed images
xxxx.jpeg

Displayed images
xxxxxx.png

xxxxxx.docx



Benefit

Images will display on screen as well as title of images without downloading.





Feel free to suggest any improvements



Average of ratings: Useful (1)
In reply to Liberty IT

Re: Display submitted images instead of titles of Images on the review page for the quiz.

by Khandaker Marsus -

Awesome answer. That helps me a lot. I am searching for that. 

In reply to Liberty IT

Re: Display submitted images instead of titles of Images on the review page for the quiz.

by Liberty IT -
On specific page



  public function files_read_only(question_attempt $qa, question_display_options $options) {

        $files = $qa->get_last_qt_files('attachments', $options->context->id);

        $output = array();


$url = $_SERVER["REQUEST_URI"]; 
$pos = strrpos($url, "review.php"); 

      if($pos != false) { foreach ($files as $file) {

            $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),

                    $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),

                    'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));

        }
          
      }
          else { foreach ($files as $file) {
           
         $type=get_mimetype_description($file);   
         $extensions=array('Image (JPEG)','Image (PNG)','Image (BMP)','Image (GIF)','Image (PICT)','Image (SVG+XML)','Image (TIFF)');
   
    if(in_array($type, $extensions)){
                $output[] = html_writer::link($qa->get_response_file_url($file),
                    '<img src="'.$qa->get_response_file_url($file).'/>');
    }
                   $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),
                    $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
                    'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));
            
        }
          }

        return implode($output);

    }