Browse Source

Option "use_new_tracking_in_lp_item" requires to add an LP extra field.

LP extrafield called "track_lp_item"
Julio Montoya 5 years ago
parent
commit
b9944096ab

+ 14 - 18
main/inc/lib/tracking.lib.php

@@ -161,6 +161,19 @@ class Tracking
         $allowNewTracking = api_get_configuration_value('use_new_tracking_in_lp_item');
 
         $lp_id = (int) $lp_id;
+
+        if ($allowNewTracking) {
+            $extraField = new ExtraFieldValue('lp');
+            $result = $extraField->get_values_by_handler_and_field_variable($lp_id, 'track_lp_item');
+            if (empty($result)) {
+                $allowNewTracking = false;
+            } else {
+                if (isset($result['value']) && $result['value'] == 1) {
+                    $allowNewTracking = true;
+                }
+            }
+        }
+
         $lp_item_id = (int) $lp_item_id;
         $user_id = (int) $user_id;
         $session_id = (int) $session_id;
@@ -330,32 +343,15 @@ class Tracking
                 $result = Database::query($sql);
                 $num = Database::num_rows($result);
                 $time_for_total = 0;
+                $attemptResult = 0;
 
                 if ($allowNewTracking && $timeCourse) {
-                    $attemptResult = 0;
                     if (isset($timeCourse['learnpath_detailed']) &&
                         isset($timeCourse['learnpath_detailed'][$lp_id]) &&
                         isset($timeCourse['learnpath_detailed'][$lp_id][$my_item_id])
                     ) {
                         $attemptResult = $timeCourse['learnpath_detailed'][$lp_id][$my_item_id][$view];
                     }
-
-                    /*$sql = " SELECT MIN(date_reg) min, MAX(date_reg) max, TIMESTAMPDIFF(SECOND, MIN(date_reg), MAX(date_reg)) diff_sec
-                            FROM track_e_access_complete
-                            WHERE
-                                tool_id = $lp_id AND
-                                user_id = $user_id AND
-                                tool_id_detail = $my_item_id AND
-                                c_id = $course_id AND
-                                session_id = $session_id AND
-                                login_as = 0 AND
-                                current_id <> 0 AND
-                                action_details = $view
-                            LIMIT 1
-                            ";
-                    $attemptResult = Database::query($sql);
-                    $attemptResult = Database::fetch_array($attemptResult, 'ASSOC');
-                    */
                 }
 
                 // Extend all

+ 1 - 0
main/install/configuration.dist.php

@@ -1093,6 +1093,7 @@ $_configuration['profile_fields_visibility'] = [
 //$_configuration['lp_minimum_time'] = false;
 
 // Track LP attempts using the new tracking system.
+// Requires to add an LP extra field called "track_lp_item" (checkbox) in order to use this feature.
 //$_configuration['use_new_tracking_in_lp_item'] = false;
 
 // Add collapsable option for user course categories

+ 4 - 5
main/lp/learnpath.class.php

@@ -1317,14 +1317,13 @@ class learnpath
     ) {
         $course_id = api_get_course_int_id();
         $_course = api_get_course_info();
+        $id = (int) $id;
 
-        if ($this->debug > 0) {
-            error_log('In learnpath::edit_item()', 0);
-        }
         if (empty($max_time_allowed)) {
             $max_time_allowed = 0;
         }
-        if (empty($id) || ($id != strval(intval($id))) || empty($title)) {
+
+        if (empty($id) || empty($_course)) {
             return false;
         }
 
@@ -1374,7 +1373,7 @@ class learnpath
 
             // Upload file in documents.
             $pi = pathinfo($audio['name']);
-            if ($pi['extension'] == 'mp3') {
+            if ($pi['extension'] === 'mp3') {
                 $c_det = api_get_course_info($this->cc);
                 $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document';
                 $path = handle_uploaded_document(

+ 9 - 13
main/lp/lp_add.php

@@ -42,16 +42,10 @@ $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView']
 $learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
 
 /* MAIN CODE */
-if ((!$is_allowed_to_edit) || ($isStudentView)) {
-    header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
+if ((!$is_allowed_to_edit) || $isStudentView) {
+    header('location:lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
     exit;
 }
-// From here on, we are admin because of the previous condition, so don't check anymore.
-
-/*
-    Course admin section
-    - all the functions not available for students - always available in this case (page only shown to admin)
-*/
 
 if (api_is_in_gradebook()) {
     $interbreadcrumb[] = [
@@ -61,7 +55,7 @@ if (api_is_in_gradebook()) {
 }
 
 $interbreadcrumb[] = [
-    'url' => 'lp_controller.php?action=list',
+    'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
     'name' => get_lang('LearningPaths'),
 ];
 
@@ -150,16 +144,19 @@ $form->addElement('html', '<div id="end_date_div" style="display:none;">');
 $form->addDatePicker('expired_on', get_lang('ExpirationDate'));
 $form->addElement('html', '</div>');
 
+$extraField = new ExtraField('lp');
+
+$extra = $extraField->addElements($form, 0, ['lp_icon']);
+
 Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);
 
 $form->addElement('html', '</div>');
 
 $defaults['activate_start_date_check'] = 1;
 
+$defaults['accumulate_scorm_time'] = 0;
 if (api_get_setting('scorm_cumulative_session_time') == 'true') {
     $defaults['accumulate_scorm_time'] = 1;
-} else {
-    $defaults['accumulate_scorm_time'] = 0;
 }
 
 $defaults['publicated_on'] = date('Y-m-d 08:00:00');
@@ -167,7 +164,6 @@ $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
 
 $form->setDefaults($defaults);
 $form->addButtonCreate(get_lang('CreateLearningPath'));
-
 $form->display();
-// Footer
+
 Display::display_footer();

+ 10 - 19
main/lp/lp_controller.php

@@ -612,20 +612,18 @@ switch ($action) {
             } else {
                 Session::write('post_time', $_POST['post_time']);
 
+                $publicated_on = null;
                 if (isset($_REQUEST['activate_start_date_check']) &&
                     $_REQUEST['activate_start_date_check'] == 1
                 ) {
                     $publicated_on = $_REQUEST['publicated_on'];
-                } else {
-                    $publicated_on = null;
                 }
 
+                $expired_on = null;
                 if (isset($_REQUEST['activate_end_date_check']) &&
                     $_REQUEST['activate_end_date_check'] == 1
                 ) {
                     $expired_on = $_REQUEST['expired_on'];
-                } else {
-                    $expired_on = null;
                 }
 
                 $new_lp_id = learnpath::add_lp(
@@ -646,6 +644,10 @@ switch ($action) {
                     $form->addSelect('skills', 'skills');
                     Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $new_lp_id);
 
+                    $extraFieldValue = new ExtraFieldValue('lp');
+                    $_REQUEST['item_id'] = $new_lp_id;
+                    $extraFieldValue->saveFieldValues($_REQUEST);
+
                     // TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
                     $_SESSION['oLP'] = new learnpath(
                         api_get_course_id(),
@@ -713,7 +715,7 @@ switch ($action) {
         } else {
             Session::write('refresh', 1);
             if (isset($_POST['submit_button']) && !empty($post_title)) {
-                //Updating the lp.modified_on
+                // Updating the lp.modified_on
                 $_SESSION['oLP']->set_modified_on();
 
                 // TODO: mp3 edit
@@ -742,15 +744,12 @@ switch ($action) {
                 if (isset($_POST['content_lp'])) {
                     $_SESSION['oLP']->edit_document($_course);
                 }
-                $is_success = true;
-
                 Display::addFlash(Display::return_message(get_lang('Updated')));
-
                 $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
                 header('Location: '.$url);
                 exit;
             }
-            if (isset($_GET['view']) && $_GET['view'] == 'build') {
+            if (isset($_GET['view']) && $_GET['view'] === 'build') {
                 require 'lp_edit_item.php';
             } else {
                 require 'lp_admin_view.php';
@@ -778,10 +777,6 @@ switch ($action) {
                     $max
                 );
 
-                if ($editPrerequisite) {
-                    $is_success = true;
-                }
-
                 Display::addFlash(Display::return_message(get_lang('Updated')));
                 $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
                 header('Location: '.$url);
@@ -810,7 +805,6 @@ switch ($action) {
                     $post_title,
                     $_POST['description']
                 );
-                $is_success = true;
                 $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
                 header('Location: '.$url);
                 exit;
@@ -1061,23 +1055,20 @@ switch ($action) {
             $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
             $_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
             $_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
-
             $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
             $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
 
             $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
             $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
 
+            $publicated_on = null;
             if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
                 $publicated_on = $_REQUEST['publicated_on'];
-            } else {
-                $publicated_on = null;
             }
 
+            $expired_on = null;
             if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
                 $expired_on = $_REQUEST['expired_on'];
-            } else {
-                $expired_on = null;
             }
             $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
             $_SESSION['oLP']->set_modified_on();

+ 9 - 12
main/lp/lp_edit.php

@@ -236,11 +236,9 @@ if (!empty($options)) {
     $defaults['extra_lp_icon'] = learnpath::getSelectedIcon($lpId);
 }
 
-$enableLpExtraFields = false;
-if ($enableLpExtraFields) {
-    $extraField = new ExtraField('lp');
-    $extra = $extraField->addElements($form, $lpId);
-}
+
+$extraField = new ExtraField('lp');
+$extra = $extraField->addElements($form, $lpId, ['lp_icon']);
 
 $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, $lpId);
 
@@ -251,13 +249,12 @@ $form->addButtonSave(get_lang('SaveLPSettings'));
 $form->addElement('hidden', 'action', 'update_lp');
 $form->addElement('hidden', 'lp_id', $lpId);
 
-if ($enableLpExtraFields) {
-    $htmlHeadXtra[] = '<script>
-    $(function() {
-        '.$extra['jquery_ready_content'].'
-    });
-    </script>';
-}
+$htmlHeadXtra[] = '<script>
+$(function() {
+    '.$extra['jquery_ready_content'].'
+});
+</script>';
+
 
 $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'</script>';