Minor - small merge from 1.11.x

pull/2487/merge
Julio Montoya 7 years ago
parent d36367f5a6
commit a416f3bc14
  1. 11
      src/CoreBundle/Component/Editor/CkEditor/CkEditor.php
  2. 2
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php
  3. 5
      src/CoreBundle/Component/Editor/Driver/CourseDriver.php
  4. 36
      src/CoreBundle/Component/Utils/ChamiloApi.php
  5. 31
      src/CoreBundle/Composer/ScriptHandler.php
  6. 28
      src/CourseBundle/Component/CourseCopy/Course.php
  7. 387
      src/CourseBundle/Component/CourseCopy/CourseBuilder.php
  8. 4
      src/CourseBundle/Component/CourseCopy/CourseRecycler.php
  9. 106
      src/CourseBundle/Component/CourseCopy/CourseRestorer.php
  10. 379
      src/CourseBundle/Component/CourseCopy/CourseSelectForm.php
  11. 3
      src/CourseBundle/Component/CourseCopy/Resources/CourseCopyLearnpath.php

@ -4,6 +4,7 @@
namespace Chamilo\CoreBundle\Component\Editor\CkEditor;
use Chamilo\CoreBundle\Component\Editor\Editor;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
//use Symfony\Component\Routing\Generator\UrlGenerator;
@ -55,13 +56,9 @@ class CkEditor extends Editor
{
$style = '';
if (trim($this->value) == '<html><head><title></title></head><body></body></html>' || $this->value == '') {
$cssFile = api_get_path(SYS_CSS_PATH).'themes/'.api_get_visual_theme().'/editor.css';
if (!is_file($cssFile)) {
$cssFile = api_get_path(WEB_CSS_PATH).'editor.css';
} else {
$cssFile = api_get_path(WEB_CSS_PATH).'themes/'.api_get_visual_theme().'/editor.css';
}
$style = '<link href="'.$cssFile.'" rel="stylesheet" type="text/css" />';
$style = api_get_css_asset('bootstrap/dist/css/bootstrap.min.css');
$style .= api_get_css_asset('fontawesome/css/font-awesome.min.css');
$style .= api_get_css(ChamiloApi::getEditorDocStylePath());
}
$html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'" class="ckeditor">

@ -181,7 +181,7 @@ class Basic extends Toolbar
$config['image2_chamilo_alignClasses'] = [
'pull-left',
'block-center',
'text-center',
'pull-right',
'img-va-baseline',
'img-va-top',

@ -256,7 +256,7 @@ class CourseDriver extends Driver implements DriverInterface
$this->connector->course,
$realPath,
'file',
intval($result['size']),
(int) $result['size'],
$result['name']
);
}
@ -335,7 +335,7 @@ class CourseDriver extends Driver implements DriverInterface
// Needed to load course information in elfinder
$this->setConnectorFromPlugin();
if ($this->allowToEdit() == false) {
if ($this->allowToEdit() === false) {
return false;
}
@ -348,7 +348,6 @@ class CourseDriver extends Driver implements DriverInterface
// Removing course path
$newPath = str_replace($realPathRoot, '/', $realPath);
$documentId = add_document(
$_course,
$newPath,

@ -253,4 +253,40 @@ class ChamiloApi
return $prefix.$text;
}
/**
* Get the stylesheet path for HTML documents created with CKEditor.
*
* @return string
*/
public static function getEditorDocStylePath()
{
$visualTheme = api_get_visual_theme();
$cssFile = api_get_path(SYS_CSS_PATH)."themes/$visualTheme/document.css";
if (is_file($cssFile)) {
return api_get_path(WEB_CSS_PATH)."themes/$visualTheme/document.css";
}
return api_get_path(WEB_CSS_PATH).'document.css';
}
/**
* Get the stylesheet path for HTML blocks created with CKEditor.
*
* @return string
*/
public static function getEditorBlockStylePath()
{
$visualTheme = api_get_visual_theme();
$cssFile = api_get_path(SYS_CSS_PATH)."themes/$visualTheme/editor_content.css";
if (is_file($cssFile)) {
return api_get_path(WEB_CSS_PATH)."themes/$visualTheme/editor_content.css";
}
return api_get_path(WEB_CSS_PATH).'editor_content.css';
}
}

@ -95,6 +95,15 @@ class ScriptHandler
__DIR__.'/../../../../plugin/skype',
__DIR__.'/../../../../main/newscorm',
__DIR__.'/../../../../main/exercice',
// js files
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/docs',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/nuget',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/grunt',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/test-infra',
__DIR__.'/../../../../web/assets/bootstrap/grunt',
__DIR__.'/../../../../web/assets/bootstrap/nuget',
__DIR__.'/../../../../web/assets/bootstrap/docs',
__DIR__.'/../../../../web/assets/bootstrap/test-infra',
];
return $paths;
@ -196,6 +205,17 @@ class ScriptHandler
__DIR__.'/../../../../src/Chamilo/CoreBundle/Entity/GroupRelTag.php',
__DIR__.'/../../../../src/Chamilo/CoreBundle/Entity/GroupRelUser.php',
__DIR__.'/../../../../src/Chamilo/CoreBundle/Entity/Groups.php',
__DIR__.'/../../../../src/Chamilo/UserBundle/Entity/Repository/UserRepository.php',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/Gemfile',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/Gemfile.lock',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/Gruntfile.js',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/package.js',
__DIR__.'/../../../../app/Resources/public/assets/bootstrap/package.json',
__DIR__.'/../../../../web/assets/bootstrap/Gemfile',
__DIR__.'/../../../../web/assets/bootstrap/Gemfile.lock',
__DIR__.'/../../../../web/assets/bootstrap/Gruntfile.js',
__DIR__.'/../../../../web/assets/bootstrap/package.js',
__DIR__.'/../../../../web/assets/bootstrap/package.json',
];
return $files;
@ -209,7 +229,16 @@ class ScriptHandler
{
$appCss = __DIR__.'/../../../../app/Resources/public/css/';
$newPath = __DIR__.'/../../../../web/css/';
$cssFiles = ['base.css', 'chat.css', 'editor.css', 'markdown.css', 'print.css', 'responsive.css', 'scorm.css'];
$cssFiles = [
'base.css',
'chat.css',
'document.css',
'editor_content.css',
'markdown.css',
'print.css',
'responsive.css',
'scorm.css',
];
$fs = new Filesystem();

@ -340,10 +340,20 @@ class Course
public static function serialize($course)
{
if (extension_loaded('igbinary')) {
return igbinary_serialize($course);
$serialized = igbinary_serialize($course);
} else {
return serialize($course);
$serialized = serialize($course);
}
// Compress
if (function_exists('gzdeflate')) {
$deflated = gzdeflate($serialized, 9);
if ($deflated !== false) {
$deflated = $serialized;
}
}
return $serialized;
}
/**
@ -355,10 +365,20 @@ class Course
*/
public static function unserialize($course)
{
// Uncompress
if (function_exists('gzdeflate')) {
$inflated = @gzinflate($course);
if ($inflated !== false) {
$course = $inflated;
}
}
if (extension_loaded('igbinary')) {
return igbinary_unserialize($course);
$unserialized = igbinary_unserialize($course);
} else {
return unserialize($course);
$unserialized = unserialize($course);
}
return $unserialized;
}
}

@ -19,6 +19,7 @@ use Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumPost;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumTopic;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Glossary;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\LearnPathCategory;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Link;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\LinkCategory;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Quiz;
@ -31,6 +32,7 @@ use Chamilo\CourseBundle\Component\CourseCopy\Resources\Thematic;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\ToolIntro;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Wiki;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Work;
use Chamilo\CourseBundle\Entity\CLpCategory;
use CourseManager;
use Database;
use Link as LinkManager;
@ -63,6 +65,7 @@ class CourseBuilder
'glossary',
'quizzes',
'test_category',
'learnpath_category',
'learnpaths',
'links',
'surveys',
@ -73,6 +76,29 @@ class CourseBuilder
'gradebook',
];
public $toolToName = [
'announcements' => RESOURCE_ANNOUNCEMENT,
'attendance' => RESOURCE_ATTENDANCE,
'course_descriptions' => RESOURCE_COURSEDESCRIPTION,
'documents' => RESOURCE_DOCUMENT,
'events' => RESOURCE_EVENT,
'forum_category' => RESOURCE_FORUMCATEGORY,
'forums' => RESOURCE_FORUM,
'forum_topics' => RESOURCE_FORUMTOPIC,
'glossary' => RESOURCE_GLOSSARY,
'quizzes' => RESOURCE_QUIZ,
'test_category' => RESOURCE_TEST_CATEGORY,
'learnpath_category' => RESOURCE_LEARNPATH_CATEGORY,
'learnpaths' => RESOURCE_LEARNPATH,
'links' => RESOURCE_LINK,
'surveys' => RESOURCE_SURVEY,
'tool_intro' => RESOURCE_TOOL_INTRO,
'thematic' => RESOURCE_THEMATIC,
'wiki' => RESOURCE_WIKI,
'works' => RESOURCE_WORK,
'gradebook' => RESOURCE_GRADEBOOK,
];
/* With this array you can filter wich elements of the tools are going
to be added in the course obj (only works with LPs) */
public $specific_id_list = [];
@ -131,34 +157,58 @@ class CourseBuilder
*
* @param int $session_id
* @param string $courseCode
* @param bool $withBaseContent true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X)
* @param bool $withBaseContent true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X)
* @param array $parseOnlyToolList
* @param array $toolsFromPost
*
* @return Course The course object structure
*/
public function build(
$session_id = 0,
$courseCode = '',
$withBaseContent = false
$withBaseContent = false,
$parseOnlyToolList = [],
$toolsFromPost = []
) {
$table_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course = api_get_course_info($courseCode);
$courseId = $course['real_id'];
foreach ($this->tools_to_build as $tool) {
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) {
continue;
}
$function_build = 'build_'.$tool;
$specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
$buildOrphanQuestions = true;
if ($tool === 'quizzes') {
if (!isset($toolsFromPost[RESOURCE_QUIZ][-1])) {
$buildOrphanQuestions = false;
}
$this->$function_build(
$session_id,
$courseId,
$withBaseContent,
$specificIdList
);
// Force orphan load
if ($this->course->type === 'complete') {
$buildOrphanQuestions = true;
}
$this->build_quizzes(
$session_id,
$courseId,
$withBaseContent,
$specificIdList,
$buildOrphanQuestions
);
} else {
$this->$function_build(
$session_id,
$courseId,
$withBaseContent,
$specificIdList
);
}
}
// Add asset
if ($course['course_image_source'] && basename($course['course_image_source']) != 'course.png') {
if ($course['course_image_source'] && basename($course['course_image_source']) !== 'course.png') {
// Add course image courses/XXX/course-pic85x85.png
$asset = new Asset(
$course['course_image_source'],
@ -176,22 +226,28 @@ class CourseBuilder
}
// Once we've built the resources array a bit more, try to get items
// from the item_property table and order them in the "resources" array
// from the item_property table and order them in the "resources" array
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
foreach ($this->course->resources as $type => $resources) {
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) {
continue;
}
foreach ($resources as $id => $resource) {
$tool = $resource->get_tool();
if ($tool != null) {
$sql = "SELECT * FROM $table_properties
WHERE
c_id = $courseId AND
tool = '".$tool."' AND
ref = '".$resource->get_id()."'";
$res = Database::query($sql);
$all_properties = [];
while ($item_property = Database::fetch_array($res)) {
$all_properties[] = $item_property;
if ($resource) {
$tool = $resource->get_tool();
if ($tool != null) {
$sql = "SELECT * FROM $table
WHERE
c_id = $courseId AND
tool = '".$tool."' AND
ref = '".$resource->get_id()."'";
$res = Database::query($sql);
$properties = [];
while ($property = Database::fetch_array($res)) {
$properties[] = $property;
}
$this->course->resources[$type][$id]->item_properties = $properties;
}
$this->course->resources[$type][$id]->item_properties = $all_properties;
}
}
}
@ -228,7 +284,7 @@ class CourseBuilder
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
@ -609,16 +665,18 @@ class CourseBuilder
/**
* Build the Quizzes.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
* @param bool $buildOrphanQuestions
*/
public function build_quizzes(
$session_id = 0,
$courseId = 0,
$withBaseContent = false,
$idList = []
$idList = [],
$buildOrphanQuestions = true
) {
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -632,15 +690,15 @@ class CourseBuilder
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true
);
@ -652,7 +710,7 @@ class CourseBuilder
c_id = $courseId AND
$idCondition
active >=0
$session_condition ";
$sessionCondition ";
} else {
// Select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
$sql = "SELECT * FROM $table_qui
@ -663,9 +721,9 @@ class CourseBuilder
(session_id = 0 OR session_id IS NULL)";
}
$sql .= 'ORDER BY title';
$sql .= ' ORDER BY title';
$db_result = Database::query($sql);
$questionList = [];
while ($obj = Database::fetch_object($db_result)) {
if (strlen($obj->sound) > 0) {
$sql = "SELECT id FROM $table_doc
@ -674,40 +732,44 @@ class CourseBuilder
$doc = Database::fetch_object($res);
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj);
$sql = 'SELECT * FROM '.$table_rel.'
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$quiz->add_question($obj2->question_id, $obj2->question_order);
$questionList[] = $obj2->question_id;
}
$this->course->add_resource($quiz);
}
if (!empty($courseId)) {
$this->build_quiz_questions($courseId);
$this->build_quiz_questions($courseId, $questionList, $buildOrphanQuestions);
} else {
$this->build_quiz_questions();
$this->build_quiz_questions(0, $questionList, $buildOrphanQuestions);
}
}
/**
* Build the Quiz-Questions.
*
* @param int $courseId Internal course ID
* @param int $courseId Internal course ID
* @param array $questionList
* @param bool $buildOrphanQuestions
*/
public function build_quiz_questions($courseId = 0)
public function build_quiz_questions($courseId = 0, $questionList = [], $buildOrphanQuestions = true)
{
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
$courseId = (int) $courseId;
$questionListToString = implode("','", $questionList);
// Building normal tests.
// Building normal tests (many queries)
$sql = "SELECT * FROM $table_que
WHERE c_id = $courseId ";
WHERE c_id = $courseId AND id IN ('$questionListToString')";
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
@ -736,7 +798,6 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_ans.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer(
$obj2->id,
@ -762,106 +823,106 @@ class CourseBuilder
$this->course->add_resource($question);
}
// Building a fictional test for collecting orphan questions.
// When a course is emptied this option should be activated (true).
$build_orphan_questions = !empty($_POST['recycle_option']);
// 1st union gets the orphan questions from deleted exercises
// 2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id = r.c_id )
WHERE ex.c_id = $courseId AND ex.active = '-1'
)
UNION
(
SELECT question_id, q.* FROM $table_que q
left OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = $courseId AND r.question_id is null
)
UNION
(
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = $courseId AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)
";
if ($buildOrphanQuestions) {
// Building a fictional test for collecting orphan questions.
// When a course is emptied this option should be activated (true).
//$build_orphan_questions = !empty($_POST['recycle_option']);
// 1st union gets the orphan questions from deleted exercises
// 2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id = r.c_id)
WHERE ex.c_id = $courseId AND ex.active = '-1'
)
UNION
(
SELECT question_id, q.* FROM $table_que q
left OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = $courseId AND r.question_id is null
)
UNION
(
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = $courseId AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)
";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$build_orphan_questions = true;
$orphanQuestionIds = [];
while ($obj = Database::fetch_object($result)) {
// Orphan questions
if (!empty($obj->question_id)) {
$obj->id = $obj->question_id;
}
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$orphanQuestionIds = [];
while ($obj = Database::fetch_object($result)) {
// Orphan questions
if (!empty($obj->question_id)) {
$obj->id = $obj->question_id;
}
// Avoid adding the same question twice
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
$obj->description,
$obj->ponderation,
$obj->type,
$obj->position,
$obj->picture,
$obj->level,
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($db_result2)) {
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
);
// Avoid adding the same question twice
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
$obj->description,
$obj->ponderation,
$obj->type,
$obj->position,
$obj->picture,
$obj->level,
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($db_result2)) {
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
);
}
$orphanQuestionIds[] = $obj->id;
}
$orphanQuestionIds[] = $obj->id;
$this->course->add_resource($question);
}
$this->course->add_resource($question);
}
}
}
if ($build_orphan_questions) {
$obj = [
'id' => -1,
'title' => get_lang('OrphanQuestions', ''),
'type' => 2,
];
$newQuiz = new Quiz((object) $obj);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
$obj = [
'id' => -1,
'title' => get_lang('OrphanQuestions'),
'type' => 2,
];
$newQuiz = new Quiz((object) $obj);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
$this->course->add_resource($newQuiz);
}
$this->course->add_resource($newQuiz);
}
/**
* Build the orphan questions.
* @deprecated
* Build the orphan questions
*/
public function build_quiz_orphan_questions()
{
@ -1211,19 +1272,19 @@ class CourseBuilder
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true
);
}
$sql = 'SELECT * FROM '.$table.'
WHERE c_id = '.$courseId.' '.$session_condition;
WHERE c_id = '.$courseId.' '.$sessionCondition;
} else {
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = 'SELECT * FROM '.$table.'
@ -1242,6 +1303,29 @@ class CourseBuilder
}
}
/**
* @param int $session_id
* @param int $courseId
* @param bool $withBaseContent
* @param array $idList
*/
public function build_learnpath_category($session_id = 0, $courseId = 0, $withBaseContent = false, $idList = [])
{
$categories = \learnpath::getCategories($courseId);
/** @var CLpCategory $item */
foreach ($categories as $item) {
$categoryId = $item->getId();
if (!empty($idList)) {
if (!in_array($categoryId, $idList)) {
continue;
}
}
$category = new LearnPathCategory($categoryId, $item);
$this->course->add_resource($category);
}
}
/**
* Build the learnpaths.
*
@ -1267,19 +1351,19 @@ class CourseBuilder
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true
);
}
$sql = 'SELECT * FROM '.$table_main.'
WHERE c_id = '.$courseId.' '.$session_condition;
WHERE c_id = '.$courseId.' '.$sessionCondition;
} else {
$sql = 'SELECT * FROM '.$table_main.'
WHERE c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)';
@ -1294,10 +1378,10 @@ class CourseBuilder
if ($result) {
while ($obj = Database::fetch_object($result)) {
$items = [];
$sql = "SELECT * FROM ".$table_item."
$sql = "SELECT * FROM $table_item
WHERE c_id = '$courseId' AND lp_id = ".$obj->id;
$db_items = Database::query($sql);
while ($obj_item = Database::fetch_object($db_items)) {
$resultItem = Database::query($sql);
while ($obj_item = Database::fetch_object($resultItem)) {
$item['id'] = $obj_item->id;
$item['item_type'] = $obj_item->item_type;
$item['ref'] = $obj_item->ref;
@ -1356,6 +1440,7 @@ class CourseBuilder
$obj->publicated_on,
$obj->expired_on,
$obj->session_id,
$obj->category_id,
$items
);
@ -1411,13 +1496,13 @@ class CourseBuilder
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true
);
@ -1426,10 +1511,10 @@ class CourseBuilder
//@todo check this queries are the same ...
if (!empty($this->course->type) && $this->course->type == 'partial') {
$sql = 'SELECT * FROM '.$table_glossary.' g
WHERE g.c_id = '.$courseId.' '.$session_condition;
WHERE g.c_id = '.$courseId.' '.$sessionCondition;
} else {
$sql = 'SELECT * FROM '.$table_glossary.' g
WHERE g.c_id = '.$courseId.' '.$session_condition;
WHERE g.c_id = '.$courseId.' '.$sessionCondition;
}
} else {
$table_glossary = Database::get_course_table(TABLE_GLOSSARY);
@ -1508,19 +1593,19 @@ class CourseBuilder
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true
);
}
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE c_id = '.$courseId.' '.$session_condition;
WHERE c_id = '.$courseId.' '.$sessionCondition;
} else {
$tbl_wiki = Database::get_course_table(TABLE_WIKI);
$sql = 'SELECT * FROM '.$tbl_wiki.'
@ -1566,17 +1651,17 @@ class CourseBuilder
$courseInfo = api_get_course_info_by_id($courseId);
$session_id = intval($session_id);
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$sessionCondition = api_get_session_condition(
$session_id,
true,
true
);
} else {
$session_condition = api_get_session_condition($session_id, true);
$sessionCondition = api_get_session_condition($session_id, true);
}
$sql = "SELECT * FROM $table_thematic
WHERE c_id = $courseId $session_condition ";
WHERE c_id = $courseId $sessionCondition ";
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result, 'ASSOC')) {
$thematic = new Thematic($row);

@ -86,6 +86,10 @@ class CourseRecycler
}
}
}
if ($backupType === 'full_backup') {
\CourseManager::deleteCoursePicture($this->course_info['code']);
}
}
/**

@ -4,7 +4,9 @@
namespace Chamilo\CourseBundle\Component\CourseCopy;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\LearnPathCategory;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CQuizAnswer;
use CourseManager;
use Database;
@ -54,6 +56,7 @@ class CourseRestorer
'links',
'works',
'surveys',
'learnpath_category',
'learnpaths',
//'scorm_documents', ??
'tool_intro',
@ -88,6 +91,11 @@ class CourseRestorer
$this->file_option = FILE_RENAME;
$this->set_tools_invisible_by_default = false;
$this->skip_content = [];
$forceImport = api_get_configuration_value('allow_import_scorm_package_in_course_builder');
if ($forceImport) {
$this->tools_to_restore[] = 'scorm_documents';
}
}
/**
@ -144,7 +152,7 @@ class CourseRestorer
}
$this->destination_course_id = $course_info['real_id'];
//Getting first teacher (for the forums)
// Getting first teacher (for the forums)
$teacher_list = CourseManager::get_teacher_list_from_course_code(
$course_info['code']
);
@ -199,7 +207,6 @@ class CourseRestorer
// Restore the item properties
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
foreach ($this->course->resources as $type => $resources) {
if (is_array($resources)) {
foreach ($resources as $id => $resource) {
@ -214,7 +221,7 @@ class CourseRestorer
$params = [];
if (!empty($session_id)) {
$params['session_id'] = intval($session_id);
$params['session_id'] = (int) $session_id;
}
$res = Database::query($sql);
@ -225,7 +232,7 @@ class CourseRestorer
$params['c_id'] = $this->destination_course_id;
$params['tool'] = self::DBUTF8($property['tool']);
$params['insert_user_id'] = $this->checkUserId($property['insert_user_id']);
$params['insert_user_id'] = $this->checkUserId($property['insert_user_id']) ?: null;
$params['insert_date'] = self::DBUTF8($property['insert_date']);
$params['lastedit_date'] = self::DBUTF8($property['lastedit_date']);
$params['ref'] = $resource->destination_id;
@ -234,7 +241,7 @@ class CourseRestorer
$params['visibility'] = self::DBUTF8($property['visibility']);
$params['start_visible'] = self::DBUTF8($property['start_visible']);
$params['end_visible'] = self::DBUTF8($property['end_visible']);
$params['to_user_id'] = $this->checkUserId($property['to_user_id']);
$params['to_user_id'] = $this->checkUserId($property['to_user_id']) ?: null;
$id = Database::insert($table, $params);
if ($id) {
@ -999,20 +1006,18 @@ class CourseRestorer
public function restore_scorm_documents()
{
$perm = api_get_permissions_for_new_directories();
if ($this->course->has_resources(RESOURCE_SCORM)) {
$resources = $this->course->resources;
foreach ($resources[RESOURCE_SCORM] as $document) {
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
@mkdir(dirname($path.$document->path), $perm, true);
if (file_exists($path.$document->path)) {
switch ($this->file_option) {
case FILE_OVERWRITE:
rmdirr($path.$document->path);
copyDirTo(
$this->course->backup_path.'/'.$document->path,
$path.dirname($document->path),
$path.$document->path,
false
);
break;
@ -1058,7 +1063,7 @@ class CourseRestorer
// end if file exists
copyDirTo(
$this->course->backup_path.'/'.$document->path,
$path.dirname($document->path),
$path.$document->path,
false
);
}
@ -1074,7 +1079,7 @@ class CourseRestorer
public function restore_forums($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_FORUM)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table_forum = Database::get_course_table(TABLE_FORUM);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
@ -1452,7 +1457,7 @@ class CourseRestorer
public function restore_tool_intro($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$tool_intro_table = Database::get_course_table(TABLE_TOOL_INTRO);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
@ -1497,7 +1502,7 @@ class CourseRestorer
public function restore_events($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_EVENT)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table = Database::get_course_table(TABLE_AGENDA);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_EVENT] as $id => $event) {
@ -1632,7 +1637,7 @@ class CourseRestorer
);
$params = [];
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
$params['c_id'] = $this->destination_course_id;
$params['description_type'] = self::DBUTF8($descriptionType);
@ -1662,7 +1667,7 @@ class CourseRestorer
public function restore_announcements($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
@ -1874,7 +1879,7 @@ class CourseRestorer
$params['session_id'] = $my_session_id;
} else {
if (!empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
}
}
@ -1891,7 +1896,6 @@ class CourseRestorer
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
$order = 0;
if (!empty($quiz->question_ids)) {
foreach ($quiz->question_ids as $index => $question_id) {
@ -2024,7 +2028,6 @@ class CourseRestorer
$quizAnswer
->setId($answerId)
->setIdAuto($answerId);
$em->merge($quizAnswer);
$em->flush();
@ -2153,7 +2156,7 @@ class CourseRestorer
foreach ($correctAnswers as $answer_id => $correct_answer) {
$params = [];
$params['correct'] = $new_options[$correct_answer];
$params['correct'] = isset($new_options[$correct_answer]) ? $new_options[$correct_answer] : '';
Database::update(
$table_ans,
$params,
@ -2293,7 +2296,7 @@ class CourseRestorer
*/
public function restore_surveys($sessionId = 0)
{
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
if ($this->course->has_resources(RESOURCE_SURVEY)) {
$table_sur = Database::get_course_table(TABLE_SURVEY);
$table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
@ -2399,7 +2402,6 @@ class CourseRestorer
// Delete the existing survey with the same code and language and
// import the one of the source course
// getting the information of the survey (used for when the survey is shared)
$sql = "SELECT * FROM $table_sur
WHERE
c_id = ".$this->destination_course_id." AND
@ -2576,6 +2578,30 @@ class CourseRestorer
return $new_id;
}
/**
* @param int $sessionId
* @param bool $baseContent
*/
public function restore_learnpath_category($sessionId = 0, $baseContent = false)
{
if ($this->course->has_resources(RESOURCE_LEARNPATH_CATEGORY)) {
$resources = $this->course->resources;
/** @var LearnPathCategory $item */
foreach ($resources[RESOURCE_LEARNPATH_CATEGORY] as $id => $item) {
/** @var CLpCategory $lpCategory */
$lpCategory = $item->object;
$values = [
'c_id' => $this->destination_course_id,
'name' => $lpCategory->getName(),
];
$categoryId = \learnpath::createCategory($values);
if ($categoryId) {
$this->course->resources[RESOURCE_LEARNPATH_CATEGORY][$id]->destination_id = $categoryId;
}
}
}
}
/**
* Restoring learning paths.
*
@ -2591,10 +2617,16 @@ class CourseRestorer
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);
$resources = $this->course->resources;
$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
// Choose default visibility
$toolVisibility = api_get_setting('tool_visible_by_default_at_creation');
$defaultLpVisibility = 'invisible';
if (isset($toolVisibility['learning_path']) && $toolVisibility['learning_path'] == 'true') {
$defaultLpVisibility = 'visible';
}
foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
$condition_session = '';
if (!empty($session_id)) {
@ -2605,7 +2637,7 @@ class CourseRestorer
}
$condition_session = $my_session_id;
} else {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$condition_session = $session_id;
}
}
@ -2649,6 +2681,16 @@ class CourseRestorer
$lp->expired_on = isset($lp->expired_on) && $lp->expired_on === '0000-00-00 00:00:00' ? null : $lp->expired_on;
$lp->publicated_on = isset($lp->publicated_on) && $lp->publicated_on === '0000-00-00 00:00:00' ? null : $lp->publicated_on;
if (isset($lp->categoryId)) {
$lp->categoryId = (int) $lp->categoryId;
}
$categoryId = 0;
if (!empty($lp->categoryId)) {
if (isset($resources[RESOURCE_LEARNPATH_CATEGORY][$lp->categoryId])) {
$categoryId = $resources[RESOURCE_LEARNPATH_CATEGORY][$lp->categoryId]->destination_id;
}
}
$params = [
'c_id' => $this->destination_course_id,
'lp_type' => $lp->lp_type,
@ -2679,7 +2721,7 @@ class CourseRestorer
'prerequisite' => 0,
'hide_toc_frame' => 0,
'seriousgame_mode' => 0,
'category_id' => 0,
'category_id' => $categoryId,
'max_attempts' => 0,
'subscribe_users' => 0,
];
@ -2732,7 +2774,7 @@ class CourseRestorer
$this->destination_course_info,
TOOL_LEARNPATH,
$new_lp_id,
'invisible',
$defaultLpVisibility,
api_get_user_id(),
0,
0,
@ -2764,6 +2806,14 @@ class CourseRestorer
$item['item_type'] = $item['item_type'] == 'dokeos_chapter' ? 'dir' : $item['item_type'];
$masteryScore = $item['mastery_score'];
// If item is a chamilo quiz, then use the max score as mastery_score
if ($item['item_type'] == 'quiz') {
if (empty($masteryScore)) {
$masteryScore = $item['max_score'];
}
}
$params = [
'c_id' => $this->destination_course_id,
'lp_id' => self::DBUTF8($new_lp_id),
@ -2774,7 +2824,7 @@ class CourseRestorer
'description' => self::DBUTF8($item['description']),
'min_score' => self::DBUTF8($item['min_score']),
'max_score' => self::DBUTF8($item['max_score']),
'mastery_score' => self::DBUTF8($item['mastery_score']),
'mastery_score' => self::DBUTF8($masteryScore),
'parent_item_id' => self::DBUTF8($item['parent_item_id']),
'previous_item_id' => self::DBUTF8($item['previous_item_id']),
'next_item_id' => self::DBUTF8($item['next_item_id']),
@ -2851,10 +2901,10 @@ class CourseRestorer
foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
$previous_new_id = 0;
if ($previous_item_old_id != 0) {
$previous_new_id = $new_item_ids[$previous_item_old_id];
$previous_new_id = isset($new_item_ids[$previous_item_old_id]) ? $new_item_ids[$previous_item_old_id] : '';
}
$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
Database::query($sql);
}
@ -2965,7 +3015,7 @@ class CourseRestorer
foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
$params = [];
if (!empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
}

@ -18,51 +18,65 @@ use Display;
*/
class CourseSelectForm
{
/**
* @return array
*/
public static function getResourceTitleList()
{
$list = [];
$list[RESOURCE_LEARNPATH_CATEGORY] = get_lang('Learnpath').' '.get_lang('Category');
$list[RESOURCE_ASSET] = get_lang('Assets');
$list[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
$list[RESOURCE_EVENT] = get_lang('Events');
$list[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$list[RESOURCE_DOCUMENT] = get_lang('Documents');
$list[RESOURCE_LINK] = get_lang('Links');
$list[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$list[RESOURCE_FORUM] = get_lang('Forums');
$list[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$list[RESOURCE_QUIZ] = get_lang('Tests');
$list[RESOURCE_TEST_CATEGORY] = get_lang('QuestionCategory');
$list[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath');
$list[RESOURCE_SCORM] = 'SCORM';
$list[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
$list[RESOURCE_SURVEY] = get_lang('Survey');
$list[RESOURCE_GLOSSARY] = get_lang('Glossary');
$list[RESOURCE_WIKI] = get_lang('Wiki');
$list[RESOURCE_THEMATIC] = get_lang('Thematic');
$list[RESOURCE_ATTENDANCE] = get_lang('Attendance');
$list[RESOURCE_WORK] = get_lang('ToolStudentPublication');
return $list;
}
/**
* Display the form.
*
* @param array $course
* @param array $hidden_fields hidden fields to add to the form
* @param bool $avoid_serialize the document array will be serialize.
* This is used in the course_copy.php file
* @param array $hidden_fields hidden fields to add to the form
* @param bool $avoidSerialize the document array will be serialize.
* This is used in the course_copy.php file
* @param bool $avoidCourseInForm
*/
public static function display_form(
$course,
$hidden_fields = null,
$avoid_serialize = false
$avoidSerialize = false,
$avoidCourseInForm = false
) {
global $charset;
$resource_titles[RESOURCE_ASSET] = get_lang('Assets');
$resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents');
$resource_titles[RESOURCE_LINK] = get_lang('Links');
$resource_titles[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$resource_titles[RESOURCE_FORUM] = get_lang('Forums');
$resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$resource_titles[RESOURCE_QUIZ] = get_lang('Tests');
$resource_titles[RESOURCE_TEST_CATEGORY] = get_lang('QuestionCategory');
$resource_titles[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath');
$resource_titles[RESOURCE_SCORM] = 'SCORM';
$resource_titles[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
$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');
$resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance');
$resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication'); ?>
global $charset; ?>
<script>
function exp(item) {
el = document.getElementById('div_'+item);
if (el.style.display == 'none') {
el.style.display = '';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className = 'fa fa-minus-square-o fa-lg';
$('#img_'+item).removeClass();
$('#img_'+item).addClass('fa fa-minus-square-o fa-lg');
} else {
el.style.display='none';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className ='fa fa-plus-square-o fa-lg';
el.style.display = 'none';
$('#img_'+item).removeClass();
$('#img_'+item).addClass('fa fa-plus-square-o fa-lg');
}
}
@ -154,6 +168,7 @@ class CourseSelectForm
echo get_lang('DestinationCourse').' : '.$courseInfo['title'].' ('.$courseInfo['code'].') '.$sessionTitle;
echo '</h3>';
}
echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
echo '<div class="tool-backups-options">';
echo '<form method="post" id="upload_form" name="course_select_form">';
@ -170,7 +185,6 @@ class CourseSelectForm
echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>';
}
$element_count = 0;
$forum_categories = [];
$forums = [];
$forum_topics = [];
@ -178,114 +192,27 @@ class CourseSelectForm
echo '<p>';
echo get_lang('SelectResources');
echo '</p>';
echo Display::return_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
foreach ($course->resources as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
//Resources to avoid
case RESOURCE_FORUMCATEGORY:
foreach ($resources as $id => $resource) {
$forum_categories[$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUM:
foreach ($resources as $id => $resource) {
$forums[$resource->obj->forum_category][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUMTOPIC:
foreach ($resources as $id => $resource) {
$forum_topics[$resource->obj->forum_id][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_LINKCATEGORY:
case RESOURCE_FORUMPOST:
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
case RESOURCE_SCORM:
break;
default:
echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">';
echo '<em id="img_'.$type.'" class="fa fa-minus-square-o fa-lg" ></em>';
echo '<span class="title">'.$resource_titles[$type].'</span></div>';
echo '<div class="item-content" id="div_'.$type.'">';
if ($type == RESOURCE_LEARNPATH) {
echo Display::return_message(
get_lang(
'ToExportLearnpathWithQuizYouHaveToSelectQuiz'
),
'warning'
);
echo Display::return_message(
get_lang(
'IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'
),
'warning'
);
}
if ($type == RESOURCE_DOCUMENT) {
if (api_get_setting('show_glossary_in_documents') != 'none') {
echo Display::return_message(
get_lang(
'ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'
),
'warning'
);
}
}
echo '<div class="well">';
echo '<div class="btn-group">';
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo '</div>';
echo '<ul class="list-backups-options">';
foreach ($resources as $id => $resource) {
if ($resource) {
echo '<li>';
// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
Resource::setClassType($resource);
echo '<label class="checkbox">';
echo '<input
type="checkbox"
name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />';
$resource->show();
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '<script language="javascript">exp('."'$type'".')</script>';
$element_count++;
}
}
}
$resource_titles = self::getResourceTitleList();
$element_count = self::parseResources($resource_titles, $course->resources, true, true);
//Fixes forum order
// Fixes forum order
if (!empty($forum_categories)) {
$type = RESOURCE_FORUMCATEGORY;
echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">';
echo '<em id="img_'.$type.'" class="fa fa-minus-square-o fa-lg"></em>';
echo '<span class="title">'.$resource_titles[RESOURCE_FORUM].'</span></div>';
echo '<div class="item-content" id="div_'.$type.'">';
echo '<ul class="list-backups-options">';
foreach ($forum_categories as $forum_category_id => $forum_category) {
echo '<li>';
echo '<label class="checkbox">';
echo '<input type="checkbox" id="resource_'.RESOURCE_FORUMCATEGORY.'_'.$forum_category_id.'" my_rel="'.$forum_category_id.'" onclick="javascript:check_category(this);" name="resource['.RESOURCE_FORUMCATEGORY.']['.$forum_category_id.']" /> ';
echo '<input type="checkbox"
id="resource_'.RESOURCE_FORUMCATEGORY.'_'.$forum_category_id.'"
my_rel="'.$forum_category_id.'"
onclick="javascript:check_category(this);"
name="resource['.RESOURCE_FORUMCATEGORY.']['.$forum_category_id.']" /> ';
$forum_category->show();
echo '</label>';
echo '</li>';
@ -296,7 +223,13 @@ class CourseSelectForm
foreach ($my_forums as $forum_id => $forum) {
echo '<li>';
echo '<label class="checkbox">';
echo '<input type="checkbox" class="resource_forum" id="resource_'.RESOURCE_FORUM.'_'.$forum_id.'" onclick="javascript:check_forum(this);" my_rel="'.$forum_id.'" rel="'.$forum_category_id.'" name="resource['.RESOURCE_FORUM.']['.$forum_id.']" />';
echo '<input type="checkbox"
class="resource_forum"
id="resource_'.RESOURCE_FORUM.'_'.$forum_id.'"
onclick="javascript:check_forum(this);"
my_rel="'.$forum_id.'"
rel="'.$forum_category_id.'"
name="resource['.RESOURCE_FORUM.']['.$forum_id.']" />';
$forum->show();
echo '</label>';
echo '</li>';
@ -307,7 +240,14 @@ class CourseSelectForm
foreach ($my_forum_topics as $topic_id => $topic) {
echo '<li>';
echo '<label class="checkbox">';
echo '<input type="checkbox" id="resource_'.RESOURCE_FORUMTOPIC.'_'.$topic_id.'" onclick="javascript:check_topic(this);" class="resource_topic" forum_id="'.$forum_id.'" rel="'.$forum_id.'" cat_id="'.$forum_category_id.'" name="resource['.RESOURCE_FORUMTOPIC.']['.$topic_id.']" />';
echo '<input
type="checkbox"
id="resource_'.RESOURCE_FORUMTOPIC.'_'.$topic_id.'"
onclick="javascript:check_topic(this);" class="resource_topic"
forum_id="'.$forum_id.'"
rel="'.$forum_id.'"
cat_id="'.$forum_category_id.'"
name="resource['.RESOURCE_FORUMTOPIC.']['.$topic_id.']" />';
$topic->show();
echo '</label>';
echo '</li>';
@ -325,14 +265,19 @@ class CourseSelectForm
echo '<script language="javascript">exp('."'$type'".')</script>';
}
if ($avoid_serialize) {
if ($avoidSerialize) {
/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
(when there are directories with hundred/thousand of files) */
// this is a known issue of serialize
$course->resources['document'] = null;
}
echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
if ($avoidCourseInForm === false) {
/** @var Course $course */
$courseSerialized = base64_encode(Course::serialize($course));
echo '<input type="hidden" name="course" value="'.$courseSerialized.'"/>';
}
if (is_array($hidden_fields)) {
foreach ($hidden_fields as $key => $value) {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
@ -340,25 +285,23 @@ class CourseSelectForm
}
$recycleOption = isset($_POST['recycle_option']) ? true : false;
if (empty($element_count)) {
echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
} else {
if (!empty($hidden_fields['destination_session'])) {
echo '<br />
<button
class="save"
type="submit"
onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'.
<button
class="save"
type="submit"
onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'.
get_lang('Ok').'</button>';
} else {
if ($recycleOption) {
echo '<br /><button class="save" type="submit">'.
get_lang('Ok').'</button>';
echo '<br /><button class="save" type="submit">'.get_lang('Ok').'</button>';
} else {
echo '<br />
<button
class="save"
class="save btn btn-primary"
type="submit"
onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
get_lang('Ok').'</button>';
@ -373,6 +316,127 @@ class CourseSelectForm
echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
}
/**
* @param array $resource_titles
* @param array $resourceList
* @param bool $showHeader
* @param bool $showItems
*
* @return int
*/
public static function parseResources(
$resource_titles,
$resourceList,
$showHeader = true,
$showItems = true
) {
$element_count = 0;
foreach ($resourceList as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
// Resources to avoid
case RESOURCE_FORUMCATEGORY:
foreach ($resources as $id => $resource) {
$forum_categories[$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUM:
foreach ($resources as $id => $resource) {
$forums[$resource->obj->forum_category][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUMTOPIC:
foreach ($resources as $id => $resource) {
$forum_topics[$resource->obj->forum_id][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_LINKCATEGORY:
case RESOURCE_FORUMPOST:
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
case RESOURCE_SCORM:
break;
default:
if ($showHeader) {
echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">';
echo '<em id="img_'.$type.'" class="fa fa-plus-square-o fa-lg"></em>';
echo '<span class="title">'.$resource_titles[$type].'</span>';
echo '</div>';
echo '<div class="item-content" id="div_'.$type.'">';
}
if ($type == RESOURCE_LEARNPATH) {
echo Display::return_message(
get_lang(
'ToExportLearnpathWithQuizYouHaveToSelectQuiz'
),
'warning'
);
echo Display::return_message(
get_lang(
'IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'
),
'warning'
);
}
if ($type == RESOURCE_DOCUMENT) {
if (api_get_setting('show_glossary_in_documents') != 'none') {
echo Display::return_message(
get_lang(
'ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'
),
'warning'
);
}
}
if ($showItems) {
echo '<div class="well">';
echo '<div class="btn-group">';
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo '</div>';
echo '<ul class="list-backups-options">';
foreach ($resources as $id => $resource) {
if ($resource) {
echo '<li>';
// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
Resource::setClassType($resource);
echo '<label class="checkbox">';
echo '<input
type="checkbox"
name="resource['.$type.']['.$id.']"
id="resource['.$type.']['.$id.']" />';
$resource->show();
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
}
if ($showHeader) {
echo '</div>';
echo '<script language="javascript">exp('."'$type'".')</script>';
}
$element_count++;
}
}
}
return $element_count;
}
/**
* @param $course
*/
@ -422,20 +486,27 @@ class CourseSelectForm
/**
* Get the posted course.
*
* @param string $from who calls the function?
* It can be copy_course, create_backup, import_backup or recycle_course
* @param string $from who calls the function?
* It can be copy_course, create_backup, import_backup or recycle_course
* @param int $session_id
* @param string $course_code
* @param Course $postedCourse
*
* @return course The course-object with all resources selected by the user
* @return Course The course-object with all resources selected by the user
* in the form given by display_form(...)
*/
public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
public static function get_posted_course($from = '', $session_id = 0, $course_code = '', $postedCourse = null)
{
$course = null;
if (isset($_POST['course'])) {
$course = Course::unserialize(base64_decode($_POST['course']));
} else {
}
if ($postedCourse) {
$course = $postedCourse;
}
if (empty($course)) {
return false;
}
@ -449,7 +520,7 @@ class CourseSelectForm
$course_id = $course_info['real_id'];
/* Searching the documents resource that have been set to null because
$avoid_serialize is true in the display_form() function*/
$avoidSerialize is true in the display_form() function*/
if ($from === 'copy_course') {
if (is_array($resource)) {
$resource = array_keys($resource);
@ -532,7 +603,6 @@ class CourseSelectForm
$forum_id == $post->obj->forum_id &&
$title == $post->obj->post_title
) {
//unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
$posts_to_save[] = $post_id;
}
}
@ -610,8 +680,11 @@ class CourseSelectForm
}
}
}
if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
unset($course->resources[$type][$id]);
// quiz question can be, not attached to an exercise
if ($type != RESOURCE_QUIZQUESTION) {
if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
unset($course->resources[$type][$id]);
}
}
}
}
@ -626,13 +699,13 @@ class CourseSelectForm
* Display the form session export.
*
* @param array $list_course
* @param array $hidden_fields hidden fields to add to the form
* @param bool $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
* @param array $hidden_fields hidden fields to add to the form
* @param bool $avoidSerialize the document array will be serialize. This is used in the course_copy.php file
*/
public static function display_form_session_export(
$list_course,
$hidden_fields = null,
$avoid_serialize = false
$avoidSerialize = false
) {
?>
<script>
@ -642,13 +715,13 @@ class CourseSelectForm
el.style.display = '';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className('fa fa-minus-square-o fa-lg');
}
else{
} else {
el.style.display = 'none';
if (document.getElementById('img_'+item).length)
document.getElementById('img_'+item).className('fa fa-plus-square-o fa-lg');
}
}
function setCheckbox(type,value) {
d = document.course_select_form;
for (i = 0; i < d.elements.length; i++) {
@ -721,7 +794,7 @@ class CourseSelectForm
}
}
}
if ($avoid_serialize) {
if ($avoidSerialize) {
// Documents are avoided due the huge amount of memory that the serialize php
// function "eats" (when there are directories with hundred/thousand of files)
// this is a known issue of serialize

@ -111,6 +111,7 @@ class CourseCopyLearnpath extends Resource
* @param string $content_license
* @param int $debug
* @param string $visibility
* @param int $categoryId
* @param array $items
*/
public function __construct(
@ -140,6 +141,7 @@ class CourseCopyLearnpath extends Resource
$publicated_on,
$expired_on,
$session_id,
$categoryId,
$items
) {
parent::__construct($id, RESOURCE_LEARNPATH);
@ -168,6 +170,7 @@ class CourseCopyLearnpath extends Resource
$this->session_id = $session_id;
$this->author = $author;
$this->preview_image = $preview_image;
$this->categoryId = $categoryId;
$this->items = $items;
}

Loading…
Cancel
Save