Adding thematic to the course copy see #1884

skala
Julio Montoya 15 years ago
parent fc73b9ffcd
commit 76c9178169
  1. 14
      main/coursecopy/classes/Course.class.php
  2. 36
      main/coursecopy/classes/CourseBuilder.class.php
  3. 69
      main/coursecopy/classes/CourseRestorer.class.php
  4. 6
      main/coursecopy/classes/CourseSelectForm.class.php
  5. 4
      main/coursecopy/classes/Resource.class.php
  6. 1
      main/coursecopy/create_backup.php
  7. 5
      main/inc/lib/database.lib.php
  8. 1
      main/inc/lib/main_api.lib.php

@ -64,10 +64,8 @@ class Course
* given type. If no type is given, check if course has resources of any
* type.
*/
function has_resources($resource_type = null)
{
if( $resource_type != null)
{
function has_resources($resource_type = null) {
if( $resource_type != null) {
return is_array($this->resources[$resource_type]) && ( count($this->resources[$resource_type]) > 0 );
}
return (count($this->resources) > 0);
@ -180,21 +178,21 @@ class Course
$title = $resource->title;
$description = $resource->subtitle;
break;
case RESOURCE_SURVEYQUESTION:
$title = $resource->survey_question;
$description = $resource->survey_question_comment;
break;
case RESOURCE_TOOL_INTRO:
$description = $resource->intro_text;
break;
case RESOURCE_WIKI:
$title = $resource->title;
$description = $resource->content;
break;
case RESOURCE_THEMATIC:
$title = $resource->title;
$description = $resource->content;
break;
default:
break;
}

@ -21,6 +21,7 @@ require_once 'SurveyQuestion.class.php';
require_once 'Glossary.class.php';
require_once 'CourseSession.class.php';
require_once 'wiki.class.php';
require_once 'Thematic.class.php';
/**
* Class which can build a course-object from a Chamilo-course.
@ -80,7 +81,8 @@ class CourseBuilder {
$this->build_learnpaths($session_id, $course_code,$with_base_content);
$this->build_links($session_id, $course_code, $with_base_content);
$this->build_course_descriptions($session_id, $course_code, $with_base_content);
$this->build_wiki($session_id, $course_code, $with_base_content);
$this->build_wiki($session_id, $course_code, $with_base_content);
$this->build_thematic($session_id, $course_code, $with_base_content);
} else {
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@ -96,7 +98,7 @@ class CourseBuilder {
$this->build_learnpaths();
$this->build_surveys();
$this->build_glossary();
$this->build_thematic();
}
//TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
@ -763,4 +765,34 @@ class CourseBuilder {
$this->course->add_resource($wiki);
}
}
/**
* Build the Surveys
*/
function build_thematic() {
$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);
$sql = 'SELECT * FROM '.$table_thematic.' WHERE session_id = 0 ';
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result,'ASSOC')) {
$thematic = new Thematic($row);
$sql = 'SELECT * FROM '.$table_thematic_advance.' WHERE thematic_id = '.$row['id'];
$result = Database::query($sql);
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
$thematic->add_thematic_advance($sub_row);
}
$sql = 'SELECT * FROM '.$table_thematic_plan.' WHERE thematic_id = '.$row['id'];
$result = Database::query($sql);
while ($sub_row = Database::fetch_array($result,'ASSOC')) {
$thematic->add_thematic_plan($sub_row);
}
$this->course->add_resource($thematic);
}
}
}

@ -25,6 +25,8 @@ require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
//require_once 'rmdirr.php';
require_once 'Glossary.class.php';
require_once 'wiki.class.php';
require_once 'Thematic.class.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
@ -44,6 +46,9 @@ class CourseRestorer
* The course-object
*/
var $course;
var $destination_course_info;
/**
* What to do with files with same name (FILE_SKIP, FILE_RENAME or
* FILE_OVERWRITE)
@ -73,16 +78,18 @@ class CourseRestorer
*/
function restore($destination_course_code = '', $session_id = 0, $update_course_settings = false, $respect_base_content = false) {
if ($destination_course_code == '') {
if ($destination_course_code == '') {
$course_info = api_get_course_info();
$this->destination_course_info = $course_info;
$this->course->destination_db = $course_info['dbName'];
$this->course->destination_path = $course_info['path'];
} else {
$course_info = Database :: get_course_info($destination_course_code);
$this->course->destination_db = $course_info['database'];
$this->course->destination_path = $course_info['directory'];
}
$course_info = api_get_course_info($destination_course_code);
$this->destination_course_info = $course_info;
$this->course->destination_db = $course_info['dbName'];
$this->course->destination_path = $course_info['path'];
}
// Source platform encoding - reading/detection
// The correspondent data field has been added as of version 1.8.6.1.
@ -112,6 +119,7 @@ class CourseRestorer
$this->restore_links($session_id);
$this->restore_course_descriptions($session_id);
$this->restore_wiki($session_id);
$this->restore_thematic($session_id);
} else {
$this->restore_links();
$this->restore_tool_intro();
@ -126,6 +134,7 @@ class CourseRestorer
$this->restore_student_publication();
$this->restore_glossary();
$this->restore_wiki();
$this->restore_thematic();
}
if ($update_course_settings) {
@ -1083,6 +1092,7 @@ class CourseRestorer
}
return $new_id;
}
/**
* Restore surveys
*/
@ -1724,4 +1734,49 @@ class CourseRestorer
}
}
}
}
/**
* Restore surveys
*/
function restore_thematic() {
if ($this->course->has_resources(RESOURCE_THEMATIC)) {
$table_thematic = Database :: get_course_table(TABLE_THEMATIC, $this->course->destination_db);
$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE, $this->course->destination_db);
$table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN, $this->course->destination_db);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$thematic->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($thematic->content, $this->course->code, $this->course->destination_path);
$doc = '';
$thematic->params['id'] = null;
$last_id = Database::insert($table_thematic, $thematic->params, true);
if (is_numeric($last_id)) {
foreach($thematic->thematic_advance_list as $thematic_advance) {
unset($thematic_advance['id']);
$thematic_advance['attendance_id'] = 0;
$thematic_advance['thematic_id'] = $last_id;
$my_id = Database::insert($table_thematic_advance, $thematic_advance, true);
if (is_numeric($my_id)) {
api_item_property_update($this->destination_course_info, 'thematic_advance', $my_id,"ThematicAdvanceAdded", api_get_user_id());
}
}
foreach($thematic->thematic_plan_list as $thematic_plan) {
unset($thematic_advance['id']);
$thematic_plan['thematic_id'] = $last_id;
$my_id = Database::insert($table_thematic_plan, $thematic_plan, true);
if (is_numeric($my_id)) {
api_item_property_update($this->destination_course_info, 'thematic_plan', $my_id, "ThematicPlanAdded", api_get_user_id());
}
}
}
}
}
}
}

@ -31,6 +31,7 @@ class CourseSelectForm
$resource_titles[RESOURCE_SURVEY] = get_lang('Survey');
$resource_titles[RESOURCE_GLOSSARY] = get_lang('Glossary');
$resource_titles[RESOURCE_WIKI] = get_lang('Wiki');
$resource_titles[RESOURCE_THEMATIC] = get_lang('Thematic');
?>
<script language="JavaScript" type="text/javascript">
@ -97,12 +98,13 @@ class CourseSelectForm
echo '<input type="hidden" name="origin_course" value="'.$hidden_fields['origin_course'].'"/>';
echo '<input type="hidden" name="destination_session" value="'.$hidden_fields['destination_session'].'"/>';
echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>';
}
}
$element_count = 0;
foreach ($course->resources as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
//Resources to avoid
case RESOURCE_LINKCATEGORY :
case RESOURCE_FORUMCATEGORY :
case RESOURCE_FORUMPOST :
@ -110,7 +112,7 @@ class CourseSelectForm
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
case RESOURCE_SCORM:
case RESOURCE_SCORM:
break;
default :
echo '<img id="img_'.$type.'" src="../img/1.gif" onclick="javascript:exp('."'$type'".');" />&nbsp;';

@ -28,6 +28,8 @@ define('RESOURCE_SURVEYQUESTION','survey_question');
define('RESOURCE_SURVEYINVITATION','survey_invitation');
define('RESOURCE_WIKI','wiki');
define('RESOURCE_THEMATIC','thematic');
/**
* Representation of a resource in a Chamilo-course.
* This is a base class of which real resource-classes (for Links,
@ -169,6 +171,8 @@ class Resource
return TOOL_GLOSSARY;
case RESOURCE_WIKI:
return TOOL_WIKI;
case RESOURCE_THEMATIC:
return TOOL_ATTENDANCE;
default:
return null;
}

@ -97,7 +97,6 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
$values['backup_option'] = 'full_backup';
$form->setDefaults($values);
$form->display();
}
}

@ -1057,7 +1057,7 @@ class Database {
* Experimental useful database insert
* @todo lot of stuff to do here
*/
public static function insert($table_name, $attributes) {
public static function insert($table_name, $attributes , $show_query = false) {
if (empty($attributes) || empty($table_name)) {
return false;
}
@ -1070,6 +1070,9 @@ class Database {
if (!empty($params) && !empty($values)) {
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')';
$result = self::query($sql);
if ($show_query) {
echo $sql;
}
return self::get_last_insert_id();
}
return false;

@ -2598,6 +2598,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
if (Database::affected_rows() == 0) {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, id_session)
VALUES ('$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
$res = Database::query($sql);
if (!$res) {
return false;

Loading…
Cancel
Save