Yannick Warnier 14 years ago
parent
commit
051205d9cf
3 changed files with 42 additions and 21 deletions
  1. 8 0
      main/inc/lib/display.lib.php
  2. 33 20
      main/newscorm/learnpath.class.php
  3. 1 1
      main/newscorm/lp_list.php

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

@@ -1092,6 +1092,14 @@ class Display {
                     $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_database);
                     if (!in_array($user_id, $invited_users['course_users'])) continue;
                 }
+                // If it's a learning path, ensure it is currently visible to the user
+                if ($item_property['tool'] == TOOL_LEARNPATH) {
+                	require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
+                    if (!learnpath::is_lp_visible_for_student($item_property['ref'],$user_id, $my_course['k'])) {
+                    	continue;
+                    }
+                    
+                }
                 $notifications[$item_property['tool']] = $item_property;
             }
         }

+ 33 - 20
main/newscorm/learnpath.class.php

@@ -1965,35 +1965,48 @@ class learnpath {
         return $output;
     }
 
+
     /**
-     * This function check if the learnpath is visible for student after the progress of its prerequisite is completed
+     * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
      * @param	int		Learnpath id
      * @param	int		Student id
+     * @param   string  Course code (optional)
      * @return	bool	True if
      */
-    public function is_lp_visible_for_student($lp_id, $student_id) {
-
-        $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
-
-        // Get current prerequisite.
-        $sql = "SELECT prerequisite FROM $tbl_learnpath WHERE id = $lp_id";
+    public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
+        $lp_id = (int)$lp_id;
+        $course = api_get_course_info($course);
+        $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
+        // Get current prerequisite
+        $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
         $rs  = Database::query($sql);
-        $row = Database :: fetch_array($rs);
-        $prerequisite = $row['prerequisite'];
-        $is_visible = true;
-        $progress = 0;
-
-        if (!empty($prerequisite)) {
-            $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
-            $progress = intval($progress);
-            if ($progress < 100) {
-                $is_visible = false;
+        if (Database::num_rows($rs)>0) {
+            $row = Database::fetch_array($rs);
+            $prerequisite = $row['prerequisite'];
+            $find = array(' ','-',':');
+            $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
+            $to = str_replace($find,'',api_get_local_time($row['expired_on']));
+            $is_visible = true;
+            $progress = 0;
+    
+            if (!empty($prerequisite)) {
+                $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
+                $progress = intval($progress);
+                if ($progress < 100) {
+                    $is_visible = false;
+                }
             }
+            // Also check the time availability of the learning path
+            if ($is_visible) {
+                $now = str_replace($find,'',api_get_local_time());
+            	if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
+            		$is_visible = false;
+            	}
+            }
+            return $is_visible;
         }
-
-        return $is_visible;
+        return false;
     }
-
     /**
      * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
      * completed so far.

+ 1 - 1
main/newscorm/lp_list.php

@@ -271,7 +271,7 @@ if (is_array($flat_list)) {
             $dsp_desc = '<td valign="middle" style="color: grey; padding-top:1em;"><em>'.$details['lp_maker'].'</em>  &nbsp;&nbsp; '.$details['lp_proximity'].' &nbsp;&nbsp; '.$details['lp_encoding'].'</td>'."\n";
             */
 
-            $dsp_desc = '<td valign="middle" style="color: grey; padding-top:1em;"><em>'.$details['lp_maker'].'</em>  &nbsp;&nbsp; '.$details['lp_proximity'].'</td>'."\n";
+            $dsp_desc = '<td valign="middle" style="color: grey; padding-top:1em;"><em>'.$details['lp_maker'].'</em>  &nbsp;&nbsp; '.$details['lp_proximity'].'<br />'.(learnpath::is_lp_visible_for_student($id,api_get_user_id())?'':'('.get_lang('LPNotVisibleToStudent').')').'</td>'."\n";
 
             /* Export */