Browse Source

Restore changes: Add extra field for exercises see BT#15743

Option added "results_available_for_x_minutes"
Julio Montoya 5 years ago
parent
commit
12ca5444fa
3 changed files with 54 additions and 4 deletions
  1. 42 4
      main/exercise/exercise.class.php
  2. 4 0
      main/exercise/overview.php
  3. 8 0
      main/inc/lib/exercise.lib.php

+ 42 - 4
main/exercise/exercise.class.php

@@ -2396,7 +2396,7 @@ class Exercise
 
             $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_EXERCISE, $this->iId);
 
-            /*$extraField = new ExtraField('exercise');
+            $extraField = new ExtraField('exercise');
             $extraField->addElements(
                 $form,
                 $this->iId,
@@ -2406,7 +2406,7 @@ class Exercise
                 [], //show only fields
                 [], // order fields
                 [] // extra data
-            );*/
+            );
             $form->addElement('html', '</div>'); //End advanced setting
             $form->addElement('html', '</div>');
         }
@@ -2678,10 +2678,10 @@ class Exercise
 
         $iId = $this->save($type);
         if (!empty($iId)) {
-            /*$values = $form->getSubmitValues();
+            $values = $form->getSubmitValues();
             $values['item_id'] = $iId;
             $extraFieldValue = new ExtraFieldValue('exercise');
-            $extraFieldValue->saveFieldValues($values);*/
+            $extraFieldValue->saveFieldValues($values);
 
             Skill::saveSkills($form, ITEM_TYPE_EXERCISE, $iId);
         }
@@ -9901,4 +9901,42 @@ class Exercise
 
         return $group;
     }
+
+    /**
+     * @param array $exerciseResultInfo
+     *
+     * @return bool
+     */
+    public function hasResultsAccess($exerciseResultInfo)
+    {
+        $extraFieldValue = new ExtraFieldValue('exercise');
+        $value = $extraFieldValue->get_values_by_handler_and_field_variable(
+            $this->iId,
+            'results_available_for_x_minutes'
+        );
+        if (!empty($value)) {
+            $value = (int) $value;
+            $endDate = new DateTime($exerciseResultInfo['exe_date']);
+            $endDate->add(new DateInterval('PT'.$value.'M'));
+            if (time() > $endDate->getTimestamp()) {
+                return false;
+            }
+        }
+        return true;
+    }
+    /**
+     * @return int
+     */
+    public function getResultsAccess()
+    {
+        $extraFieldValue = new ExtraFieldValue('exercise');
+        $value = $extraFieldValue->get_values_by_handler_and_field_variable(
+            $this->iId,
+            'results_available_for_x_minutes'
+        );
+        if (!empty($value)) {
+            return (int) $value;
+        }
+        return 0;
+    }
 }

+ 4 - 0
main/exercise/overview.php

@@ -302,6 +302,10 @@ if (!empty($attempts)) {
                 }
             }
 
+            if (!$objExercise->hasResultsAccess($attempt_result)) {
+                $attempt_link = '';
+            }
+
             $row['attempt_link'] = $attempt_link;
         }
         $my_attempt_array[] = $row;

+ 8 - 0
main/inc/lib/exercise.lib.php

@@ -4413,6 +4413,14 @@ EOT;
             }
         }
 
+        if ($objExercise->hasResultsAccess($exercise_stat_info) === false) {
+            echo Display::return_message(
+                sprintf(get_lang('YouPassedTheLimitOfXMinutesToSeeTheResults'), $objExercise->getResultsAccess())
+            );
+            return false;
+        }
+
+
         $counter = 1;
         $total_score = $total_weight = 0;
         $exercise_content = null;