Internal - Fix add course with content

pull/3464/head
Julio Montoya 4 years ago
parent c90ddc530d
commit a94dae6da8
  1. 9
      public/main/exercise/exercise.class.php
  2. 10
      public/main/exercise/question.class.php
  3. 51
      public/main/inc/lib/add_course.lib.inc.php
  4. 2
      public/main/inc/lib/document.lib.php
  5. 6
      public/main/inc/lib/link.lib.php
  6. 3
      tests/datafiller/fill_courses.php

@ -1420,8 +1420,6 @@ class Exercise
*/
public function save()
{
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$id = $this->getId();
$title = $this->exercise;
$description = $this->description;
@ -1545,8 +1543,9 @@ class Exercise
$em->persist($exercise);
$em->flush();
$id = $exercise->getIid();
$this->iId = $this->id = $id;
if ($id) {
if ('true' == api_get_setting('search_enabled') && extension_loaded('xapian')) {
if ('true' === api_get_setting('search_enabled') && extension_loaded('xapian')) {
$this->search_engine_save();
}
}
@ -1554,7 +1553,7 @@ class Exercise
$this->save_categories_in_exercise($this->categories);
return $this->iId;
return $id;
}
/**
@ -8429,7 +8428,7 @@ class Exercise
} else {
$qb->andWhere($qb->expr()->eq('resource.active', 1));
}
//var_dump($qb->getQuery()->getSQL());
$exerciseList = $qb->getQuery()->getResult();
$total = $qb->select('count(resource.iid)')->setMaxResults(1)->getQuery()->getScalarResult();

@ -524,7 +524,7 @@ abstract class Question
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$em = Database::getManager();
$exerciseId = $exercise->id;
$exerciseId = $exercise->iId;
$id = $this->id;
$type = $this->type;
@ -597,9 +597,9 @@ abstract class Question
->setFeedback($this->feedback)
->setParent($exerciseEntity)
->addCourseLink(
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity()
$courseEntity,
api_get_session_entity(),
api_get_group_entity()
)
;
@ -636,8 +636,6 @@ abstract class Question
$em->persist($quizAnswer);
$em->flush();
$id = $quizAnswer->getIid();
}
if (HOT_SPOT_DELINEATION == $type) {

@ -317,7 +317,12 @@ class AddCourse
$now = api_get_utc_datetime();
$files = [
['path' => '/shared_folder', 'title' => get_lang('Folders of users'), 'filetype' => 'folder', 'size' => 0],
['path' => '/chat_files', 'title' => get_lang('Chat conversations history'), 'filetype' => 'folder', 'size' => 0],
[
'path' => '/chat_files',
'title' => get_lang('Chat conversations history'),
'filetype' => 'folder',
'size' => 0,
],
['path' => '/certificates', 'title' => get_lang('Certificates'), 'filetype' => 'folder', 'size' => 0],
];
@ -332,15 +337,28 @@ class AddCourse
/* Documents */
if ($fill_with_exemplary_content) {
$files = [
['path' => '/images', 'title' => get_lang('Images'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images/gallery', 'title' => get_lang('Gallery'), 'filetype' => 'folder', 'size' => 0],
['path' => '/audio', 'title' => get_lang('Audio'), 'filetype' => 'folder', 'size' => 0],
['path' => '/flash', 'title' => get_lang('Flash'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images', 'title' => get_lang('Images'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images/diagrams', 'title' => get_lang('Diagrams'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images/diagrams/animated', 'title' => 'animated', 'filetype' => 'folder', 'size' => 0],
[
'path' => '/images/mr_chamilo',
'title' => get_lang('Mr Chamilo'),
'filetype' => 'folder',
'size' => 0,
],
['path' => '/images/mr_chamilo/svg', 'title' => 'svg', 'filetype' => 'folder', 'size' => 0],
['path' => '/images/small', 'title' => get_lang('Small'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images/trainer', 'title' => get_lang('Trainer'), 'filetype' => 'folder', 'size' => 0],
['path' => '/images/gallery', 'title' => get_lang('Gallery'), 'filetype' => 'folder', 'size' => 0],
['path' => '/video', 'title' => get_lang('Video'), 'filetype' => 'folder', 'size' => 0],
['path' => '/video/flv', 'title' => 'flv', 'filetype' => 'folder', 'size' => 0],
];
$paths = [];
foreach ($files as $file) {
self::insertDocument($courseInfo, $counter, $file, $authorId);
$doc = self::insertDocument($courseInfo, $counter, $file, $authorId);
$paths[$file['path']] = $doc->getIid();
$counter++;
}
@ -349,18 +367,15 @@ class AddCourse
$finder->in($defaultPath);
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$path = str_replace($defaultPath, '', $file->getRealPath());
/*foreach ($finder as $file) {
$parentName = dirname(str_replace($defaultPath, '', $file->getRealPath()));
$title = $file->getFilename();
$parent = DocumentManager::getDocumentByPathInCourse($courseInfo, $parentName);
$parentId = 0;
if (!empty($parent)) {
$parent = $parent[0];
$parentId = $parent['iid'];
if ('/' === $parentName || '/certificates' === $parentName) {
continue;
}
$title = $file->getFilename();
$parentId = $paths[$parentName];
if ($file->isDir()) {
$realPath = str_replace($defaultPath, '', $file->getRealPath());
DocumentManager::addDocument(
@ -404,7 +419,7 @@ class AddCourse
$certificateId = $document->getIid();
}
}
}
}*/
$agenda = new Agenda('course');
$agenda->set_course($courseInfo);
@ -443,7 +458,7 @@ class AddCourse
];
foreach ($links as $params) {
$link->save($params);
$link->save($params, false, false);
}
/* Announcement tool */
@ -509,6 +524,7 @@ class AddCourse
$exercise_id = $exercise->id;
$question = new MultipleAnswer();
$question->course = $courseInfo;
$question->question = get_lang('Socratic irony is...');
$question->description = get_lang('(more than one answer can be true)');
$question->weighting = 10;
@ -518,7 +534,6 @@ class AddCourse
$questionId = $question->id;
$answer = new Answer($questionId, $courseInfo['real_id']);
$answer->createAnswer(get_lang('Ridiculise one\'s interlocutor in order to have him concede he is wrong.'), 0, get_lang('No. Socratic irony is not a matter of psychology, it concerns argumentation.'), -5, 1);
$answer->createAnswer(get_lang('Admit one\'s own errors to invite one\'s interlocutor to do the same.'), 0, get_lang('No. Socratic irony is not a seduction strategy or a method based on the example.'), -5, 2);
$answer->createAnswer(get_lang('Compell one\'s interlocutor, by a series of questions and sub-questions, to admit he doesn\'t know what he claims to know.'), 1, get_lang('Indeed'), 5, 3);
@ -593,7 +608,7 @@ class AddCourse
*/
public static function insertDocument($courseInfo, $counter, $file, $authorId = 0)
{
DocumentManager::addDocument(
return DocumentManager::addDocument(
$courseInfo,
$file['path'],
$file['filetype'],

@ -4117,6 +4117,8 @@ class DocumentManager
/**
* Check if the path is used in this course.
*
* @deprecated
*
* @param array $courseInfo
* @param string $path
*

@ -74,7 +74,7 @@ class Link extends Model
*
* @return bool True if link could be saved, false otherwise
*/
public function save($params, $showQuery = null)
public function save($params, $showQuery = null, $showFlash = true)
{
$course_info = $this->getCourse();
$course_id = $course_info['real_id'];
@ -253,7 +253,9 @@ class Link extends Model
Database:: query($sql);
}
}
Display::addFlash(Display::return_message(get_lang('The link has been added.')));
if ($showFlash) {
Display::addFlash(Display::return_message(get_lang('The link has been added.')));
}
return $link_id;
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -31,7 +32,7 @@ function fill_courses()
}
// Effectively create the course
$res = CourseManager::create_course($course);
$output[$i]['line-info'] = $res ? get_lang('Added') : get_lang('NotInserted');
$output[$i]['line-info'] = $res ? get_lang('Added') : get_lang('Not inserted');
$i++;
}

Loading…
Cancel
Save