Ver código fonte

Add extra field for exercises see BT#15743

Option added "results_available_for_x_minutes"
Julio Montoya 5 anos atrás
pai
commit
a90bb3b63d

+ 61 - 2
main/exercise/exercise.class.php

@@ -2234,8 +2234,6 @@ class Exercise
                 ['onclick' => 'activate_start_date()']
             );
 
-            $var = self::selectTimeLimit();
-
             if (!empty($this->start_time)) {
                 $form->addElement('html', '<div id="start_date_div" style="display:block;">');
             } else {
@@ -2377,6 +2375,17 @@ class Exercise
 
             $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_EXERCISE, $this->iId);
 
+            $extraField = new ExtraField('exercise');
+            $extraField->addElements(
+                $form,
+                $this->iId,
+                [], //exclude
+                false, // filter
+                false, // tag as select
+                [], //show only fields
+                [], // order fields
+                [] // extra data
+            );
             $form->addElement('html', '</div>'); //End advanced setting
             $form->addElement('html', '</div>');
         }
@@ -2589,6 +2598,11 @@ class Exercise
 
         $iId = $this->save($type);
         if (!empty($iId)) {
+            $values = $form->getSubmitValues();
+            $values['item_id'] = $iId;
+            $extraFieldValue = new ExtraFieldValue('exercise');
+            $extraFieldValue->saveFieldValues($values);
+
             Skill::saveSkills($form, ITEM_TYPE_EXERCISE, $iId);
         }
     }
@@ -8597,4 +8611,49 @@ 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;
+    }
 }

+ 5 - 3
main/exercise/overview.php

@@ -216,9 +216,7 @@ if (!empty($attempts)) {
         $score = ExerciseLib::show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
         $attempt_url = api_get_path(WEB_CODE_PATH).'exercise/result.php?';
         $attempt_url .= api_get_cidreq().'&show_headers=1&';
-        $attempt_url .= http_build_query([
-            'id' => $attempt_result['exe_id'],
-        ]);
+        $attempt_url .= http_build_query(['id' => $attempt_result['exe_id']]);
         $attempt_url .= $url_suffix;
 
         $attempt_link = Display::url(
@@ -287,6 +285,10 @@ if (!empty($attempts)) {
                     unset($row['result']);
                 }
             }
+            if (!$objExercise->hasResultsAccess($attempt_result)) {
+                $attempt_link = '';
+            }
+
             $row['attempt_link'] = $attempt_link;
         }
         $my_attempt_array[] = $row;

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

@@ -4423,6 +4423,13 @@ 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;

+ 4 - 0
main/inc/lib/extra_field.lib.php

@@ -116,6 +116,9 @@ class ExtraField extends Model
                 $this->extraFieldType = EntityExtraField::SESSION_FIELD_TYPE;
                 $this->primaryKey = 'id';
                 break;
+            case 'exercise':
+                $this->extraFieldType = EntityExtraField::EXERCISE_FIELD_TYPE;
+                break;
             case 'question':
                 $this->extraFieldType = EntityExtraField::QUESTION_FIELD_TYPE;
                 break;
@@ -188,6 +191,7 @@ class ExtraField extends Model
             'terms_and_condition',
             'forum_category',
             'forum_post',
+            'exercise',
         ];
 
         if (api_get_configuration_value('allow_scheduled_announcements')) {

+ 1 - 0
src/Chamilo/CoreBundle/Entity/ExtraField.php

@@ -33,6 +33,7 @@ class ExtraField extends BaseAttribute
     const TERMS_AND_CONDITION_TYPE = 14;
     const FORUM_CATEGORY_TYPE = 15;
     const FORUM_POST_TYPE = 16;
+    const EXERCISE_FIELD_TYPE = 17;
 
     /**
      * @var int