Browse Source

Adding lp author, lp image when copying a course see CT#519

Julio Montoya 15 years ago
parent
commit
e4f11ee807

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

@@ -581,12 +581,10 @@ class CourseBuilder
 				$item['previous_item_id'] = $obj_item->previous_item_id;
 				$item['next_item_id'] 	= $obj_item->next_item_id;
 				$item['display_order'] 	= $obj_item->display_order;
-				$item['prerequisite']	 = $obj_item->prerequisite;
+				$item['prerequisite']	= $obj_item->prerequisite;
 				$item['parameters'] 	= $obj_item->parameters;
 				$item['launch_data'] 	= $obj_item->launch_data;
-				//adding audio data
-				$item['audio'] 	= $obj_item->audio;
-				
+				$item['audio'] 			= $obj_item->audio;				
 				$items[] = $item;
 			}
 
@@ -614,8 +612,10 @@ class CourseBuilder
 								$obj->display_order,
 								$obj->js_lib,
 								$obj->content_license,
-								$obj->debug,
+								$obj->debug,								
 								$visibility,
+								$obj->author,
+								$obj->preview_image,
 								$items);
 
 			$this->course->add_resource($lp);

+ 19 - 7
main/coursecopy/classes/CourseCopyLearnpath.class.php

@@ -74,6 +74,17 @@ class CourseCopyLearnpath extends Resource {
 	 * The learnpath visibility on the homepage
 	 */
 	var $visibility;
+	
+	/**
+	 * Author info
+	 */
+	var $author;
+	
+	/**
+	 * Author's image
+	 */
+	var $preview_image;
+								
 
 	/**
 	 * Create a new learnpath
@@ -96,7 +107,7 @@ class CourseCopyLearnpath extends Resource {
 	 * @param string $visibility
 	 * @param array  $items
 	 */
-	function CourseCopyLearnpath($id,$type,$name,$path,$ref,$description,$content_local,$default_encoding,$default_view_mode,$prevent_reinit,$force_commit,$content_maker,$display_order,$js_lib,$content_license,$debug,$visibility,$items)
+	function CourseCopyLearnpath($id,$type,$name,$path,$ref,$description,$content_local,$default_encoding,$default_view_mode,$prevent_reinit,$force_commit,$content_maker,$display_order,$js_lib,$content_license,$debug,$visibility, $author, $preview_image, $items)
 	{
 		parent::Resource($id,RESOURCE_LEARNPATH);
 		$this->lp_type = $type;
@@ -115,6 +126,10 @@ class CourseCopyLearnpath extends Resource {
 		$this->content_license = $content_license;
 		$this->debug = $debug;
 		$this->visibility=$visibility;
+		
+		$this->author= $author;
+		$this->preview_image= $preview_image;
+		
 		$this->items = $items;
 	}
 	/**
@@ -129,10 +144,8 @@ class CourseCopyLearnpath extends Resource {
 	 */
 	function has_item($resource)
 	{
-		foreach($this->items as $index => $item)
-		{
-			if( $item['id'] == $resource->get_id() && $item['type'] == $resource->get_type())
-			{
+		foreach($this->items as $index => $item) {
+			if( $item['id'] == $resource->get_id() && $item['type'] == $resource->get_type()) {
 				return true;
 			}
 		}
@@ -141,8 +154,7 @@ class CourseCopyLearnpath extends Resource {
 	/**
 	 * Show this learnpath
 	 */
-	function show()
-	{
+	function show() {
 		parent::show();
 		echo $this->name;
 	}

+ 39 - 18
main/coursecopy/classes/CourseRestorer.class.php

@@ -1185,6 +1185,10 @@ class CourseRestorer
 			$table_tool 	= Database::get_course_table(TABLE_TOOL_LIST, $this->course->destination_db);
 
 			$resources = $this->course->resources;
+			
+							
+			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';				
+			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
 
 			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
 
@@ -1193,25 +1197,42 @@ class CourseRestorer
 					$session_id = intval($session_id);
 					$condition_session = " , session_id = '$session_id' ";
 				}
+				
+				//Adding the author's image
+				if (!empty($lp->preview_image)) {
+					$new_filename = uniqid('').$new_filename.substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));	
+					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
+						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
+						//$copy_result = true;
+						if ($copy_result === true) {
+							$lp->preview_image = $new_filename;
+						} else {
+							$lp->preview_image ='';
+						}
+					}			
+				}
 
-				$sql = "INSERT INTO ".$table_main." " .
-						"SET lp_type = '".$lp->lp_type."', " .
-								"name = '".Database::escape_string($lp->name)."', " .
-								"path = '".Database::escape_string($lp->path)."', " .
-								"ref = '".$lp->ref."', " .
-								"description = '".Database::escape_string($lp->description)."', " .
-								"content_local = '".Database::escape_string($lp->content_local)."', " .
-								"default_encoding = '".Database::escape_string($lp->default_encoding)."', " .
-								"default_view_mod = '".Database::escape_string($lp->default_view_mod)."', " .
-								"prevent_reinit = '".Database::escape_string($lp->prevent_reinit)."', " .
-								"force_commit = '".Database::escape_string($lp->force_commit)."', " .
-								"content_maker = '".Database::escape_string($lp->content_maker)."', " .
-								"display_order = '".Database::escape_string($lp->display_order)."', " .
-								"js_lib= '".Database::escape_string($lp->js_lib)."', " .
-								"content_license= '".Database::escape_string($lp->content_license)."', " .
-								"debug= '".Database::escape_string($lp->debug)."' $condition_session ";
-				Database::query($sql);
-
+				$sql = "INSERT INTO ".$table_main." SET " .
+						"lp_type = '".$lp->lp_type."', " .
+						"name = '".Database::escape_string($lp->name)."', " .
+						"path = '".Database::escape_string($lp->path)."', " .
+						"ref = '".$lp->ref."', " .
+						"description = '".Database::escape_string($lp->description)."', " .
+						"content_local = '".Database::escape_string($lp->content_local)."', " .
+						"default_encoding = '".Database::escape_string($lp->default_encoding)."', " .
+						"default_view_mod = '".Database::escape_string($lp->default_view_mod)."', " .
+						"prevent_reinit = '".Database::escape_string($lp->prevent_reinit)."', " .
+						"force_commit = '".Database::escape_string($lp->force_commit)."', " .
+						"content_maker = '".Database::escape_string($lp->content_maker)."', " .
+						"display_order = '".Database::escape_string($lp->display_order)."', " .
+						"js_lib= '".Database::escape_string($lp->js_lib)."', " .
+						"content_license= '".Database::escape_string($lp->content_license)."', " .
+						"author= '".Database::escape_string($lp->author)."', " .
+						"preview_image= '".Database::escape_string($lp->preview_image)."', " .
+						"debug= '".Database::escape_string($lp->debug)."' $condition_session ";
+							
+				Database::query($sql);		
+				
 				$new_lp_id = Database::insert_id();
 
 				if($lp->visibility) {