소스 검색

course copy: most recent version of wiki pages

Patrick Cool 15 년 전
부모
커밋
32c7c9b980

+ 19 - 0
main/coursecopy/classes/CourseBuilder.class.php

@@ -20,6 +20,7 @@ require_once 'Survey.class.php';
 require_once 'SurveyQuestion.class.php';
 require_once 'Glossary.class.php';
 require_once 'CourseSession.class.php';
+require_once 'wiki.class.php';
 
 /**
  * Class which can build a course-object from a Dokeos-course.
@@ -70,6 +71,7 @@ class CourseBuilder
 			$this->build_learnpaths($session_id,$course_code);
 			$this->build_links($session_id,$course_code);
 			$this->build_course_descriptions($session_id,$course_code);
+			$this->build_wiki();
 
 		} else {
 
@@ -82,10 +84,12 @@ class CourseBuilder
 			$this->build_tool_intro();
 			$this->build_documents();
 			$this->build_course_descriptions();
+			$this->build_wiki();
 			$this->build_quizzes();
 			$this->build_learnpaths();
 			$this->build_surveys();
 			$this->build_glossary();
+			
 		}
 
 		//TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
@@ -693,4 +697,19 @@ class CourseBuilder
 		}
 		return $list;
 	}
+	
+	function build_wiki() 
+	{
+		// Database table definition
+		$tbl_wiki = Database::get_course_table('wiki');
+
+ 		$sql = 'SELECT * FROM ' . $tbl_wiki . ' INNER JOIN (SELECT MAX(id) as wikiid FROM ' . $tbl_wiki . ' GROUP BY page_id)ids ON id=ids.wikiid ORDER BY dtime DESC, group_id, reflink';
+
+		$db_result = api_sql_query($sql, __FILE__, __LINE__);
+		while ($obj = mysql_fetch_object($db_result))
+		{
+			$wiki = new Wiki($obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime);
+			$this->course->add_resource($wiki);
+		}
+	}	
 }

+ 34 - 0
main/coursecopy/classes/CourseRestorer.class.php

@@ -39,6 +39,7 @@ require_once 'SurveyQuestion.class.php';
 //require_once 'mkdirr.php';
 //require_once 'rmdirr.php';
 require_once 'Glossary.class.php';
+require_once 'wiki.class.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 
 define('FILE_SKIP', 1);
@@ -103,6 +104,7 @@ class CourseRestorer
 			$this->restore_learnpaths($session_id);
 			$this->restore_links($session_id);
 			$this->restore_course_descriptions($session_id);
+			$this->restore_wiki();
 		} else {
 			$this->restore_links();
 			$this->restore_tool_intro();
@@ -116,6 +118,7 @@ class CourseRestorer
 			$this->restore_surveys();
 			$this->restore_student_publication();
 			$this->restore_glossary();
+			$this->restore_wiki();
 		}
 
 
@@ -1422,5 +1425,36 @@ class CourseRestorer
 			}
 		}
 	}
+	
+	function restore_wiki()
+	{
+		if ($this->course->has_resources(RESOURCE_WIKI))
+		{
+			// wiki table of the target course
+			$table_wiki = Database :: get_course_table('wiki', $this->course->destination_db);
+
+			// storing all the resources that have to be copied in an array
+			$resources = $this->course->resources;
+
+			foreach ($resources[RESOURCE_WIKI] as $id => $wiki)
+			{
+				//$wiki = new Wiki($obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime);
+				// the sql statement to insert the groups from the old course to the new course
+				$sql = "INSERT INTO $table_wiki (page_id, reflink, title, content, user_id, group_id, dtime)
+							VALUES (
+							'".Database::escape_string($wiki->page_id)."',
+							'".Database::escape_string($wiki->reflink)."',
+							'".Database::escape_string($wiki->title)."',
+							'".Database::escape_string($wiki->content)."',
+							'".Database::escape_string($wiki->user_id)."', " .
+							(empty($wiki->group_id) ? 'NULL' : Database::escape_string($wiki->group_id)).",
+							'".Database::escape_string($wiki->dtime)."')";
+				$result = Database::query($sql, __FILE__, __LINE__);
+				echo $sql;
+				$new_id = Database::insert_id();
+				$this->course->resources[RESOURCE_WIKI][$id]->destination_id = $new_id;
+			}
+		}
+	}	
 }
 ?>

+ 2 - 0
main/coursecopy/classes/CourseSelectForm.class.php

@@ -52,6 +52,8 @@ class CourseSelectForm
 		$resource_titles[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
 		$resource_titles[RESOURCE_SURVEY] = get_lang('Survey');
 		$resource_titles[RESOURCE_GLOSSARY] = get_lang('Glossary');
+		$resource_titles[RESOURCE_WIKI] = get_lang('Wiki');
+		
 ?>
 		<script language="JavaScript" type="text/javascript">
 			function exp(item) {

+ 1 - 0
main/coursecopy/classes/Resource.class.php

@@ -45,6 +45,7 @@ define('RESOURCE_SCORM', 'Scorm');
 define('RESOURCE_SURVEY','survey');
 define('RESOURCE_SURVEYQUESTION','survey_question');
 define('RESOURCE_SURVEYINVITATION','survey_invitation');
+define('RESOURCE_WIKI','wiki');
 
 /**
  * Representation of a resource in a Dokeos-course.

+ 40 - 0
main/coursecopy/classes/wiki.class.php

@@ -0,0 +1,40 @@
+<?php
+require_once('resource.class.php');
+
+/**
+ * Class for migrating the wiki
+ *
+ *@author Matthias Crauwels <matthias.crauwels@UGent.be>, Ghent University
+ */
+class Wiki extends Resource
+{
+	var $id;
+	var $reflink;
+	var $title;
+	var $content;
+	var $user_id;
+	var $group_id;
+	var $timestamp;
+	var $template;
+	var $menu;
+
+	function Wiki($id, $reflink, $title, $content, $user_id, $group_id, $timestamp, $template, $menu)
+	{
+		parent::Resource($id,RESOURCE_WIKI);
+		$this->reflink 					= $reflink;
+		$this->title 					= $title;
+		$this->content					= $content;
+		$this->user_id					= $user_id;
+		$this->group_id					= $group_id;
+		$this->dtime					= $timestamp;
+		$this->template					= $template;
+		$this->menu						= $menu;
+	}
+
+	function show()
+	{
+		parent::show();
+		echo $this->reflink.' ('. (empty($this->group_id) ? get_lang('Everyone') : get_lang('Group') . ' ' .  $this->group_id) .') ' . '<i>(' . $this->dtime . ')</i>';
+	}
+}
+?>

+ 13 - 38
main/coursecopy/copy_course.php

@@ -1,49 +1,20 @@
-<?php
-// $Id: copy_course.php 22204 2009-07-17 20:31:35Z iflorespaz $
-/*
-==============================================================================
-	Dokeos - elearning and course management software
-
-	Copyright (c) 2004 Dokeos S.A.
-	Copyright (c) 2003 Ghent University (UGent)
-	Copyright (c) 2001 Universite catholique de Louvain (UCL)
-	Copyright (c) Bart Mollet (bart.mollet@hogent.be)
-
-	For a full list of contributors, see "credits.txt".
-	The full license can be read in "license.txt".
+<?php // $Id: copy_course.php 22204 2009-07-17 20:31:35Z iflorespaz $
 
-	This program is free software; you can redistribute it and/or
-	modify it under the terms of the GNU General Public License
-	as published by the Free Software Foundation; either version 2
-	of the License, or (at your option) any later version.
+/* For licensing terms, see /dokeos_license.txt */
 
-	See the GNU General Public License for more details.
-
-	Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
-	Mail: info@dokeos.com
-==============================================================================
-*/
-/**
- * ==============================================================================
- * Copy resources from one course to another one.
- *
- * @author Bart Mollet <bart.mollet@hogent.be>
- * @package dokeos.backup
- * ==============================================================================
- */
-/*
-==============================================================================
-		INIT SECTION
-==============================================================================
-*/
 // name of the language file that needs to be included
 $language_file = array('exercice', 'coursebackup', 'admin');
+
+// setting the global file that gets the general configuration, the databases, the languages, ...
 require_once '../inc/global.inc.php';
+
+// including additional libraries
 include_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
 require_once 'classes/CourseBuilder.class.php';
 require_once 'classes/CourseRestorer.class.php';
 require_once 'classes/CourseSelectForm.class.php';
 
+// notice for unauthorized people.
 if (!api_is_allowed_to_edit())
 {
 	api_not_allowed(true);
@@ -56,10 +27,14 @@ if(function_exists('ini_set'))
 	ini_set('max_execution_time',1800);
 }
 
-$nameTools = get_lang('CopyCourse');
+// breadcrumbs
 $interbreadcrumb[] = array ("url" => "../course_info/maintenance.php", "name" => get_lang('Maintenance'));
 
-Display::display_header($nameTools);
+// the section (for the tabs)
+$this_section=SECTION_COURSES;
+
+// Display the header
+Display::display_header(get_lang('CopyCourse'));
 //api_display_tool_title($nameTools);
 /*
 ==============================================================================