Browse Source

The Thematic() constructor now needs a course array

Julio Montoya 11 năm trước cách đây
mục cha
commit
b314edacbd

+ 3 - 2
main/course_progress/index.php

@@ -60,9 +60,10 @@ if (isset($_GET['thematic_id'])) {
 if (isset($_GET['description_type'])) {
 	$description_type = intval($_GET['description_type']);
 }
+$courseInfo = api_get_course_info();
 
 // instance thematic object for using like library here
-$thematic = new Thematic();
+$thematic = new Thematic($courseInfo);
 
 // thematic controller object
 $thematic_controller = new ThematicController();
@@ -328,4 +329,4 @@ switch ($action) {
     case 'thematic_advance_list'    :
         $thematic_controller->thematic_advance($action);
         break;
-}
+}

+ 19 - 10
main/course_progress/thematic_controller.php

@@ -15,14 +15,17 @@
 /**
  * Thematic Controller script. Prepares the common background variables to give to the scripts corresponding to
  * the requested action
+ * @todo use a proper controller in src/ChamiloLMS
  * @package chamilo.course_progress
  */
-class ThematicController {
+class ThematicController
+{
 
     /**
      * Constructor
      */
-    public function __construct() {
+    public function __construct()
+    {
         $this->toolname = 'course_progress';
         $this->view = new View($this->toolname);
     }
@@ -32,8 +35,10 @@ class ThematicController {
      * @param 	string	Action
      * render to thematic.php
      */
-    public function thematic($action) {
-        $thematic = new Thematic();
+    public function thematic($action)
+    {
+        $courseInfo = api_get_course_info();
+        $thematic = new Thematic($courseInfo);
         $data = array();
         $error = false;
 
@@ -222,7 +227,7 @@ class ThematicController {
                 }
                 $data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
             } else {
-                $thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
+                $thematic_data = $thematic->get_thematic_list(null, null, api_get_session_id());
                 $data['max_thematic_item'] = $thematic->get_max_thematic_item();
                 $data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
                 $data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
@@ -258,8 +263,10 @@ class ThematicController {
      * @param 	string	Action
      * render to thematic_plan.php
      */
-    public function thematic_plan($action) {
-        $thematic = new Thematic();
+    public function thematic_plan($action)
+    {
+        $courseInfo = api_get_course_info();
+        $thematic = new Thematic($courseInfo);
 
         $data = array();
         $error = false;
@@ -361,8 +368,10 @@ class ThematicController {
      * @param 	string	Action
      * render to thematic_advance.php
      */
-    public function thematic_advance($action) {
-        $thematic = new Thematic();
+    public function thematic_advance($action)
+    {
+        $courseInfo = api_get_course_info();
+        $thematic = new Thematic($courseInfo);
         $attendance = new Attendance();
         $data = array();
 
@@ -475,4 +484,4 @@ class ThematicController {
         $this->view->render();
     }
 
-}
+}

+ 5 - 2
main/coursecopy/classes/CourseBuilder.class.php

@@ -977,7 +977,8 @@ class CourseBuilder
 	/**
 	* Build the Surveys
 	*/
-	function build_thematic($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
+	function build_thematic($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
+    {
 		$table_thematic			= Database :: get_course_table(TABLE_THEMATIC);
 		$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
 		$table_thematic_plan    = Database :: get_course_table(TABLE_THEMATIC_PLAN);
@@ -991,10 +992,12 @@ class CourseBuilder
 
 		$course_id = api_get_course_int_id();
 
+        $courseInfo = api_get_course_info();
+
 		$sql = "SELECT * FROM $table_thematic WHERE c_id = $course_id $session_condition ";
 		$db_result = Database::query($sql);
 		while ($row = Database::fetch_array($db_result,'ASSOC')) {
-			$thematic = new Thematic($row);
+			$thematic = new Thematic($courseInfo);
 			$sql = 'SELECT * FROM '.$table_thematic_advance.' WHERE c_id = '.$course_id.' AND thematic_id = '.$row['id'];
 
 			$result = Database::query($sql);

+ 9 - 5
main/inc/ajax/thematic.ajax.php

@@ -9,7 +9,9 @@ require_once '../global.inc.php';
 api_protect_course_script(true);
 
 $action = $_GET['a'];
-$thematic = new Thematic();
+$courseInfo = api_get_course_info();
+
+$thematic = new Thematic($courseInfo);
 
 switch ($action) {
 	case 'save_thematic_plan':
@@ -84,12 +86,13 @@ switch ($action) {
 	case 'get_datetime_by_attendance':
 		$attendance_id       = intval($_REQUEST['attendance_id']);
 		$thematic_advance_id = intval($_REQUEST['thematic_advance_id']);
+        $courseInfo = api_get_course_info();
 
 		$label = '';
 		$input_select = '';
 		if (!empty($attendance_id)) {
 			$attendance = new Attendance();
-			$thematic   = new Thematic();
+			$thematic   = new Thematic($courseInfo);
             $thematic_list = $thematic->get_thematic_list();
 
             $my_list = $thematic_list_temp = array();
@@ -143,12 +146,13 @@ switch ($action) {
 	    break;
 	case 'update_done_thematic_advance':
 		$thematic_advance_id = intval($_GET['thematic_advance_id']);
+        $courseInfo = api_get_course_info();
 		$total_average = 0;
 		if (!empty($thematic_advance_id)) {
-			$thematic = new Thematic();
+			$thematic = new Thematic($courseInfo);
 			$affected_rows  = $thematic->update_done_thematic_advances($thematic_advance_id);
 			//if ($affected_rows) {
-			$total_average  = $thematic->get_total_average_of_thematic_advances(api_get_course_id(), api_get_session_id());
+			$total_average  = $thematic->get_total_average_of_thematic_advances(null, api_get_session_id());
 			//}
 		}
 		echo $total_average;
@@ -156,4 +160,4 @@ switch ($action) {
 	default:
 		echo '';
 }
-exit;
+exit;

+ 3 - 2
main/inc/lib/display.lib.php

@@ -114,6 +114,7 @@ class Display
         global $charset;
         $is_allowed_to_edit = api_is_allowed_to_edit();
         $moduleId = $tool;
+        $courseInfo = api_get_course_info();
         $introduction_section = null;
 
         if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) {
@@ -146,7 +147,7 @@ class Display
             $thematic_description_html = '';
 
             if ($tool == TOOL_COURSE_HOMEPAGE) {
-                $thematic = new Thematic();
+                $thematic = new Thematic($courseInfo);
                 $thematic->set_course_int_id(api_get_course_int_id());
                 if (api_get_course_setting('display_info_advance_inside_homecourse') == '1') {
                     $information_title = get_lang('InfoAboutLastDoneAdvance');
@@ -205,7 +206,7 @@ class Display
             $introduction_section .= '<div class="row"><div class="span12">';
             $introduction_section .=  $thematic_description_html;
 
-            if (!empty($intro_content))	{
+            if (!empty($intro_content)) {
                 $introduction_section .=  $intro_content;
             }
             $introduction_section .=  '</div>';

+ 61 - 51
main/inc/lib/thematic.lib.php

@@ -10,6 +10,7 @@
  */
 class Thematic
 {
+    private $course;
 	private $thematic_id;
 	private $thematic_title;
 	private $thematic_content;
@@ -25,23 +26,29 @@ class Thematic
 	private $course_int_id;
     private $session_id;
 
-	public function __construct() {
-		//$this->course_int_id = api_get_course_int_id();
+	public function __construct($courseInfo)
+    {
+		$this->course = $courseInfo;
+        $this->course_int_id = $courseInfo['real_id'];
 	}
 
-    public function set_course_int_id($course_id) {
+    public function set_course_int_id($course_id)
+    {
         $this->course_int_id = intval($course_id);
     }
 
-    public function set_session_id($session_id) {
+    public function set_session_id($session_id)
+    {
         $this->session_id = intval($session_id);
     }
 
-    public function get_session_id() {
+    public function get_session_id()
+    {
         return isset($this->session_id) ? $this->session_id : api_get_session_id();
     }
 
-    public function get_course_int_id() {
+    public function get_course_int_id()
+    {
         return isset($this->course_int_id) ? $this->course_int_id : api_get_course_int_id();
     }
 
@@ -72,7 +79,8 @@ class Thematic
 	 * @param   string  Order (ASC,DESC)
 	 * @see SortableTable#get_table_data($from)
 	 */
-	public function get_thematic_data($from, $number_of_items, $column, $direction) {
+	public function get_thematic_data($from, $number_of_items, $column, $direction)
+    {
 		$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
         $condition_session = '';
         if (!api_get_session_id()) {
@@ -152,7 +160,8 @@ class Thematic
 	 * Get the maximum display order of the thematic item
 	 * @return int	Maximum display order
 	 */
-	public function get_max_thematic_item($use_session = true) {
+	public function get_max_thematic_item($use_session = true)
+    {
 		// Database table definition
 		$tbl_thematic   = Database :: get_course_table(TABLE_THEMATIC);
 		$session_id     = $this->get_session_id();
@@ -239,8 +248,7 @@ class Thematic
 
 	 	// set current course and session
 	 	$tbl_thematic   = Database :: get_course_table(TABLE_THEMATIC);
-        $course_info    = api_get_course_info($course_code);
-        $course_id      = $course_info['real_id'];
+        $course_id      = $this->course_int_id;
 
 	 	if (isset($session_id)) {
 	 		$session_id = intval($session_id);
@@ -249,7 +257,6 @@ class Thematic
 	 	}
 
 	    $data = array();
-	    $condition = '';
 	    if (isset($thematic_id)) {
 	    	$thematic_id = intval($thematic_id);
 	    	$condition = " WHERE id = $thematic_id AND active = 1 ";
@@ -275,7 +282,8 @@ class Thematic
 		return $data;
 	 }
 
-    public function get_thematic_by_title($title) {
+    public function get_thematic_by_title($title)
+    {
         $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
         $course_id = $this->get_course_int_id();
         $session_id = $this->get_session_id();
@@ -305,8 +313,7 @@ class Thematic
         $course_id = $this->get_course_int_id();
         $session_id = $this->get_session_id();
         $user_id = api_get_user_id();
-
-        $course_info = api_get_course_info_by_id($course_id);
+        $course_info = $this->course;
 
 		// protect data
 		$id = intval($this->thematic_id);
@@ -345,12 +352,13 @@ class Thematic
 	 * @param	int|array	One or many thematic ids
 	 * @return	int			Affected rows
 	 */
-	public function thematic_destroy($thematic_id) {
+	public function thematic_destroy($thematic_id)
+    {
 		$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
 		$affected_rows = 0;
 		$user_id = api_get_user_id();
 		$course_id = $this->get_course_int_id();
-        $course_info = api_get_course_info_by_id($course_id);
+        $course_info = $this->course;
 
 		if (is_array($thematic_id)) {
 			foreach ($thematic_id as $id) {
@@ -378,9 +386,11 @@ class Thematic
 		return $affected_rows;
 	}
 
-	public function copy($thematic_id) {
-	    $thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0);
-	    $thematic_copy = new Thematic();
+	public function copy($thematic_id)
+    {
+        $courseInfo = $this->course;
+	    $thematic = self::get_thematic_list($thematic_id, null, 0);
+	    $thematic_copy = new Thematic($courseInfo);
 	    $thematic_copy->set_thematic_attributes('', $thematic['title'].' - '.get_lang('Copy'), $thematic['content'], api_get_session_id());
 
 	    $new_thematic_id = $thematic_copy->thematic_save();
@@ -388,7 +398,7 @@ class Thematic
             $thematic_advanced = self::get_thematic_advance_by_thematic_id($thematic_id);
             if(!empty($thematic_advanced)) {
                 foreach($thematic_advanced as $item) {
-                    $thematic = new Thematic();
+                    $thematic = new Thematic($courseInfo);
                     $thematic->set_thematic_advance_attributes(0, $new_thematic_id,  0, $item['content'], $item['start_date'], $item['duration']);
                     $thematic->thematic_advance_save();
                 }
@@ -396,7 +406,7 @@ class Thematic
             $thematic_plan = self::get_thematic_plan_data($thematic_id);
             if (!empty($thematic_plan)) {
                 foreach ($thematic_plan as $item) {
-                    $thematic = new Thematic();
+                    $thematic = new Thematic($courseInfo);
                     $thematic->set_thematic_plan_attributes($new_thematic_id, $item['title'], $item['description'], $item['description_type']);
                     $thematic->thematic_plan_save();
                 }
@@ -483,7 +493,7 @@ class Thematic
 	 */
 	 public function get_thematic_advance_by_thematic_id($thematic_id, $course_code = null) {
 
-	    $course_info = api_get_course_info($course_code);
+	    $course_info = $this->course;
         $course_id = $course_info['real_id'];
 
 	 	// set current course
@@ -589,8 +599,8 @@ class Thematic
 	 * @param	string	Course code (optional)
 	 * @return	array	data
 	 */
-	 public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null, $force_session_id = false) {	 	// set current course
-	    $course_info = api_get_course_info($course_code);
+	 public function get_thematic_advance_list($thematic_advance_id = null, $course_code = null, $force_session_id = false)
+     {
         $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
 
         $data = array();
@@ -601,12 +611,14 @@ class Thematic
 	 		$condition = " AND a.id = $thematic_advance_id ";
 	 	}
 
-        $course_id = $course_info['real_id'];
-	 	$sql = "SELECT * FROM $tbl_thematic_advance a WHERE  c_id = $course_id $condition  ORDER BY start_date ";
+        $course_id = $this->course_int_id;
+        $course_code = $this->course['code'];
+
+	 	$sql = "SELECT * FROM $tbl_thematic_advance a WHERE c_id = $course_id $condition ORDER BY start_date ";
 
         $elements =  array();
 	 	if ($force_session_id) {
-    	 	$list = api_get_item_property_by_tool('thematic_advance', $course_info['code'], api_get_session_id());
+    	 	$list = api_get_item_property_by_tool('thematic_advance', $course_code, api_get_session_id());
     	 	foreach($list as $value) {
     	 	    $elements[$value['ref']]= $value;
     	 	}
@@ -657,7 +669,7 @@ class Thematic
 		$duration	      = intval($this->duration);
         $user_id          = api_get_user_id();
         $course_id        = $this->get_course_int_id();
-        $course_info      = api_get_course_info_by_id($course_id);
+        $course_info      = $this->course;
 
 		if (empty($id)) {
 			// Insert
@@ -686,7 +698,7 @@ class Thematic
 	 * @return	int		Affected rows
 	 */
 	public function thematic_advance_destroy($thematic_advance_id) {
-        $_course = api_get_course_info();
+        $_course = $this->course;
 		$course_id = $this->get_course_int_id();
 
 		// definition database table
@@ -731,9 +743,10 @@ class Thematic
 			//$description_type = intval($description_type);
 			//$condition .= " AND description_type = $description_type ";
 		}
+        $courseCode = $this->course['code'];
 
-		$items_from_course  = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), 0);
-	    $items_from_session = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id());
+		$items_from_course  = api_get_item_property_by_tool('thematic_plan', $courseCode, 0);
+	    $items_from_session = api_get_item_property_by_tool('thematic_plan', $courseCode, api_get_session_id());
 
 		$thematic_plan_complete_list  = array();
 		$thematic_plan_id_list = array();
@@ -824,7 +837,7 @@ class Thematic
         $course_id   = $this->get_course_int_id();
         $session_id  = $this->get_session_id();
 
-        $course_info = api_get_course_info_by_id($course_id);
+        $course_info = $this->course;
 		$list        = api_get_item_property_by_tool('thematic_plan', $course_info['code'], $session_id);
 
 		$elements_to_show = array();
@@ -877,7 +890,7 @@ class Thematic
 		$description_type = intval($description_type);
         $user_id = api_get_user_id();
         $course_id = $this->get_course_int_id();
-        $course_info = api_get_course_info_by_id($course_id);
+        $course_info = $this->course;
 
         // get thematic plan id
         $thematic_plan_data = $this->get_thematic_plan_data($thematic_id, $description_type);
@@ -897,7 +910,7 @@ class Thematic
         $course_id = $this->get_course_int_id();
         $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
         $thematic_plan_id = $this->thematic_plan_id;
-        $course_info = api_get_course_info_by_id($course_id);
+        $course_info = $this->course;
 
         if (empty($thematic_plan_id)) {
             return false;
@@ -945,10 +958,11 @@ class Thematic
 	 * @param 	int		Thematic id
 	 * @return	int		Affected rows
 	 */
-	public function update_done_thematic_advances($thematic_advance_id) {
-        $_course = api_get_course_info();
-		$thematic_data         = $this->get_thematic_list(null, api_get_course_id());
-		$thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
+	public function update_done_thematic_advances($thematic_advance_id)
+    {
+
+		$thematic_data         = $this->get_thematic_list();
+		$thematic_advance_data = $this->get_thematic_advance_list(null, null, true);
 		$tbl_thematic_advance  = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
 
 		$affected_rows = 0;
@@ -969,7 +983,6 @@ class Thematic
 		$a_thematic_advance_ids = array();
         $course_id = $this->get_course_int_id();
 
-
 		if (!empty($thematic_data)) {
 			foreach ($thematic_data as $thematic) {
 			    $my_affected_rows = 0;
@@ -977,7 +990,7 @@ class Thematic
 				if (!empty($thematic_advance_data[$thematic['id']])) {
 					foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
 
-						$item_info = api_get_item_property_info(api_get_course_int_id(), 'thematic_advance', $thematic_advance['id']);
+						$item_info = api_get_item_property_info($course_id, 'thematic_advance', $thematic_advance['id']);
 
 						if ($item_info['id_session'] == api_get_session_id()) {
 
@@ -989,7 +1002,7 @@ class Thematic
     						$my_affected_rows = Database::affected_rows();
     						$affected_rows += $my_affected_rows;
                             //if ($my_affected_rows) {
-                                api_item_property_update($_course, 'thematic_advance', $thematic_advance['id'], "ThematicAdvanceDone", $user_id);
+                                api_item_property_update($this->course, 'thematic_advance', $thematic_advance['id'], "ThematicAdvanceDone", $user_id);
                             //}
     						if ($thematic_advance['id'] == $thematic_advance_id) {
     							break 2;
@@ -1032,8 +1045,7 @@ class Thematic
 	 * Get last done thematic advance from thematic details interface
 	 * @return	int		Last done thematic advance id
 	 */
-	public function get_last_done_thematic_advance() {
-        $courseCode = api_get_course_id();
+	public function get_last_done_thematic_advance($courseCode = null) {
 
         if (!empty($courseCode)) {
             $thematic_data          = $this->get_thematic_list();
@@ -1098,14 +1110,12 @@ class Thematic
 	 * @param	int		Session id	(optional)
 	 * @return 	float	Average of thematic advances
 	 */
-	public function get_total_average_of_thematic_advances($course_code = null, $session_id = null) {
-        if (empty($course_code)) {
-			$course_code = api_get_course_id();
-		}
+	public function get_total_average_of_thematic_advances($course_code = null, $session_id = null)
+    {
 	    if (api_get_session_id()) {
-		    $thematic_data = $this->get_thematic_list(null, $course_code );
+		    $thematic_data = $this->get_thematic_list(null, null);
 	    } else {
-	        $thematic_data = $this->get_thematic_list(null, $course_code, 0);
+	        $thematic_data = $this->get_thematic_list(null, null, 0);
 	    }
 		$new_thematic_data = array();
 		if (!empty($thematic_data)) {
@@ -1115,7 +1125,7 @@ class Thematic
     		$thematic_data = $new_thematic_data;
 		}
 
-		$thematic_advance_data = $this->get_thematic_advance_list(null, $course_code, true);
+		$thematic_advance_data = $this->get_thematic_advance_list(null, null, true);
 		$a_average_of_advances_by_thematic = array();
 		$total_average = 0;
 		if (!empty($thematic_data)) {
@@ -1284,4 +1294,4 @@ class Thematic
 	public function build_datetime_from_array($array) {
         return Text::return_datetime_from_array($array);
 	}
-}
+}

+ 4 - 2
main/mySpace/course.php

@@ -175,7 +175,9 @@ if (is_array($a_courses)) {
 
 		$rs = Database::query($sql);
 		$users = array();
-		while ($row = Database::fetch_array($rs)) { $users[] = $row['user_id']; }
+		while ($row = Database::fetch_array($rs)) {
+            $users[] = $row['user_id'];
+        }
 
 		if (count($users) > 0) {
 			$nb_students_in_course = count($users);
@@ -202,7 +204,7 @@ if (is_array($a_courses)) {
 		}
 
 		$tematic_advance_progress = 0;
-		$thematic = new Thematic();
+		$thematic = new Thematic($course);
 		$tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);
 
 		if (!empty($tematic_advance)) {

+ 4 - 4
plugin/dashboard/block_course/block_course.class.php

@@ -144,14 +144,14 @@ class BlockCourse extends Block {
 	 * Get course information data
 	 * @return array
 	 */
-	function get_course_information_data() {
+	function get_course_information_data()
+    {
 		$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 		$course_data = array();
 		$courses = $this->courses;
 
-		$thematic = new Thematic();
-
 		foreach ($courses as $row_course) {
+            $thematic = new Thematic($row_course);
 			$course_code = $row_course['code'];
             $courseId = $row_course['real_id'];
 
@@ -194,4 +194,4 @@ class BlockCourse extends Block {
 	}
 
 }
-?>
+?>

+ 1 - 1
tests/migrate/migration.custom.class.php

@@ -563,7 +563,7 @@ class MigrationCustom {
                 $course_info = api_get_course_info($course_data['code']);
 
                 if (!empty($course_data)) {
-                    $thematic = new Thematic();
+                    $thematic = new Thematic($course_info);
                     $thematic->set_course_int_id($course_info['real_id']);
                     $thematic->set_session_id($session_id);
                     $thematic_info = $thematic->get_thematic_by_title($data['thematic']);