Browse Source

Adding course code in URL in order to fix the "newscorm -1" error see BT#6962

Julio Montoya 11 years ago
parent
commit
bc15484afa
2 changed files with 54 additions and 28 deletions
  1. 47 25
      main/newscorm/learnpath.class.php
  2. 7 3
      main/newscorm/scorm_api.php

+ 47 - 25
main/newscorm/learnpath.class.php

@@ -13,7 +13,8 @@
  * @package chamilo.learnpath
  */
 
-class learnpath {
+class learnpath
+{
 
     public $attempt = 0; // The number for the current ID view.
     public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
@@ -76,27 +77,17 @@ class learnpath {
     public $course_int_id;
     public $course_info = array();
 
-    public function get_course_int_id() {
-        return isset($this->course_int_id) ? $this->course_int_id : api_get_course_int_id();
-    }
-
-    public function set_course_int_id($course_id) {
-        return $this->course_int_id = intval($course_id);
-    }
-
     /**
-     * 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.
-     * @param	string		Course code
-     * @param	integer		Learnpath ID
-     * @param	integer		User ID
-     * @return	boolean		True on success, false on error
-     */
-    public function __construct($course, $lp_id, $user_id) {
+    * 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.
+    * @param	string		Course code
+    * @param	integer		Learnpath ID
+    * @param	integer		User ID
+    * @return	boolean		True on success, false on error
+    */
+    public function __construct($course, $lp_id, $user_id)
+    {
         $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
-        // Check course code.
-        $course_id = api_get_course_int_id();
-
         if ($this->debug > 0) { error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
         if (empty($course)) {
             $this->error = 'Course code is empty';
@@ -108,7 +99,7 @@ class learnpath {
                 $this->course_info  = $course_info;
                 $course_id 	        = $course_info['real_id'];
             } else {
-                $this->error = 'Course code does not exist in database ('.$sql.')';
+                $this->error = 'Course code does not exist in database.';
                 return false;
             }
         }
@@ -380,8 +371,35 @@ class learnpath {
     }
 
     /**
-     * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
-     * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
+     * @return string
+     */
+    public function getCourseCode()
+    {
+        return $this->cc;
+    }
+
+    /**
+     * @return int
+     */
+    public function get_course_int_id()
+    {
+        return isset($this->course_int_id) ? $this->course_int_id : api_get_course_int_id();
+    }
+
+    /**
+     * @param $course_id
+     * @return int
+     */
+    public function set_course_int_id($course_id)
+    {
+        return $this->course_int_id = intval($course_id);
+    }
+
+    /**
+     * Function rewritten based on old_add_item() from Yannick Warnier.
+     * Due the fact that users can decide where the item should come, I had to overlook this function and
+     * I found it better to rewrite it. Old function is still available.
+     * Added also the possibility to add a description.
      *
      * @param int $parent
      * @param int $previous
@@ -389,9 +407,12 @@ class learnpath {
      * @param int  resource ID (ref)
      * @param string $title
      * @param string $description
+     * @param int $prerequisites
+     * @param int $max_time_allowed
      * @return int
      */
-    public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
+    public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0)
+    {
         $course_id = api_get_course_int_id();
         if ($this->debug > 0) {
             error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
@@ -621,7 +642,8 @@ class learnpath {
      * @param	string	Zip file containing the learnpath or directory containing the learnpath
      * @return	integer	The new learnpath ID on success, 0 on failure
      */
-    public static function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
+    public static function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '')
+    {
         global $charset;
         $course_id = api_get_course_int_id();
         $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);

+ 7 - 3
main/newscorm/scorm_api.php

@@ -35,6 +35,7 @@ require_once 'learnpathItem.class.php';
 require_once 'scorm.class.php';
 
 $file   = (empty($_SESSION['file'])?'':$_SESSION['file']);
+/** @var Learnpath $oLP */
 $oLP    = unserialize($_SESSION['lpobject']);
 $oItem 	= $oLP->items[$oLP->current];
 
@@ -157,7 +158,7 @@ olms.launch_data = '<?php echo $oItem->get_launch_data();?>';
 olms.max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
 olms.interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
 olms.item_objectives = new Array();
-olms.info_lms_item=new Array();
+olms.info_lms_item = new Array();
 
 // Chamilo internal variables (not SCORM)
 // olms.saved_lesson_status = 'not attempted';
@@ -181,6 +182,9 @@ olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
 olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
 olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
 olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
+olms.lms_course_id = '<?php echo $oLP->get_course_int_id(); ?>';
+olms.lms_course_code = '<?php echo $oLP->getCourseCode(); ?>';
+
 <?php echo $oLP->get_items_details_as_js('olms.lms_item_types');?>
 
 olms.asset_timer = 0;
@@ -1462,10 +1466,10 @@ function switch_item(current_item, next_item){
             break;
     }
 
-    var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item;
+    var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item+'&cidReq='+olms.lms_course_code;
     var cont_f = $("#content_id");
 
-    <?php if($oLP->mode == 'fullscreen'){ ?>
+    <?php if($oLP->mode == 'fullscreen') { ?>
     cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
     cont_f.onload=function(){
         olms.info_lms_item[0]=olms.info_lms_item[1];