Adding event attachments when copying a course from a zip file see CT#519

skala
Julio Montoya 16 years ago
parent f56e947152
commit 77fc12ccab
  1. 34
      main/coursecopy/classes/CourseArchiver.class.php
  2. 17
      main/coursecopy/classes/CourseBuilder.class.php
  3. 48
      main/coursecopy/classes/CourseRestorer.class.php
  4. 38
      main/coursecopy/classes/Event.class.php

@ -89,17 +89,43 @@ class CourseArchiver
}
// Copy all scorm documents to the temp-dir
if (is_array($course->resources[RESOURCE_SCORM]))
{
foreach ($course->resources[RESOURCE_SCORM] as $id => $document)
{
if (is_array($course->resources[RESOURCE_SCORM])) {
foreach ($course->resources[RESOURCE_SCORM] as $id => $document) {
$doc_dir = dirname($backup_dir.$document->path);
// error_log($doc_dir);
@mkdir($doc_dir, $perm_dirs, true);
//error_log($course->path.$document->path);
//error_log('----------');
copyDirTo($course->path.$document->path, $doc_dir, false);
}
}
//Copy calendar attachments
if (is_array($course->resources[RESOURCE_EVENT])) {
$doc_dir = dirname($backup_dir.'/upload/calendar/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path.'upload/calendar/', $doc_dir, false);
}
//Copy learningpath author image
if (is_array($course->resources[RESOURCE_LEARNPATH])) {
$doc_dir = dirname($backup_dir.'/upload/learning_path/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path.'upload/learning_path/', $doc_dir, false);
}
//Copy announcements attachments
if (is_array($course->resources[RESOURCE_ANNOUNCEMENT])) {
$doc_dir = dirname($backup_dir.'/upload/announcements/');
@mkdir($doc_dir, $perm_dirs, true);
copyDirTo($course->path.'upload/announcements/', $doc_dir, false);
}
// Zip the course-contents
$zip = new PclZip($zip_dir.$zip_file);

@ -57,9 +57,8 @@ class CourseBuilder
/**
* Build the course-object
*/
function build($session_id = 0,$course_code = '')
{
function build($session_id = 0,$course_code = '') {
if (!empty($session_id) && !empty($course_code)) {
$course_info = api_get_course_info($course_code);
$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES,$course_info['dbName']);
@ -122,6 +121,8 @@ class CourseBuilder
}
}
}
return $this->course;
}
/**
@ -510,11 +511,15 @@ class CourseBuilder
$table = Database :: get_course_table(TABLE_AGENDA);
$sql = 'SELECT * FROM '.$table.' WHERE session_id = 0';
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result))
{
$event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date);
while ($obj = Database::fetch_object($db_result)) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
$sql = 'SELECT path, comment, filename, size FROM '.$table_attachment.' WHERE agenda_id = '.$obj->id.'';
$result = Database::query($sql);
$attachment_obj = Database::fetch_object($result);
$event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date, $attachment_obj->path, $attachment_obj->filename, $attachment_obj->size, $attachment_obj->comment);
$this->course->add_resource($event);
}
}
/**
* Build the course-descriptions

@ -706,6 +706,7 @@ class CourseRestorer
if ($this->course->has_resources(RESOURCE_EVENT)) {
$table = Database :: get_course_table(TABLE_AGENDA, $this->course->destination_db);
$resources = $this->course->resources;
//var_dump($resources[RESOURCE_EVENT]); exit;
foreach ($resources[RESOURCE_EVENT] as $id => $event) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($event->content, $this->course->code, $this->course->destination_path);
@ -719,24 +720,37 @@ class CourseRestorer
$origin_path = $this->course->backup_path.'/upload/calendar/';
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT, $this->course->orig);
$sql = 'SELECT path, comment, size, filename FROM '.$table_attachment.' WHERE agenda_id = '.$id;
$attachment_event = Database::query($sql);
$attachment_event = Database::fetch_object($attachment_event);
if (file_exists($origin_path.$attachment_event->path) && !is_dir($origin_path.$attachment_event->path) ) {
$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
//$copy_result = true;
if ($copy_result == true) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT, $this->course->destination_db);
$sql = "INSERT INTO ".$table_attachment." SET path = '".Database::escape_string($new_filename)."', comment = '".Database::escape_string($attachment_event->comment)."', size = '".$attachment_event->size."', filename = '".$attachment_event->filename."' , agenda_id = '".$new_event_id."' ";
Database::query($sql);
}
}
}
if (!empty($this->course->orig)) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT, $this->course->orig);
$sql = 'SELECT path, comment, size, filename FROM '.$table_attachment.' WHERE agenda_id = '.$id;
$attachment_event = Database::query($sql);
$attachment_event = Database::fetch_object($attachment_event);
if (file_exists($origin_path.$attachment_event->path) && !is_dir($origin_path.$attachment_event->path) ) {
$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
//$copy_result = true;
if ($copy_result == true) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT, $this->course->destination_db);
$sql = "INSERT INTO ".$table_attachment." SET path = '".Database::escape_string($new_filename)."', comment = '".Database::escape_string($attachment_event->comment)."', size = '".$attachment_event->size."', filename = '".$attachment_event->filename."' , agenda_id = '".$new_event_id."' ";
Database::query($sql);
}
}
} else {
// get the info of the file
if(!empty($event->attachment_path) && is_file($origin_path.$event->attachment_path) && is_readable($origin_path.$event->attachment_path)) {
$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
if ($copy_result == true) {
$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT, $this->course->destination_db);
$sql = "INSERT INTO ".$table_attachment." SET path = '".Database::escape_string($new_filename)."', comment = '".Database::escape_string($event->attachment_comment)."', size = '".$event->attachment_size."', filename = '".$event->attachment_filename."' , agenda_id = '".$new_event_id."' ";
Database::query($sql);
}
}
}
}
}
}
/**

@ -25,6 +25,26 @@ class Event extends Resource
* The end date
*/
var $end_date;
/**
* The attachment path
*/
var $attachment_path;
/**
* The attachment filename
*/
var $attachment_filename;
/**
* The attachment size
*/
var $attachment_size;
/**
* The attachment comment
*/
var $attachment_comment;
/**
* Create a new Event
* @param int $id
@ -34,13 +54,19 @@ class Event extends Resource
* @param string $hour
* @param int $duration
*/
function Event($id,$title,$content,$start_date,$end_date)
{
function Event($id,$title,$content,$start_date,$end_date, $attachment_path, $attachment_filename, $attachment_size, $attachment_comment) {
parent::Resource($id,RESOURCE_EVENT);
$this->title = $title;
$this->content = $content;
$this->start_date = $start_date;
$this->end_date = $end_date;
$this->title = $title;
$this->content = $content;
$this->start_date = $start_date;
$this->end_date = $end_date;
$this->attachment_path = $attachment_path;
$this->attachment_filename = $attachment_filename;
$this->attachment_size = $attachment_size;
$this->attachment_comment = $attachment_comment;
}
/**
* Show this Event

Loading…
Cancel
Save