Add import/export LP using CourseBuilder/CourseRestorer see BT#10885

pull/2495/head
jmontoyaa 8 years ago
parent 8725ef0a94
commit 09c92fe68b
  1. 57
      main/lp/learnpath.class.php
  2. 18
      main/lp/lp_controller.php
  3. 11
      main/lp/lp_list.php
  4. 17
      main/lp/lp_upload.php
  5. 1
      main/template/default/learnpath/list.tpl
  6. 13
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php

@ -5,6 +5,7 @@ use Chamilo\CoreBundle\Entity\Repository\CourseRepository;
use Chamilo\CoreBundle\Entity\Repository\ItemPropertyRepository;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpCategory;
@ -17,6 +18,7 @@ use Gedmo\Sortable\Entity\Repository\SortableRepository;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
/**
* Class learnpath
* This class defines the parent attributes and methods for Chamilo learnpaths
@ -2137,7 +2139,6 @@ class learnpath
{
// Get name of the zip file without the extension.
$file_info = pathinfo($file_name);
$filename = $file_info['basename']; // Name including extension.
$extension = $file_info['extension']; // Extension only.
if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), [
'dll',
@ -2156,7 +2157,6 @@ class learnpath
// Check the zip content (real size and file extension).
$zipContentArray = $zipFile->listContent();
$package_type = '';
$at_root = false;
$manifest = '';
$aicc_match_crs = 0;
$aicc_match_au = 0;
@ -2202,11 +2202,17 @@ class learnpath
}
}
}
if (empty($package_type) && 4 == ($aicc_match_crs + $aicc_match_au + $aicc_match_des + $aicc_match_cst)) {
// If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
$package_type = 'aicc';
}
// Try with chamilo course builder
if (empty($package_type)) {
$package_type = 'chamilo';
}
return $package_type;
}
@ -13085,4 +13091,51 @@ EOD;
return '';
}
/**
* Exports a LP to a courseBuilder zip file. It adds the documents related to the LP
*/
public function exportToCourseBuildFormat()
{
if (!api_is_allowed_to_edit()) {
return false;
}
$courseBuilder = new CourseBuilder();
$documentList = [];
/** @var learnpathItem $item */
foreach ($this->items as $item) {
if ($item->get_type() == 'document') {
$documentList[] = $item->get_path();
}
}
$courseBuilder->build_documents(
api_get_session_id(),
$this->get_course_int_id(),
true,
$documentList
);
$courseBuilder->build_learnpaths(
api_get_session_id(),
$this->get_course_int_id(),
true,
[$this->get_id()]
);
$zipFile = CourseArchiver::createBackup($courseBuilder->course);
$zipPath = CourseArchiver::getBackupDir().$zipFile;
$result = DocumentManager::file_send_for_download(
$zipPath,
true,
$this->get_name().'.zip'
);
if ($result) {
api_not_allowed();
}
return true;
}
}

@ -859,6 +859,24 @@ switch ($action) {
exit;
}
break;
case 'export_to_course_build':
if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
api_not_allowed();
}
if (api_is_allowed_to_edit()) {
if (!$lp_found) {
require 'lp_list.php';
} else {
$result = $_SESSION['oLP']->exportToCourseBuildFormat($_GET['lp_id']);
if (!$result) {
require 'lp_list.php';
}
exit;
}
}
require 'lp_list.php';
break;
case 'delete':
if (!$is_allowed_to_edit) {
api_not_allowed(true);

@ -386,6 +386,7 @@ foreach ($categories as $item) {
$lp_auto_launch_icon = null;
$actionSeriousGame = null;
$actionUpdateScormFile = '';
$actionExportToCourseBuild = '';
if ($is_allowed_to_edit) {
// EDIT LP
@ -778,6 +779,15 @@ foreach ($categories as $item) {
);
}
$actionExportToCourseBuild = Display::url(
Display::return_icon(
'backup.png',
get_lang('ExportToChamiloFormat')
),
api_get_self().'?'.api_get_cidreq()
."&action=export_to_course_build&lp_id=$id"
);
if ($is_allowed_to_edit) {
$start_time = $start_time;
$end_time = $end_time;
@ -862,6 +872,7 @@ foreach ($categories as $item) {
'action_serious_game' => $actionSeriousGame,
'action_subscribe_users' => $subscribeUsers,
'action_update_scorm' => $actionUpdateScormFile,
'action_export_to_course_build' => $actionExportToCourseBuild,
];
$lpIsShown = true;

@ -1,5 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
/**
* Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it.
*
@ -63,6 +67,19 @@ if (isset($_POST) && $is_error) {
}
switch ($type) {
case 'chamilo':
$filename = CourseArchiver::importUploadedFile(
$_FILES['user_file']['tmp_name']
);
if ($filename) {
$course = CourseArchiver::readCourse($filename, false);
$courseRestorer = new CourseRestorer($course);
// FILE_SKIP, FILE_RENAME or FILE_OVERWRITE
$courseRestorer->set_file_option(FILE_OVERWRITE);
$courseRestorer->restore();
Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
}
break;
case 'scorm':
$oScorm = new scorm();
$manifest = $oScorm->import_package($_FILES['user_file'], $current_dir);

@ -163,6 +163,7 @@
{{ row.action_delete }}
{{ row.action_order }}
{{ row.action_update_scorm }}
{{ row.action_export_to_course_build }}
</td>
</tr>
{% endfor %}

@ -205,13 +205,13 @@ class CourseBuilder
* @param int $session_id
* @param int $courseId
* @param bool $with_base_content
* @param array $id_list
* @param array $idList
*/
public function build_documents(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$idList = []
) {
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -220,6 +220,11 @@ class CourseBuilder
$avoid_paths = " path NOT LIKE '/shared_folder%' AND
path NOT LIKE '/chat_files%' ";
$documentCondition = '';
if (!empty($idList)) {
$documentCondition = ' d.iid IN ("'.implode('","', $idList).'") AND ';
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
@ -247,6 +252,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths
@ -261,6 +267,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
$avoid_paths AND
p.visibility != 2 $session_condition
ORDER BY path";
@ -288,6 +295,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths AND
@ -302,6 +310,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
$avoid_paths AND
(d.session_id = 0 OR d.session_id IS NULL)

Loading…
Cancel
Save