From 08da1c793bc3ef74dfa2345768786bf7985e055e Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 11 May 2017 09:02:20 +0200 Subject: [PATCH] Minor - Format code, replace deprecated function - Deprecated function: CourseManager::get_course_information --- .../Component/CourseCopy/CourseSelectForm.php | 682 +++++++++--------- 1 file changed, 349 insertions(+), 333 deletions(-) diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php index b231dde464..56e213e432 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php @@ -51,61 +51,61 @@ class CourseSelectForm $resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance'); $resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication'); ?> - - + '; - echo get_lang('DestinationCourse').' : '.$course_infos['title'].' ('.$course_infos['code'].') '.$sessionTitle; - echo ''; - } + $courseInfo = api_get_course_info($hidden_fields['destination_course']); + echo '

'; + echo get_lang('DestinationCourse').' : '.$courseInfo['title'].' ('.$courseInfo['code'].') '.$sessionTitle; + echo '

'; + } echo ''; echo '
'; - echo '
'; - echo ''; + echo ''; + echo ''; - if (!empty($hidden_fields['destination_course']) && + if (!empty($hidden_fields['destination_course']) && !empty($hidden_fields['origin_course']) && !empty($hidden_fields['destination_session']) && !empty($hidden_fields['origin_session']) ) { - echo ''; - echo ''; - echo ''; - echo ''; - } + echo ''; + echo ''; + echo ''; + echo ''; + } - $element_count = 0; + $element_count = 0; $forum_categories = array(); $forums = array(); $forum_topics = array(); echo '

'; - echo get_lang('SelectResources'); - echo '

'; + echo get_lang('SelectResources'); + echo '

'; 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: + switch ($type) { + //Resources to avoid + case RESOURCE_FORUMCATEGORY: foreach ($resources as $id => $resource) { $forum_categories[$id] = $resource; } @@ -211,29 +211,44 @@ class CourseSelectForm break; default: echo '
'; - echo ''; - echo ''.$resource_titles[$type].'
'; - echo '
'; - if ($type == RESOURCE_LEARNPATH) { - echo Display::return_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'), 'warning'); - echo Display::return_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'), 'warning'); - } - if ($type == RESOURCE_DOCUMENT) { + echo ''; + echo ''.$resource_titles[$type].'
'; + echo '
'; + 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 Display::return_message( + get_lang( + 'ToExportDocumentsWithGlossaryYouHaveToSelectGlossary' + ), + 'warning' + ); } - } + } - echo '
'; + echo '
'; echo '
'; - echo "".get_lang('All').""; + echo "".get_lang('All').""; echo "".get_lang('None').""; - echo '
'; + echo '
'; echo '
    '; - foreach ($resources as $id => $resource) { + foreach ($resources as $id => $resource) { if ($resource) { echo '
  • '; - // Event obj in 1.9.x in 1.10.x the class is CalendarEvent + // Event obj in 1.9.x in 1.10.x the class is CalendarEvent Resource::setClassType($resource); echo ''; echo '
  • '; } - } + } echo '
'; - echo '
'; - echo '
'; - echo ''; - $element_count++; + echo '
'; + echo ''; + echo ''; + $element_count++; } - } - } + } + } //Fixes forum order if (!empty($forum_categories)) { @@ -303,66 +318,65 @@ class CourseSelectForm echo ''; } - if ($avoid_serialize) { - /*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 ''; + if ($avoid_serialize) { + /*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; + } - if (is_array($hidden_fields)) { - foreach ($hidden_fields as $key => $value) { - echo ''; - } - } + echo ''; + if (is_array($hidden_fields)) { + foreach ($hidden_fields as $key => $value) { + echo ''; + } + } $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 '
'; - } else { + } else { if ($recycleOption) { echo '
'; } else { - echo '
'; } - } - } + } + } - self::display_hidden_quiz_questions($course); - self::display_hidden_scorm_directories($course); - echo ''; + self::display_hidden_quiz_questions($course); + self::display_hidden_scorm_directories($course); + echo ''; echo ''; - echo '
'; - } + echo '
'; + } /** * @param $course */ public static function display_hidden_quiz_questions($course) { - if (is_array($course->resources)) { - foreach ($course->resources as $type => $resources) { - if (count($resources) > 0) { - switch ($type) { - case RESOURCE_QUIZQUESTION: - foreach ($resources as $id => $resource) { - echo ''; - } - break; - } - } - } - } - } + if (is_array($course->resources)) { + foreach ($course->resources as $type => $resources) { + if (count($resources) > 0) { + switch ($type) { + case RESOURCE_QUIZQUESTION: + foreach ($resources as $id => $resource) { + echo ''; + } + break; + } + } + } + } + } /** * @param $course @@ -370,30 +384,30 @@ class CourseSelectForm public static function display_hidden_scorm_directories($course) { if (is_array($course->resources)) { - foreach ($course->resources as $type => $resources) { - if (count($resources) > 0) { - switch ($type) { - case RESOURCE_SCORM: - foreach ($resources as $id => $resource) { - echo ''; - } - break; - } - } - } - } - } - - /** - * Get the posted course - * @param string $from who calls the function? + foreach ($course->resources as $type => $resources) { + if (count($resources) > 0) { + switch ($type) { + case RESOURCE_SCORM: + foreach ($resources as $id => $resource) { + echo ''; + } + break; + } + } + } + } + } + + /** + * Get the posted 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 - * @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 = '') + * @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 = '') { $course = null; if (isset($_POST['course'])) { @@ -402,40 +416,40 @@ class CourseSelectForm return false; } - // Create the resource DOCUMENT objects - // Loading the results from the checkboxes of ethe javascript - $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; + // Create the resource DOCUMENT objects + // Loading the results from the checkboxes of ethe javascript + $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; - $course_info = api_get_course_info($course_code); - $table_doc = Database::get_course_table(TABLE_DOCUMENT); - $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); - $course_id = $course_info['real_id']; + $course_info = api_get_course_info($course_code); + $table_doc = Database::get_course_table(TABLE_DOCUMENT); + $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); + $course_id = $course_info['real_id']; - /* Searching the documents resource that have been set to null because + /* Searching the documents resource that have been set to null because $avoid_serialize is true in the display_form() function*/ - if ($from === 'copy_course') { - if (is_array($resource)) { - $resource = array_keys($resource); - foreach ($resource as $resource_item) { - $conditionSession = ''; - if (!empty($session_id)) { - $session_id = intval($session_id); - $conditionSession = ' AND d.session_id ='.$session_id; - } - - $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size - FROM '.$table_doc.' d - INNER JOIN '.$table_prop.' p - ON (d.c_id = p.c_id) - WHERE - d.c_id = '.$course_id.' AND + if ($from === 'copy_course') { + if (is_array($resource)) { + $resource = array_keys($resource); + foreach ($resource as $resource_item) { + $conditionSession = ''; + if (!empty($session_id)) { + $session_id = intval($session_id); + $conditionSession = ' AND d.session_id ='.$session_id; + } + + $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size + FROM '.$table_doc.' d + INNER JOIN '.$table_prop.' p + ON (d.c_id = p.c_id) + WHERE + d.c_id = '.$course_id.' AND p.c_id = '.$course_id.' AND tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND d.id = '.$resource_item.$conditionSession.' - ORDER BY path'; - $db_result = Database::query($sql); - while ($obj = Database::fetch_object($db_result)) { + ORDER BY path'; + $db_result = Database::query($sql); + while ($obj = Database::fetch_object($db_result)) { $doc = new Document( $obj->id, $obj->path, @@ -459,24 +473,24 @@ class CourseSelectForm } $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties; } - } - } - } - } - - if (is_array($course->resources)) { - foreach ($course->resources as $type => $resources) { - switch ($type) { - case RESOURCE_SURVEYQUESTION: - foreach ($resources as $id => $obj) { - if (isset($_POST['resource'][RESOURCE_SURVEY]) && + } + } + } + } + + if (is_array($course->resources)) { + foreach ($course->resources as $type => $resources) { + switch ($type) { + case RESOURCE_SURVEYQUESTION: + foreach ($resources as $id => $obj) { + if (isset($_POST['resource'][RESOURCE_SURVEY]) && is_array($_POST['resource'][RESOURCE_SURVEY]) && !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY])) ) { - unset($course->resources[$type][$id]); - } - } - break; + unset($course->resources[$type][$id]); + } + } + break; case RESOURCE_FORUMTOPIC: case RESOURCE_FORUMPOST: //Add post from topic @@ -529,24 +543,24 @@ class CourseSelectForm } } // no break - case RESOURCE_LINKCATEGORY: - // no break - case RESOURCE_FORUMCATEGORY: - // no break - case RESOURCE_QUIZQUESTION: - // no break - case RESOURCE_DOCUMENT: - // Mark folders to import which are not selected by the user to import, - // but in which a document was selected. - $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; - if (!empty($resources) && is_array($resources)) - foreach ($resources as $id => $obj) { - if (isset($obj->file_type) && $obj->file_type == 'folder' && + case RESOURCE_LINKCATEGORY: + // no break + case RESOURCE_FORUMCATEGORY: + // no break + case RESOURCE_QUIZQUESTION: + // no break + case RESOURCE_DOCUMENT: + // Mark folders to import which are not selected by the user to import, + // but in which a document was selected. + $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; + if (!empty($resources) && is_array($resources)) + foreach ($resources as $id => $obj) { + if (isset($obj->file_type) && $obj->file_type == 'folder' && !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && is_array($documents) ) { - foreach ($documents as $id_to_check => $post_value) { - if (isset($resources[$id_to_check])) { + foreach ($documents as $id_to_check => $post_value) { + if (isset($resources[$id_to_check])) { $obj_to_check = $resources[$id_to_check]; $shared_path_part = substr( $obj_to_check->path, @@ -558,151 +572,153 @@ class CourseSelectForm break; } } - } - } - } + } + } + } // no break - default: - if (!empty($resources) && is_array($resources)) { - foreach ($resources as $id => $obj) { - $resource_is_used_elsewhere = $course->is_linked_resource($obj); - // check if document is in a quiz (audio/video) - if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { - foreach ($course->resources[RESOURCE_QUIZ] as $quiz) { + default: + if (!empty($resources) && is_array($resources)) { + foreach ($resources as $id => $obj) { + $resource_is_used_elsewhere = $course->is_linked_resource($obj); + // check if document is in a quiz (audio/video) + if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { + foreach ($course->resources[RESOURCE_QUIZ] as $quiz) { $quiz = $quiz->obj; - if (isset($quiz->media) && $quiz->media == $id) { - $resource_is_used_elsewhere = true; - } - } - } - if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { - unset($course->resources[$type][$id]); - } - } - } - } - } - } - - return $course; - } - - /** - * Display the form session export + if (isset($quiz->media) && $quiz->media == $id) { + $resource_is_used_elsewhere = true; + } + } + } + if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { + unset($course->resources[$type][$id]); + } + } + } + } + } + } + + return $course; + } + + /** + * Display the form session export * @param array $list_course - * @param array $hidden_fields Hidden fields to add to the form. + * @param array $hidden_fields Hidden fields to add to the form. * @param boolean $avoid_serialize 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 ) { ?> - - '; - echo get_lang('DestinationCourse').' : '.$course_infos['title'].$sessionTitle; - echo ''; - } - - echo ''; + 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++) { + if (d.elements[i].type == "checkbox") { + var name = d.elements[i].attributes.getNamedItem('name').nodeValue; + if( name.indexOf(type) > 0 || type == 'all' ){ + d.elements[i].checked = value; + } + } + } + } + function checkLearnPath(message){ + d = document.course_select_form; + for (i = 0; i < d.elements.length; i++) { + if (d.elements[i].type == "checkbox") { + var name = d.elements[i].attributes.getNamedItem('name').nodeValue; + if( name.indexOf('learnpath') > 0){ + if(d.elements[i].checked){ + setCheckbox('document',true); + alert(message); + break; + } + } + } + } + } + + '; + echo get_lang('DestinationCourse').' : '.$courseInfo['title'].$sessionTitle; + echo ''; + } + + echo ''; $icon = Display::returnIconPath('progress_bar.gif'); echo '
'; - echo '
'; - echo ''; - foreach ($list_course as $course) { - foreach ($course->resources as $type => $resources) { - if (count($resources) > 0) { + echo ''; + echo ''; + foreach ($list_course as $course) { + foreach ($course->resources as $type => $resources) { + if (count($resources) > 0) { echo '
code'".');">'; - echo ''; - echo ' '.$course->code.'
'; - echo '
'; - echo '
'; + echo ''; + echo ' '.$course->code.'
'; + echo ''; - foreach ($resources as $id => $resource) { - echo '
'; - echo ''; - } - } - } - if ($avoid_serialize) { - //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 ''; - if (is_array($hidden_fields)) { - foreach ($hidden_fields as $key => $value) { - echo "\n"; - echo ''; - } - } - echo '
'; - self::display_hidden_quiz_questions($course); - self::display_hidden_scorm_directories($course); - echo ''; + $resource->show(); + echo ''; + } + echo ''; + echo ''; + echo ''; + } + } + } + if ($avoid_serialize) { + //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 ''; + if (is_array($hidden_fields)) { + foreach ($hidden_fields as $key => $value) { + echo "\n"; + echo ''; + } + } + echo '
'; + self::display_hidden_quiz_questions($course); + self::display_hidden_scorm_directories($course); + echo ''; echo ''; - echo '
'; - } + echo '
'; + } }