Added copy of work/assignments to coursecopy - refs #6599

1.9.x
Yannick Warnier 12 years ago
parent f19b0a18d0
commit c6d3ca1890
  1. 10
      main/coursecopy/classes/Course.class.php
  2. 8
      main/coursecopy/classes/CourseArchiver.class.php
  3. 22
      main/coursecopy/classes/CourseBuilder.class.php
  4. 25
      main/coursecopy/classes/CourseRecycler.class.php
  5. 40
      main/coursecopy/classes/CourseRestorer.class.php
  6. 1
      main/coursecopy/classes/CourseSelectForm.class.php
  7. 3
      main/coursecopy/classes/Resource.class.php
  8. 36
      main/coursecopy/classes/Work.class.php

@ -181,6 +181,10 @@ class Course
$title = $resource->params['name'];
$description = $resource->params['description'];
break;
case RESOURCE_WORK:
$title = $resource->title;
$description = $resource->description;
break;
default:
break;
}
@ -320,7 +324,11 @@ class Course
$resource->content = api_to_system_encoding($resource->content, $this->encoding);
$resource->reflink = api_to_system_encoding($resource->reflink, $this->encoding);
break;
case RESOURCE_WORK:
$resource->url = api_to_system_encoding($resource->url, $this->encoding);
$resource->title = api_to_system_encoding($resource->title, $this->encoding);
$resource->description = api_to_system_encoding($resource->description, $this->encoding);
break;
default:
break;
}

@ -120,6 +120,14 @@ class CourseArchiver
copyDirTo($course->path . 'upload/announcements/', $doc_dir, false);
}
// Copy work folders (only folders)
if (isset($course->resources[RESOURCE_WORK]) && is_array($course->resources[RESOURCE_WORK])) {
$doc_dir = dirname($backup_dir . '/upload/work/');
@mkdir($doc_dir, $perm_dirs, true);
// @todo: adjust to only create subdirs, but not copy files
copyDirTo($course->path . 'upload/work/', $doc_dir, false);
}
// Zip the course-contents
$zip = new PclZip($zip_dir . $zip_file);
$zip->create($zip_dir . $tmp_dir_name, PCLZIP_OPT_REMOVE_PATH, $zip_dir . $tmp_dir_name . '/');

@ -23,6 +23,7 @@ require_once 'CourseSession.class.php';
require_once 'wiki.class.php';
require_once 'Thematic.class.php';
require_once 'Attendance.class.php';
require_once 'Work.class.php';
/**
* Class which can build a course-object from a Chamilo-course.
@ -51,7 +52,8 @@ class CourseBuilder
'surveys',
'tool_intro',
'thematic',
'wiki'
'wiki',
'works'
);
/* With this array you can filter wich elements of the tools are going to be added in the course obj (only works with LPs) */
@ -986,7 +988,7 @@ class CourseBuilder
}
/**
* Build the Surveys
* Build the attendances
*/
function build_attendance($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
@ -1007,4 +1009,20 @@ class CourseBuilder
$this->course->add_resource($obj);
}
}
/**
* Build the works (or "student publications", or "assignments")
*/
function build_works($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
//$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$course_id = api_get_course_int_id();
$sql = 'SELECT * FROM '.$table_work.' WHERE c_id = '.$course_id.' AND session_id = 0 AND filetype = \'folder\' AND parent_id = 0 AND active = 1';
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result,'ASSOC')) {
$obj = new Work($row);
$this->course->add_resource($obj);
}
}
}

@ -56,6 +56,7 @@ class CourseRecycler
$this->recycle_glossary();
$this->recycle_thematic();
$this->recycle_attendance();
$this->recycle_work();
foreach ($this->course->resources as $type => $resources) {
foreach ($resources as $id => $resource) {
@ -528,4 +529,28 @@ class CourseRecycler
}
}
}
/**
* Recycle Works
*/
function recycle_work($session_id = 0) {
if ($this->course->has_resources(RESOURCE_WORK)) {
$table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_WORK] as $last_id => $obj) {
if (is_numeric($last_id)) {
$cond = array('publication_id = ? AND c_id = ? '=>array($last_id, $this->course_id));
Database::delete($table_work_assignment, $cond);
// The following also deletes student tasks
$cond = array('parent_id = ? AND c_id = ?'=>array($last_id, $this->course_id));
Database::delete($table_work, $cond);
// Finally, delete the main task registry
$cond = array('id = ? AND c_id = ?'=>array($last_id, $this->course_id));
Database::delete($table_work, $cond);
api_item_property_update($this->course_info, TOOL_STUDENTPUBLICATION, $last_id,'StudentPublicationDeleted', api_get_user_id());
}
}
}
}
}

@ -24,6 +24,7 @@ require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
require_once 'Glossary.class.php';
require_once 'wiki.class.php';
require_once 'Thematic.class.php';
require_once 'Work.class.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
@ -72,7 +73,8 @@ class CourseRestorer
//'scorm_documents', ??
'tool_intro',
'thematic',
'wiki'
'wiki',
'works',
);
/** Setting per tool */
@ -2008,6 +2010,42 @@ class CourseRestorer
}
}
/**
* Restore Work
*/
function restore_works($session_id = 0)
{
$perm = api_get_permissions_for_new_directories();
if ($this->course->has_resources(RESOURCE_WORK)) {
$table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_WORK] as $id => $obj) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($obj->params['description'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$obj->params['id'] = null;
$obj->params['c_id'] = $this->destination_course_id;
$last_id = Database::insert($table_work, $obj->params);
// re-create dir
// @todo check security against injection of dir in crafted course backup here!
$path = $obj->params['url'];
$path = '/'.str_replace('/','',substr($path,1));
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/work'.$path;
$r = @mkdir($destination_path, $perm);
if ($r === false) {
error_log('Failed creating directory '.$destination_path.' in course restore for work tool');
}
if (is_numeric($last_id)) {
api_item_property_update($this->destination_course_info, 'work', $last_id,"DirectoryCreated", api_get_user_id());
}
}
}
}
function DBUTF8($str)
{
if (UTF8_CONVERT) {

@ -35,6 +35,7 @@ class CourseSelectForm
$resource_titles[RESOURCE_WIKI] = get_lang('Wiki');
$resource_titles[RESOURCE_THEMATIC] = get_lang('Thematic');
$resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance');
$resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication');
?>
<script>
function exp(item) {

@ -30,6 +30,7 @@ define('RESOURCE_SURVEYINVITATION', 'survey_invitation');
define('RESOURCE_WIKI', 'wiki');
define('RESOURCE_THEMATIC', 'thematic');
define('RESOURCE_ATTENDANCE', 'attendance');
define('RESOURCE_WORK', 'work');
/**
* Representation of a resource in a Chamilo-course.
@ -179,6 +180,8 @@ class Resource {
return TOOL_COURSE_PROGRESS;
case RESOURCE_ATTENDANCE:
return TOOL_ATTENDANCE;
case RESOURCE_WORK:
return TOOL_STUDENTPUBLICATION;
default:
return null;
}

@ -0,0 +1,36 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Work/Assignment/Student publication backup script
* @package chamilo.backup
*/
/**
* Code
*/
require_once 'Resource.class.php';
/**
* An event
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @package chamilo.backup
*/
class Work extends Resource
{
public $params = array();
/**
* Create a new Work
*
* @param array parameters
*/
public function __construct($params)
{
parent::Resource($params['id'], RESOURCE_WORK);
$this->params = $params;
}
public function show()
{
parent::show();
echo $this->params['title'];
}
}
Loading…
Cancel
Save