From e922d8d2c2cba894aefce3f6c8c99e1f95e04a44 Mon Sep 17 00:00:00 2001
From: Astor Bizard <astor.bizard@grenoble-inp.fr>
Date: Wed, 18 Mar 2020 14:10:41 +0100
Subject: [PATCH] Added force graph load option on previous submissions list.

---
 lang/en/vpl.php             |  1 +
 views/vpl_grapher.class.php | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lang/en/vpl.php b/lang/en/vpl.php
index a23c695f..9a93fdd4 100644
--- a/lang/en/vpl.php
+++ b/lang/en/vpl.php
@@ -112,6 +112,7 @@ $string ['finalreduction_help'] = '<b>FR [NE/FE R]</b><br>
 <b>R</b> Grade reduction by evaluation. If it is a percent, it is apply over previous result.<br>';
 $string ['find'] = "Find";
 $string ['find_replace'] = 'Find/Replace';
+$string ['forceload'] = 'Force load';
 $string ['freeevaluations'] = 'Free evaluations';
 $string ['freeevaluations_help'] = 'Number of automatic evaluations that do not reduce final score';
 $string ['fulldescription'] = 'Full description';
diff --git a/views/vpl_grapher.class.php b/views/vpl_grapher.class.php
index d5a5c356..6429780e 100644
--- a/views/vpl_grapher.class.php
+++ b/views/vpl_grapher.class.php
@@ -151,6 +151,11 @@ class vpl_grapher {
             $totalseries = array();
             if ($diff) {
                 $reqfiles = $this->vpl->get_fgm('required')->getAllFiles();
+                if (optional_param('forcegraphload', false, PARAM_INT)) {
+                    $timelimit = 0;
+                } else {
+                    $timelimit = 500;
+                }
             }
             foreach ($submissionslist as $subinstance) {
                 $submission = new mod_vpl_submission( $this->vpl, $subinstance );
@@ -162,7 +167,7 @@ class vpl_grapher {
                         $series[$name] = array_fill(0, $i - 1, null);
                     }
                     if ($diff && isset($reqfiles[$name])) {
-                        $value = vpl_diff::compute_filediff($reqfiles[$name], $data, 500);
+                        $value = vpl_diff::compute_filediff($reqfiles[$name], $data, $timelimit);
                     } else {
                         $value = strlen( $data );
                     }
@@ -184,9 +189,11 @@ class vpl_grapher {
             }
             self::draw( $title, get_string( 'submissions', VPL ) , get_string( "sizeb" ), $subsn, $series, $names );
         } catch (Exception $e) {
+            global $PAGE;
             echo '<span class="chart-area nograph">';
             echo '<b>' . $title . '</b><br>';
-            echo get_string('graphcomputationfailed', VPL);
+            echo get_string('graphcomputationfailed', VPL) . '<br>';
+            echo '<a href="'. $PAGE->url->out(true, array('forcegraphload' => 1)) .'">' . get_string('forceload', VPL) . '</a>';
             echo '</span>';
         }
     }
-- 
GitLab