Fixing query + cosmetic changes

skala
Julio Montoya 14 years ago
parent 2b78f01fc6
commit bd69db7b9c
  1. 59
      main/coursecopy/classes/Course.class.php
  2. 41
      main/coursecopy/classes/CourseBuilder.class.php
  3. 32
      main/coursecopy/classes/CourseRestorer.class.php
  4. 9
      main/coursecopy/copy_course.php

@ -22,19 +22,18 @@ class Course
/**
* Create a new Course-object
*/
function Course()
{
$this->resources = array ();
$this->code = '';
$this->path = '';
$this->backup_path = '';
$this->encoding = api_get_system_encoding();
function __construct() {
$this->resources = array ();
$this->code = '';
$this->path = '';
$this->backup_path = '';
$this->encoding = api_get_system_encoding();
}
/**
* Check if a resource links to the given resource
*/
function is_linked_resource(& $resource_to_check)
{
function is_linked_resource(& $resource_to_check) {
foreach($this->resources as $type => $resources) {
if (is_array($resources)) {
foreach($resources as $id => $resource) {
@ -51,13 +50,14 @@ class Course
}
return false;
}
/**
* Add a resource from a given type to this course
*/
function add_resource(& $resource)
{
function add_resource(& $resource) {
$this->resources[$resource->get_type()][$resource->get_id()] = $resource;
}
/**
* Does this course has resources?
* @param const $resource_type Check if this course has resources of the
@ -73,19 +73,10 @@ class Course
/**
* Show this course resources
*/
function show()
{
function show() {
echo '<pre>';
print_r($this);
echo '</pre>';
// foreach ($this->resources as $id => $resources)
// {
// foreach ($resources as $type => $resource)
// {
// $resource->show();
// }
// }
}
/**
@ -96,31 +87,25 @@ class Course
public function get_sample_text() {
$sample_text = '';
foreach ($this->resources as $type => & $resources) {
if (count($resources) > 0) {
foreach ($resources as $id => & $resource) {
$title = '';
$description = '';
switch ($type) {
case RESOURCE_ANNOUNCEMENT:
$title = $resource->title;
$description = $resource->content;
break;
case RESOURCE_DOCUMENT:
$title = $resource->title;
$description = $resource->comment;
break;
case RESOURCE_EVENT:
$title = $resource->title;
$description = $resource->content;
break;
case RESOURCE_FORUM:
$title = $resource->title;
$description = $resource->description;
@ -130,50 +115,40 @@ class Course
$title = $resource->title;
$description = $resource->description;
break;
case RESOURCE_FORUMPOST:
$title = $resource->title;
$description = $resource->text;
break;
case RESOURCE_FORUMTOPIC:
$title = $resource->title;
break;
case RESOURCE_GLOSSARY:
$title = $resource->name;
$description = $resource->description;
break;
case RESOURCE_LEARNPATH:
$title = $resource->name;
$description = $resource->description;
break;
case RESOURCE_LINK:
$title = $resource->title;
$description = $resource->description;
break;
case RESOURCE_LINKCATEGORY:
$title = $resource->title;
$description = $resource->description;
break;
case RESOURCE_QUIZ:
$title = $resource->title;
$description = $resource->description;
break;
case RESOURCE_QUIZQUESTION:
$title = $resource->question;
$description = $resource->description;
break;
case RESOURCE_SCORM:
$title = $resource->title;
break;
case RESOURCE_SURVEY:
$title = $resource->title;
$description = $resource->subtitle;
@ -193,8 +168,7 @@ class Course
$title = $resource->title;
$description = $resource->content;
break;
case RESOURCE_ATTENDANCE:
case RESOURCE_ATTENDANCE:
$title = $resource->params['name'];
$description = $resource->params['description'];
break;
@ -217,7 +191,6 @@ class Course
}
}
}
return $sample_text;
}
@ -345,8 +318,6 @@ class Course
}
}
}
$this->encoding = api_get_system_encoding();
}
}
}

@ -37,21 +37,21 @@ class CourseBuilder {
/**
* Create a new CourseBuilder
*/
function CourseBuilder($type='', $course = null) {
function __construct($type='', $course = null) {
global $_course;
if (!empty($course['official_code'])){
$_course = $course;
}
$this->course = new Course();
$this->course->code = $_course['official_code'];
$this->course->type = $type;
$this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
$this->course->encoding = api_get_system_encoding(); //current platform encoding
$this->course->db_name = $_course['dbName'];
$this->course->info = $_course;
$this->course = new Course();
$this->course->code = $_course['official_code'];
$this->course->type = $type;
$this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
$this->course->encoding = api_get_system_encoding(); //current platform encoding
$this->course->db_name = $_course['dbName'];
$this->course->info = $_course;
}
/**
* Get the created course
@ -70,15 +70,13 @@ class CourseBuilder {
* in the session, (session_id = 0 or session_id = X)
*/
function build($session_id = 0, $course_code = '', $with_base_content = false) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
if (!empty($session_id) && !empty($course_code)) {
if (!empty($session_id) && !empty($course_code)) {
$this->build_documents($session_id, $course_code, $with_base_content);
$this->build_quizzes($session_id, $course_code, $with_base_content);
$this->build_glossary($session_id, $course_code, $with_base_content);
@ -90,7 +88,6 @@ class CourseBuilder {
$this->build_thematic();
$this->build_attendance();
} else {
$this->build_events();
$this->build_announcements();
$this->build_links();
@ -403,8 +400,8 @@ class CourseBuilder {
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
@ -417,9 +414,9 @@ class CourseBuilder {
$sql = "SELECT * FROM $table_que as questions LEFT JOIN $table_rel as quizz_questions
ON questions.id=quizz_questions.question_id LEFT JOIN $table_qui as exercices
ON exercice_id=exercices.id
WHERE questions.c_id = $course_id AND
quizz_questions.c_id = $course_id AND
exercices.c_id = $course_id AND
WHERE questions.c_id = $course_id AND
quizz_questions.c_id = $course_id AND
exercices.c_id = $course_id AND
quizz_questions.exercice_id IS NULL OR
exercices.active = -1"; // active = -1 means "deleted" test.
$db_result = Database::query($sql);

@ -62,7 +62,7 @@ class CourseRestorer
/**
* Create a new CourseRestorer
*/
function CourseRestorer($course) {
function __construct($course) {
$this->course = $course;
$course_info = api_get_course_info($this->course->code);
$this->course_origin_id = $course_info['real_id'];
@ -98,11 +98,16 @@ class CourseRestorer
}
$this->destination_course_id = $course_info['real_id'];
if (empty($this->course)) {
return false;
}
// Source platform encoding - reading/detection
// The correspondent data field has been added as of version 1.8.6.1.
// The correspondent data field has been added as of version 1.8.6.1
if (empty($this->course->encoding)) {
// The archive has been created by a system wich is prior to 1.8.6.1 version.
// The archive has been created by a system which is prior to 1.8.6.1 version.
// In this case we have to detect the encoding.
$sample_text = $this->course->get_sample_text()."\n";
// Let us exclude ASCII lines, probably they are English texts.
@ -153,7 +158,6 @@ class CourseRestorer
$this->restore_course_settings($destination_course_code);
}
// Restore the item properties
$table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@ -802,13 +806,13 @@ class CourseRestorer
}
$sql = "INSERT INTO ".$link_table." SET
c_id = ".$this->destination_course_id." ,
url = '".self::DBUTF8escapestring($link->url)."',
title = '".self::DBUTF8escapestring($link->title)."',
description = '".self::DBUTF8escapestring($link->description)."',
category_id='".$cat_id."',
on_homepage = '".$link->on_homepage."',
display_order='".($max_order+1)."' $condition_session";
c_id = ".$this->destination_course_id." ,
url = '".self::DBUTF8escapestring($link->url)."',
title = '".self::DBUTF8escapestring($link->title)."',
description = '".self::DBUTF8escapestring($link->description)."',
category_id = '".$cat_id."',
on_homepage = '".$link->on_homepage."',
display_order = '".($max_order+1)."' $condition_session";
Database::query($sql);
$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id();
@ -1907,10 +1911,8 @@ class CourseRestorer
}
}
function DBUTF8escapestring($str)
{
function DBUTF8escapestring($str) {
if (UTF8_CONVERT) $str = utf8_encode($str);
return Database::escape_string($str);
}
}
}

@ -27,6 +27,7 @@ if (!api_is_allowed_to_edit()) {
if (function_exists('ini_set')) {
ini_set('memory_limit', '256M');
ini_set('max_execution_time', 1800);
//ini_set('post_max_size', "512M");
}
// Breadcrumbs
@ -48,17 +49,19 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
} else {
$cb = new CourseBuilder();
$course = $cb->build();
}
}
$cr = new CourseRestorer($course);
$cr->set_file_option($_POST['same_file_name_option']);
$cr->restore($_POST['destination_course']);
Display::display_normal_message(get_lang('CopyFinished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.$_POST['destination_course'].'</a>',false);
} elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
$cb = new CourseBuilder();
$course = $cb->build();
$hidden_fields = array();
$hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
$hidden_fields['destination_course'] = $_POST['destination_course'];
$hidden_fields['destination_course'] = $_POST['destination_course'];
CourseSelectForm :: display_form($course, $hidden_fields, true);
} else {
$table_c = Database :: get_main_table(TABLE_MAIN_COURSE);

Loading…
Cancel
Save