Browse Source

added visibility of a learning path for a student when the prerequisite is completed - partial BT#871

Cristian Fasanando 15 years ago
parent
commit
d3225a1c13

+ 113 - 0
main/newscorm/learnpath.class.php

@@ -67,6 +67,8 @@ class learnpath {
 
 	var $lp_session_id =0;
 
+	var $prerequisite = 0;
+	
 	/**
 	 * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
 	 * Also builds the list of items into $this->items.
@@ -2137,6 +2139,36 @@ class learnpath {
 
 	}
 
+	/**
+	 * This function check if the learnpath is visible for student after the progress of its prerequisite is completed
+	 * @param	int		Learnpath id
+	 * @param	int		Student id
+	 * @return	bool	True if
+	 */
+	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";
+		$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,'%');
+			$progress = intval($progress);			
+			if ($progress < 100) {
+				$is_visible = false;	
+			}			
+		}
+		
+		return $is_visible;
+		
+	}
+
 	/**
 	 * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
 	 * completed so far.
@@ -4080,6 +4112,26 @@ class learnpath {
 		$res = Database::query($sql);
 		return true;
 	}
+	
+	/**
+	* Sets the prerequisite of a LP (and save)
+	* @param	int		integer giving the new prerequisite of this learnpath
+	* @return 	bool 	returns true if prerequisite is not empty
+	*/
+	function set_prerequisite($prerequisite) {
+		if ($this->debug > 0) {
+			error_log('New LP - In learnpath::set_prerequisite()', 0);
+		}
+		$this->prerequisite = intval($prerequisite);
+		$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
+		$lp_id = $this->get_id();
+		$sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
+		if ($this->debug > 2) {
+			error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
+		}
+		$res = Database::query($sql);
+		return true;
+	}
 
 	/**
 	 * Sets the location/proximity of the LP (local/remote) (and save)
@@ -7681,6 +7733,67 @@ class learnpath {
 		return $return;
 	}
 
+	/**
+	 * Return HTML list to allow prerequisites selection for lp
+	 * @param	integer Item ID
+	 * @return	string	HTML form
+	 */
+	function display_lp_prerequisites_list() {
+		global $charset;
+		
+		 
+		$lp_id = $this->lp_id;
+
+		$tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
+		
+		// get current prerequisite
+		$sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
+		$result = Database::query($sql);
+		$row = Database :: fetch_array($result);
+		$preq_id = $row['prerequisite'];		
+		
+		
+		$return = '';
+		$return .= '<div class="sectioncomment">';
+		$return .= '<table style="border-collapse:collapse;">';
+
+		//Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
+		$return .= '<tr >';
+		$return .= '<td>';
+		$return .= '<input checked="checked" id="idNone" name="prerequisites" type="radio" />';
+		$return .= '<label for="idNone">'.get_lang('None').'</label>';
+		$return .= '</td>';
+		$return .= '</tr>';
+
+		$session_id = api_get_session_id();
+		$session_condition = api_get_session_condition($session_id, false);
+		
+		$sql 	= "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";		
+		$rs = Database::query($sql);
+		
+		if (Database::num_rows($rs) > 0) {			
+			while ($row = Database::fetch_array($rs)) {
+				if ($row['id'] == $lp_id) {
+					continue;	
+				}
+				
+				$return .= '<tr >';
+				$return .= '<td >';
+				$return .= '<input '.(($row['id']==$preq_id)?' checked="checked" ' : '').' id="id_'.$row['id'].'" name="prerequisites"  type="radio" value="'.$row['id'].'" />';				
+				$return .= '<label for="id_'.$row['id'].'">'.$row['name'].'</label>';
+				$return .= '</td>';
+				
+				$return .= '</tr>';				
+			}			
+		}
+		
+		$return .= '</table>';		
+		$return .= '</div>';
+
+		return $return;
+	}
+
+
 	/**
 	 * Creates a list with all the documents in it
 	 *

+ 2 - 0
main/newscorm/lp_controller.php

@@ -603,6 +603,8 @@ switch($action)
 			$_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
 			$_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
 			$_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
+			$_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
+
 			if ($_REQUEST['remove_picture'])
 			{
 				$_SESSION['oLP']->delete_lp_image();

+ 4 - 0
main/newscorm/lp_edit.php

@@ -163,6 +163,10 @@ $encoding_select -> setSelected($s_selected_encoding);
 $defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
 $defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
 
+$form->addElement('html', '<div class="row"><div class="label">'.get_lang('Prerequisites').'</div><div class="formw">'.$_SESSION['oLP']->display_lp_prerequisites_list().'</div></div>');
+
+//$form->addElement('html', $_SESSION['oLP']->display_lp_prerequisites_list());
+
 //Submit button
 $form->addElement('style_submit_button', 'Submit',get_lang('SaveLPSettings'),'class="save"');
 //'<img src="'.api_get_path(WEB_IMG_PATH).'accept.png'.'" alt=""/>'

+ 25 - 7
main/newscorm/lp_list.php

@@ -196,6 +196,12 @@ if (is_array($flat_list))
 	    	// This is a student and this path is invisible, skip
 	    	continue;
 	    }
+	    
+	    // check if the learnpath is visible for student
+	    if (!$is_allowed_to_edit && !learnpath::is_lp_visible_for_student($id,api_get_user_id())) {
+	    	continue;
+	    }
+	    
 		$counter++;
 	    if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
 
@@ -247,11 +253,16 @@ if (is_array($flat_list))
 			$dsp_progress = '<td style="padding-top:1em;">'.learnpath::get_db_progress($id,api_get_user_id(),'both').'</td>';
 	    }
 	    if($is_allowed_to_edit) {
+	    	
+	    	/*
 	    	if ($current_session == $details['lp_session']) {
 		    	$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'].'<a href="lp_controller.php?'.api_get_cidreq().'&action=edit&lp_id='.$id.'">&nbsp;&nbsp;<img src="../img/edit.gif" border="0" title="'.get_lang('_edit_learnpath').'"></a></td>'."\n";
 	    	} else {
 				$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'].'<img src="../img/edit_na.gif" border="0" title="'.get_lang('_edit_learnpath').'"></td>'."\n";
 	    	}
+	    	*/
+	    	
+	    	$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";
 
 			/* export */
 			//Export is inside "Edit"
@@ -279,8 +290,15 @@ if (is_array($flat_list))
 
 			$dsp_edit = '<td align="center">';
 	    	$dsp_edit_close = '</td>';
-
-			/*   BUILD    */
+			
+			// EDIT LP
+			if ($current_session == $details['lp_session']) {
+				$dsp_edit_lp = '<a href="lp_controller.php?'.api_get_cidreq().'&action=edit&lp_id='.$id.'">&nbsp;&nbsp;<img src="../img/edit.gif" border="0" title="'.get_lang('_edit_learnpath').'"></a>&nbsp;';
+			} else {
+				$dsp_edit_lp = '<img src="../img/edit.gif" border="0" title="'.get_lang('_edit_learnpath').'">&nbsp;';
+			}
+				
+			//   BUILD  
 			if ($current_session == $details['lp_session']) {
 				if($details['lp_type']==1 || $details['lp_type']==2){
 					$dsp_build = '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=build&amp;lp_id='.$id.'"><img src="../img/wizard.gif" border="0" title="'.get_lang("Build").'"></a>&nbsp;';
@@ -395,11 +413,11 @@ if (is_array($flat_list))
 				if($details['lp_scorm_debug']==1){
 					$dsp_debug = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_scorm_debug&lp_id='.$id.'">' .
 							'<img src="../img/bug.gif" border="0" alt="'.get_lang("HideDebug").'" title="'.get_lang("HideDebug").'"/>' .
-							'</a>&nbsp;';
+							'</a>';
 				}else{
 					$dsp_debug = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_scorm_debug&lp_id='.$id.'">' .
 							'<img src="../img/bug_gray.gif" border="0" alt="'.get_lang("ShowDebug").'" title="'.get_lang("ShowDebug").'"/>' .
-							'</a>&nbsp;';
+							'</a>';
 				}
 		 	}
 
@@ -433,11 +451,11 @@ if (is_array($flat_list))
 				if($details['lp_scorm_debug']==1){
 					$dsp_debug = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_scorm_debug&lp_id='.$id.'">' .
 							'<img src="../img/bug.gif" border="0" alt="'.get_lang("HideDebug").'" title="'.get_lang("HideDebug").'"/>' .
-							'</a>&nbsp;';
+							'</a>';
 				}else{
 					$dsp_debug = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_scorm_debug&lp_id='.$id.'">' .
 							'<img src="../img/bug_gray.gif" border="0" alt="'.get_lang("ShowDebug").'" title="'.get_lang("ShowDebug").'"/>' .
-							'</a>&nbsp;';
+							'</a>';
 				}
 		 	}
 		 	/*   Export  */
@@ -497,7 +515,7 @@ if (is_array($flat_list))
 			}
 	    }	// end if($is_allowedToEdit)
 	    //echo $dsp_line.$dsp_desc.$dsp_export.$dsp_edit.$dsp_delete.$dsp_visible;
-	    echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_publish.$dsp_reinit.$dsp_default_view.$dsp_debug.$dsp_delete.$dsp_disk.$dsp_order;
+	    echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_publish.$dsp_reinit.$dsp_default_view.$dsp_debug.$dsp_edit_lp.$dsp_delete.$dsp_disk.$dsp_order.$dsp_edit_close;
 	    //echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_reinit.$dsp_force_commit.$dsp_delete;
 	    echo	"</tr>\n";
 		$current ++; //counter for number of elements treated