diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php index e18a237f1c..27cac8a644 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php @@ -636,7 +636,6 @@ class CourseBuilder while ($obj = Database::fetch_object($result)) { // find the question category - // @todo : need to be adapted for multi category questions in 1.10 $question_category_id = TestCategory::getCategoryForQuestion( $obj->id, diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php index 181f26d101..1325df3bbb 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php @@ -4,6 +4,7 @@ namespace Chamilo\CourseBundle\Component\CourseCopy; use Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup; +use Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion; use Chamilo\CourseBundle\Entity\CQuizAnswer; use DocumentManager; use Database; @@ -37,10 +38,10 @@ class CourseRestorer public $set_tools_invisible_by_default; public $skip_content; public $tools_to_restore = array( + 'documents', // first restore documents 'announcements', 'attendance', 'course_descriptions', - 'documents', 'events', 'forum_category', 'forums', @@ -924,6 +925,18 @@ class CourseRestorer } } // end file doesn't exist } + + // add image information for area questions + if (preg_match('/^quiz-.*$/', $document->title) && + preg_match('/^document\/images\/.*$/', $document->path) + ) { + $this->course->resources[RESOURCE_DOCUMENT]['image_quiz'][$document->title] = [ + 'path' => $document->path, + 'title' => $document->title, + 'source_id' => $document->source_id, + 'destination_id' => $document->destination_id + ]; + } } // end for each // Delete sessions for the copy the new folder in session @@ -1801,8 +1814,8 @@ class CourseRestorer { $em = Database::getManager(); $resources = $this->course->resources; + /** @var QuizQuestion $question */ $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null; - $new_id = 0; if (is_object($question)) { @@ -1822,6 +1835,18 @@ class CourseRestorer $this->course->info['path'] ); + $imageNewId = ''; + if (preg_match('/^quiz-.*$/', $question->picture) && + isset($resources[RESOURCE_DOCUMENT]['image_quiz'][$question->picture]) + ) { + $imageNewId = $resources[RESOURCE_DOCUMENT]['image_quiz'][$question->picture]['destination_id']; + } else { + if (isset($resources[RESOURCE_DOCUMENT][$question->picture])) { + $documentsToRestore = $resources[RESOURCE_DOCUMENT][$question->picture]; + $imageNewId = $documentsToRestore->destination_id; + } + } + $params = [ 'c_id' => $this->destination_course_id, 'question' => self::DBUTF8($question->question), @@ -1829,7 +1854,7 @@ class CourseRestorer 'ponderation' => self::DBUTF8($question->ponderation), 'position' => self::DBUTF8($question->position), 'type' => self::DBUTF8($question->quiz_type), - 'picture' => self::DBUTF8($question->picture), + 'picture' => self::DBUTF8($imageNewId), 'level' => self::DBUTF8($question->level), 'extra' => self::DBUTF8($question->extra), ]; @@ -1839,30 +1864,6 @@ class CourseRestorer if ($new_id) { $sql = "UPDATE $table_que SET id = iid WHERE iid = $new_id"; Database::query($sql); - - if (!empty($question->picture)) { - $question_temp = Question::read( - $new_id, - $this->destination_course_info['real_id'] - ); - - $documentPath = api_get_path(SYS_COURSE_PATH).$this->destination_course_info['path'].'/document'; - // picture path - $picturePath = $documentPath.'/images'; - $old_picture = api_get_path(SYS_COURSE_PATH).$this->course->info['path'].'/document/images/'.$question->picture; - if (file_exists($old_picture)) { - $picture_name = 'quiz-'.$new_id.'.jpg'; - $result = $question_temp->uploadPicture($old_picture, $picture_name, $picturePath); - if ($result) { - $sql = "UPDATE $table_que SET - picture = '$picture_name' - WHERE - c_id = " . $this->destination_course_id . " AND - id = $new_id "; - Database::query($sql); - } - } - } } $correctAnswers = array(); @@ -2157,9 +2158,9 @@ class CourseRestorer if ($this->course->has_resources(RESOURCE_QUIZQUESTION)) { // check the category number of each question restored if (!empty($resources[RESOURCE_QUIZQUESTION])) { - foreach ($resources[RESOURCE_QUIZQUESTION] as $id => $CourseCopyQuestion) { + foreach ($resources[RESOURCE_QUIZQUESTION] as $id => $courseCopyQuestion) { $new_quiz_question_id = $resources[RESOURCE_QUIZQUESTION][$id]->destination_id; - $question_category = $CourseCopyQuestion->question_category; + $question_category = $courseCopyQuestion->question_category; if ($question_category > 0) { TestCategory::add_category_for_question_id( $tab_test_category_id_old_new[$question_category], @@ -2179,7 +2180,6 @@ class CourseRestorer public function restore_surveys($sessionId = 0) { $sessionId = intval($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); diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/Resources/QuizQuestion.php b/src/Chamilo/CourseBundle/Component/CourseCopy/Resources/QuizQuestion.php index 44db2da2df..6ba94bf277 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/Resources/QuizQuestion.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/Resources/QuizQuestion.php @@ -58,12 +58,17 @@ class QuizQuestion extends Resource public $question_category; /** - * Create a new QuizQuestion + * QuizQuestion constructor. + * @param int $id * @param string $question * @param string $description * @param int $ponderation - * @param int $type - * @param int $position + * @param $type + * @param $position + * @param $picture + * @param $level + * @param $extra + * @param int $question_category */ public function __construct( $id,