From 75ee00776cddde9b90a3ef31d2fb3485a5ce464c Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Mon, 19 Feb 2018 13:44:41 +0100 Subject: [PATCH] Minor - format code --- main/exercise/Annotation.php | 14 +- main/exercise/Draggable.php | 4 +- main/exercise/Hpdownload.php | 4 +- main/exercise/MatchingDraggable.php | 15 +- main/exercise/ReadingComprehension.php | 6 +- main/exercise/UniqueAnswerImage.php | 24 +- main/exercise/adminhp.php | 8 +- main/exercise/aiken.php | 4 +- main/exercise/exercise_admin.php | 14 +- main/exercise/exercise_history.php | 14 +- main/exercise/exercise_reminder.php | 28 +- main/exercise/exercise_result.class.php | 10 +- main/exercise/exercise_submit_modal.php | 64 ++- main/exercise/export/aiken/aiken_classes.php | 2 +- .../export/aiken/aiken_import.inc.php | 13 +- main/exercise/export/exercise_import.inc.php | 73 ++-- main/exercise/export/qti2/qti2_classes.php | 10 +- main/exercise/export/qti2/qti2_export.php | 2 +- main/exercise/export/scorm/scorm_classes.php | 52 +-- main/exercise/freeanswer.class.php | 6 +- .../exercise/global_multiple_answer.class.php | 18 +- main/exercise/hotpotatoes.lib.php | 22 +- main/exercise/hotpotatoes.php | 12 +- main/exercise/hotpotatoes_exercise_report.php | 74 ++-- .../hotpotatoes_exercise_result.class.php | 20 +- main/exercise/hotspot.class.php | 10 +- main/exercise/hotspot.inc.php | 12 +- main/exercise/hotspot_admin.inc.php | 403 ++++++++++-------- main/exercise/hotspot_lang_conversion.php | 2 +- main/exercise/live_stats.php | 40 +- main/exercise/matching.class.php | 14 +- main/exercise/multiple_answer.class.php | 16 +- .../multiple_answer_combination.class.php | 18 +- ...le_answer_combination_true_false.class.php | 4 +- .../multiple_answer_true_false.class.php | 30 +- main/exercise/oral_expression.class.php | 8 +- main/exercise/overview.php | 34 +- main/exercise/qti2.php | 19 +- main/exercise/question_create.php | 8 +- main/exercise/unique_answer.class.php | 45 +- .../unique_answer_no_option.class.php | 22 +- main/exercise/upload_exercise.php | 14 +- main/inc/lib/browser/Browser.php | 4 +- main/inc/lib/elfinder/connectorAction.php | 10 +- main/inc/lib/elfinder/templates.php | 4 +- .../lib/formvalidator/Element/SelectTheme.php | 4 +- main/inc/lib/hook/HookEvent.php | 2 +- 47 files changed, 643 insertions(+), 593 deletions(-) diff --git a/main/exercise/Annotation.php b/main/exercise/Annotation.php index f7e2a5f8b1..cd0379c993 100644 --- a/main/exercise/Annotation.php +++ b/main/exercise/Annotation.php @@ -41,15 +41,16 @@ class Annotation extends Question ); if (!empty($this->id)) { - $form->setDefaults(array('weighting' => float_format($this->weighting, 1))); + $form->setDefaults(['weighting' => float_format($this->weighting, 1)]); } else { if ($this->isContent == 1) { - $form->setDefaults(array('weighting' => '10')); + $form->setDefaults(['weighting' => '10']); } } + global $text; if (isset($_GET['editQuestion'])) { - $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion'); + $form->addButtonUpdate($text, 'submitQuestion'); return; } @@ -57,7 +58,7 @@ class Annotation extends Question $form->addElement( 'file', 'imageUpload', - array( + [ Display::img( Display::return_icon( 'annotation.png', @@ -69,7 +70,7 @@ class Annotation extends Question ) ), get_lang('UploadJpgPicture'), - ) + ] ); $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); @@ -77,7 +78,7 @@ class Annotation extends Question 'imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', - array('jpg', 'jpeg', 'png', 'gif') + ['jpg', 'jpeg', 'png', 'gif'] ); $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); } @@ -108,7 +109,6 @@ class Annotation extends Question */ public function createAnswersForm($form) { - // nothing } /** diff --git a/main/exercise/Draggable.php b/main/exercise/Draggable.php index 0161641a76..20ecb29d00 100644 --- a/main/exercise/Draggable.php +++ b/main/exercise/Draggable.php @@ -26,9 +26,9 @@ class Draggable extends Question */ public function createAnswersForm($form) { - $defaults = array(); + $defaults = []; $nb_matches = $nb_options = 2; - $matches = array(); + $matches = []; $answer = null; if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); diff --git a/main/exercise/Hpdownload.php b/main/exercise/Hpdownload.php index 6b6bd17a5e..06c0a133f9 100755 --- a/main/exercise/Hpdownload.php +++ b/main/exercise/Hpdownload.php @@ -13,7 +13,7 @@ $this_section = SECTION_COURSES; $tbl_document = Database::get_course_table(TABLE_DOCUMENT); -$doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($_GET['doc_url'])); +$doc_url = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], urldecode($_GET['doc_url'])); $filename = basename($doc_url); // launch event @@ -87,7 +87,7 @@ header('Last-Modified: '.gmdate('D, d M Y H:i:s', time() + 10).' GMT'); if ($content_type == 'text/html') { $directory_name = dirname($full_file_name); $coursePath = api_get_path(SYS_COURSE_PATH); - $dir = str_replace(array('\\', $coursePath.$_course['path'].'/document'), array('/', ''), $directory_name); + $dir = str_replace(['\\', $coursePath.$_course['path'].'/document'], ['/', ''], $directory_name); if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; diff --git a/main/exercise/MatchingDraggable.php b/main/exercise/MatchingDraggable.php index 3f95729256..0d306f4b28 100644 --- a/main/exercise/MatchingDraggable.php +++ b/main/exercise/MatchingDraggable.php @@ -26,9 +26,9 @@ class MatchingDraggable extends Question */ public function createAnswersForm($form) { - $defaults = array(); + $defaults = []; $nb_matches = $nb_options = 2; - $matches = array(); + $matches = []; $answer = null; $counter = 1; if (isset($this->id)) { @@ -115,15 +115,14 @@ class MatchingDraggable extends Question echo Display::return_message(get_lang('YouHaveToCreateAtLeastOneAnswer'), 'normal'); } - $editorConfig = array( + $editorConfig = [ 'ToolbarSet' => 'TestMatching', 'Width' => '100%', 'Height' => '125' - ); + ]; for ($i = 1; $i <= $nb_matches; ++$i) { $renderer = &$form->defaultRenderer(); - $renderer->setElementTemplate( '{error}{element}', "answer[$i]" @@ -198,7 +197,7 @@ class MatchingDraggable extends Question $form->addHtml(''); global $text; - $group = array(); + $group = []; // setting the save button here and not in the question class.php $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true); $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true); @@ -214,10 +213,10 @@ class MatchingDraggable extends Question } $form->setConstants( - array( + [ 'nb_matches' => $nb_matches, 'nb_options' => $nb_options - ) + ] ); } diff --git a/main/exercise/ReadingComprehension.php b/main/exercise/ReadingComprehension.php index 389cf30148..eb21730b6c 100755 --- a/main/exercise/ReadingComprehension.php +++ b/main/exercise/ReadingComprehension.php @@ -169,7 +169,7 @@ class ReadingComprehension extends UniqueAnswer $isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null; // default values - $defaults = array(); + $defaults = []; $defaults['questionName'] = $this->question; $defaults['questionDescription'] = $this->description; $defaults['questionLevel'] = $this->level; @@ -194,13 +194,13 @@ class ReadingComprehension extends UniqueAnswer */ public static function get_default_levels() { - $select_level = array( + $select_level = [ 1 => sprintf(get_lang('ReadingComprehensionLevelX'), self::$speeds[1]), 2 => sprintf(get_lang('ReadingComprehensionLevelX'), self::$speeds[2]), 3 => sprintf(get_lang('ReadingComprehensionLevelX'), self::$speeds[3]), 4 => sprintf(get_lang('ReadingComprehensionLevelX'), self::$speeds[4]), 5 => sprintf(get_lang('ReadingComprehensionLevelX'), self::$speeds[5]) - ); + ]; return $select_level; } } diff --git a/main/exercise/UniqueAnswerImage.php b/main/exercise/UniqueAnswerImage.php index 792e718b70..4d5cc2f111 100644 --- a/main/exercise/UniqueAnswerImage.php +++ b/main/exercise/UniqueAnswerImage.php @@ -68,7 +68,7 @@ class UniqueAnswerImage extends UniqueAnswer $form->addHeader(get_lang('Answers')); $form->addHtml($html); - $defaults = array(); + $defaults = []; $correct = 0; if (!empty($this->id)) { @@ -84,7 +84,7 @@ class UniqueAnswerImage extends UniqueAnswer //Feedback SELECT $questionList = $objExercise->selectQuestionList(); - $selectQuestion = array(); + $selectQuestion = []; $selectQuestion[0] = get_lang('SelectTargetQuestion'); if (is_array($questionList)) { @@ -106,14 +106,14 @@ class UniqueAnswerImage extends UniqueAnswer $list = new LearnpathList(api_get_user_id()); $flatList = $list->get_flat_list(); - $selectLpId = array(); + $selectLpId = []; $selectLpId[0] = get_lang('SelectTargetLP'); foreach ($flatList as $id => $details) { $selectLpId[$id] = cut($details['lp_name'], 20); } - $tempScenario = array(); + $tempScenario = []; if ($numberAnswers < 1) { $numberAnswers = 1; @@ -161,8 +161,8 @@ class UniqueAnswerImage extends UniqueAnswer $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2'); $defaults['weighting[2]'] = 0; - $tempScenario['destination'.$i] = array('0'); - $tempScenario['lp'.$i] = array('0'); + $tempScenario['destination'.$i] = ['0']; + $tempScenario['lp'.$i] = ['0']; } $defaults['scenario'] = $tempScenario; @@ -206,7 +206,7 @@ class UniqueAnswerImage extends UniqueAnswer ); // Direct feedback // Adding extra feedback fields - $group = array(); + $group = []; $group['try'.$i] = $form->createElement('checkbox', 'try'.$i, null, get_lang('TryAgain')); $group['lp'.$i] = $form->createElement( 'select', @@ -224,10 +224,10 @@ class UniqueAnswerImage extends UniqueAnswer 'text', 'url'.$i, get_lang('Other').': ', - array( + [ 'class' => 'col-md-2', 'placeholder' => get_lang('Other') - ) + ] ); $form->addGroup($group, 'scenario'); @@ -238,7 +238,7 @@ class UniqueAnswerImage extends UniqueAnswer } else { $form->addHtmlEditor('comment['.$i.']', null, null, false, $editorConfig); } - $form->addText('weighting['.$i.']', null, null, array('class' => "col-md-1", 'value' => '0')); + $form->addText('weighting['.$i.']', null, null, ['class' => "col-md-1", 'value' => '0']); $form->addHtml(''); } @@ -269,11 +269,11 @@ class UniqueAnswerImage extends UniqueAnswer // Default sample content. $form->setDefaults($defaults); } else { - $form->setDefaults(array('correct' => 1)); + $form->setDefaults(['correct' => 1]); } } - $form->setConstants(array('nb_answers' => $numberAnswers)); + $form->setConstants(['nb_answers' => $numberAnswers]); } /** diff --git a/main/exercise/adminhp.php b/main/exercise/adminhp.php index ea74e02e2d..eda24793c6 100755 --- a/main/exercise/adminhp.php +++ b/main/exercise/adminhp.php @@ -38,16 +38,16 @@ if (!$is_allowedToEdit) { } if (api_is_in_gradebook()) { - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('ToolGradebook'), - ); + ]; } -$interbreadcrumb[] = array( +$interbreadcrumb[] = [ "url" => "exercise.php", "name" => get_lang('Exercises') -); +]; $nameTools = get_lang('adminHP'); Display::display_header($nameTools, "Exercise"); diff --git a/main/exercise/aiken.php b/main/exercise/aiken.php index 276eeac1e0..d891e335d6 100755 --- a/main/exercise/aiken.php +++ b/main/exercise/aiken.php @@ -25,10 +25,10 @@ if (!api_is_allowed_to_edit(null, true)) { } // the breadcrumbs -$interbreadcrumb[] = array( +$interbreadcrumb[] = [ "url" => 'exercise.php?'.api_get_cidreq(), "name" => get_lang('Exercises'), -); +]; $is_allowedToEdit = api_is_allowed_to_edit(null, true); // import file if ((api_is_allowed_to_edit(null, true))) { diff --git a/main/exercise/exercise_admin.php b/main/exercise/exercise_admin.php index 582226f791..339223c341 100755 --- a/main/exercise/exercise_admin.php +++ b/main/exercise/exercise_admin.php @@ -164,20 +164,20 @@ if ($form->validate()) { exit; } else { if (api_is_in_gradebook()) { - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('ToolGradebook') - ); + ]; } $nameTools = get_lang('ExerciseManagement'); - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ "url" => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises'), - ); - $interbreadcrumb[] = array( + ]; + $interbreadcrumb[] = [ "url" => 'admin.php?exerciseId='.$objExercise->id.'&'.api_get_cidreq(), "name" => $objExercise->selectTitle(true), - ); + ]; Display::display_header($nameTools, get_lang('Exercise')); @@ -190,7 +190,7 @@ if ($form->validate()) { if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])) { if (!empty($_POST['lp_id'])) { $lp_id = intval($_POST['lp_id']); - //TODO:this remains to be implemented after press the first post + //TODO:this remains to be implemented after press the first post } else { $lp_id = intval($_GET['lp_id']); } diff --git a/main/exercise/exercise_history.php b/main/exercise/exercise_history.php index c6533abb69..ca1ca9f01a 100755 --- a/main/exercise/exercise_history.php +++ b/main/exercise/exercise_history.php @@ -24,18 +24,18 @@ if (!$is_allowedToEdit) { exit; } -$interbreadcrumb[] = array( +$interbreadcrumb[] = [ 'url' => 'exercise_report.php?'.api_get_cidreq(), 'name' => get_lang('Exercises'), -); -$interbreadcrumb[] = array( +]; +$interbreadcrumb[] = [ 'url' => 'exercise_report.php?filter=2&'.api_get_cidreq(), 'name' => get_lang('StudentScore'), -); -$interbreadcrumb[] = array( +]; +$interbreadcrumb[] = [ 'url' => 'exercise_history.php?exe_id='.intval($_GET['exe_id']).'&'.api_get_cidreq(), 'name' => get_lang('Details'), -); +]; $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); @@ -44,7 +44,7 @@ $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ Display::display_header($nameTools, get_lang('Exercise')); if (isset($_GET['message'])) { - if (in_array($_GET['message'], array('ExerciseEdited'))) { + if (in_array($_GET['message'], ['ExerciseEdited'])) { $my_message_history = Security::remove_XSS($_GET['message']); echo Display::return_message(get_lang($my_message_history), 'confirm'); } diff --git a/main/exercise/exercise_reminder.php b/main/exercise/exercise_reminder.php index 716a250411..03fdb292e2 100755 --- a/main/exercise/exercise_reminder.php +++ b/main/exercise/exercise_reminder.php @@ -104,7 +104,7 @@ if (empty($exercise_stat_info) || empty($question_list)) { } $nameTools = get_lang('Exercises'); -$interbreadcrumb[] = array("url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')); +$interbreadcrumb[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')]; if ($origin != 'learnpath') { //so we are not in learnpath tool @@ -119,9 +119,9 @@ if ($origin != 'learnpath') { if (api_is_course_admin() && $origin != 'learnpath') { echo '
'; echo ''. - Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).''; + Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32).''; echo ''. - Display::return_icon('edit.png', get_lang('ModifyExercise'), array(), 32).''; + Display::return_icon('edit.png', get_lang('ModifyExercise'), [], 32).''; echo '
'; } echo Display::page_header(get_lang('QuestionsToReview')); @@ -130,7 +130,7 @@ if ($time_control) { echo $objExercise->return_time_left_div(); } -echo Display::div('', array('id'=>'message')); +echo Display::div('', ['id'=>'message']); echo ''; exit; } -$choice = array(); +$choice = []; $questionid = $questionList[$questionNum]; // $choice_value => value of the user selection $choice[$questionid] = isset($choice_value) ? $choice_value : null; // initializing if (!is_array($exerciseResult)) { - $exerciseResult = array(); + $exerciseResult = []; } // if the user has answered at least one question @@ -170,11 +170,11 @@ if (in_array($questionid, $questionList)) { $objAnswerTmp = new Answer($questionid); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $choice = $exerciseResult[$questionid]; -$destination = array(); +$destination = []; $comment = ''; $next = 1; -$_SESSION['hotspot_coord'] = array(); -$_SESSION['hotspot_dest'] = array(); +$_SESSION['hotspot_coord'] = []; +$_SESSION['hotspot_dest'] = []; $overlap_color = $missing_color = $excess_color = false; $organs_at_risk_hit = 0; $wrong_results = false; @@ -195,7 +195,9 @@ if (!empty($choice_value)) { //delineation $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1); $answer_delineation_destination = $objAnswerTmp->selectDestination(1); - if ($dbg_local > 0) { error_log(__LINE__.' answerId: '.$answerId.'('.$answerType.') - user delineation_cord: '.$delineation_cord.' - $answer_delineation_destination: '.$answer_delineation_destination, 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' answerId: '.$answerId.'('.$answerType.') - user delineation_cord: '.$delineation_cord.' - $answer_delineation_destination: '.$answer_delineation_destination, 0); + } switch ($answerType) { // for unique answer @@ -230,7 +232,9 @@ if (!empty($choice_value)) { } } elseif ($answerType == HOT_SPOT_DELINEATION) { if ($next) { - if ($dbg_local > 0) { error_log(__LINE__.' - next', 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' - next', 0); + } $hot_spot_load = true; //apparently the script is called twice $user_answer = $user_array; $_SESSION['exerciseResultCoordinates'][$questionid] = $user_answer; //needed for exercise_result.php @@ -265,7 +269,9 @@ if (!empty($choice_value)) { } //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels - if ($dbg_local > 0) { error_log(__LINE__.' - Polygons results are '.print_r($poly_results, 1), 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' - Polygons results are '.print_r($poly_results, 1), 0); + } if ($overlap < 1) { //shortcut to avoid complicated calculations $final_overlap = 0; @@ -274,13 +280,19 @@ if (!empty($choice_value)) { } else { // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); - if ($dbg_local > 1) { error_log(__LINE__.' - Final overlap is '.$final_overlap, 0); } + if ($dbg_local > 1) { + error_log(__LINE__.' - Final overlap is '.$final_overlap, 0); + } // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon $final_missing = 100 - $final_overlap; - if ($dbg_local > 1) { error_log(__LINE__.' - Final missing is '.$final_missing, 0); } + if ($dbg_local > 1) { + error_log(__LINE__.' - Final missing is '.$final_missing, 0); + } // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); - if ($dbg_local > 1) { error_log(__LINE__.' - Final excess is '.$final_excess, 0); } + if ($dbg_local > 1) { + error_log(__LINE__.' - Final excess is '.$final_excess, 0); + } } $destination_items = explode('@@', $answerDestination); @@ -324,12 +336,16 @@ if (!empty($choice_value)) { } } elseif ($answerId > 1) { if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { - if ($dbg_local > 0) { error_log(__LINE__.' - answerId is of type noerror', 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' - answerId is of type noerror', 0); + } //type no error shouldn't be treated $next = 1; continue; } - if ($dbg_local > 0) { error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR', 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR', 0); + } //check the intersection between the oar and the user //echo 'user'; print_r($x_user_list); print_r($y_user_list); //echo 'official';print_r($x_list);print_r($y_list); @@ -395,7 +411,9 @@ if (!empty($choice_value)) { } } else { // the first delineation feedback - if ($dbg_local > 0) { error_log(__LINE__.' first', 0); } + if ($dbg_local > 0) { + error_log(__LINE__.' first', 0); + } } } } @@ -504,7 +522,7 @@ if (isset($try) && $try == 1) { $links .= Display:: return_icon( 'reload.gif', '', - array('style' => 'padding-left:0px;padding-right:5px;') + ['style' => 'padding-left:0px;padding-right:5px;'] ).''.get_lang('TryAgain').'

'; } @@ -516,7 +534,7 @@ if (!empty($lp)) { $links .= Display:: return_icon( 'theory.gif', '', - array('style' => 'padding-left:0px;padding-right:5px;') + ['style' => 'padding-left:0px;padding-right:5px;'] ).''.get_lang('SeeTheory').'
'; } $links .= '
'; @@ -526,7 +544,7 @@ if (!empty($url)) { $links .= Display:: return_icon( 'link.gif', '', - array('style' => 'padding-left:0px;padding-right:5px;') + ['style' => 'padding-left:0px;padding-right:5px;'] ).''.get_lang('VisitUrl').'

'; } @@ -535,7 +553,7 @@ if ($destinationid == -1) { $links .= Display:: return_icon( 'finish.gif', '', - array('style' => 'width:22px; height:22px; padding-left:0px;padding-right:5px;') + ['style' => 'width:22px; height:22px; padding-left:0px;padding-right:5px;'] ).''.get_lang('EndActivity').'

'; } else { // the link to other question @@ -546,7 +564,7 @@ if ($destinationid == -1) { $links .= Display:: return_icon( 'quiz.png', '', - array('style' => 'padding-left:0px;padding-right:5px;') + ['style' => 'padding-left:0px;padding-right:5px;'] ).''.get_lang('GoToQuestion').' '.$num_value_array[0].'

'; } } @@ -588,7 +606,7 @@ if ($links != '') { echo ''; Session::write('hot_spot_result', $message); - $_SESSION['hotspot_delineation_result'][$exerciseId][$questionid] = array($message, $exerciseResult[$questionid]); + $_SESSION['hotspot_delineation_result'][$exerciseId][$questionid] = [$message, $exerciseResult[$questionid]]; //reseting the exerciseResult variable Session::write('exerciseResult', $exerciseResult); @@ -599,7 +617,7 @@ if ($links != '') { } else { $questionNum++; echo ''; } diff --git a/main/exercise/export/aiken/aiken_classes.php b/main/exercise/export/aiken/aiken_classes.php index c97f522659..3ebd76762b 100755 --- a/main/exercise/export/aiken/aiken_classes.php +++ b/main/exercise/export/aiken/aiken_classes.php @@ -16,7 +16,7 @@ class Aiken2Question extends Question /** * Include the correct answer class and create answer */ - function setAnswer() + public function setAnswer() { switch ($this->type) { case MCUA: diff --git a/main/exercise/export/aiken/aiken_import.inc.php b/main/exercise/export/aiken/aiken_import.inc.php index 93d4f2f1e9..9ce1720657 100755 --- a/main/exercise/export/aiken/aiken_import.inc.php +++ b/main/exercise/export/aiken/aiken_import.inc.php @@ -29,7 +29,7 @@ function aiken_display_form() 'post', api_get_self()."?".api_get_cidreq(), null, - array('enctype' => 'multipart/form-data') + ['enctype' => 'multipart/form-data'] ); $form_validator->addElement('header', $name_tools); $form_validator->addElement('text', 'total_weight', get_lang('TotalWeight')); @@ -115,9 +115,9 @@ function aiken_import_exercise($file) $uploadPath = 'aiken_'.api_get_unique_id().'/'; // set some default values for the new exercise - $exercise_info = array(); + $exercise_info = []; $exercise_info['name'] = preg_replace('/.(zip|txt)$/i', '', $file); - $exercise_info['question'] = array(); + $exercise_info['question'] = []; // if file is not a .zip, then we cancel all if (!preg_match('/.(zip|txt)$/i', $file)) { @@ -252,7 +252,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) $question_index = 0; $correct_answer = ''; - $answers_array = array(); + $answers_array = []; $new_question = true; foreach ($data as $line => $info) { if ($question_index > 0 && $new_question == true && preg_match('/^(\r)?\n/', $info)) { @@ -288,7 +288,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) $correct_answer_index = array_search($matches[1], $answers_array); $exercise_info['question'][$question_index]['title'] = $matches[1]; } elseif (preg_match('/^TAGS:\s?([A-Z])\s?/', $info, $matches)) { - //TAGS for chamilo >= 1.10 + //TAGS for chamilo >= 1.10 $exercise_info['question'][$question_index]['answer_tags'] = explode(',', $matches[1]); } elseif (preg_match('/^ETIQUETAS:\s?([A-Z])\s?/', $info, $matches)) { //TAGS for chamilo >= 1.10 (Spanish e-ducativa format) @@ -305,7 +305,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) } $question_index++; //emptying answers array when moving to next question - $answers_array = array(); + $answers_array = []; $new_question = true; } else { if (empty($exercise_info['question'][$question_index]['title'])) { @@ -349,7 +349,6 @@ function aiken_import_file($array_file) Display::addFlash(Display::return_message(get_lang('Uploaded'))); return $imported; - } else { Display::addFlash(Display::return_message(get_lang($imported), 'error')); diff --git a/main/exercise/export/exercise_import.inc.php b/main/exercise/export/exercise_import.inc.php index 72e16d5c0b..24e18b9bcb 100755 --- a/main/exercise/export/exercise_import.inc.php +++ b/main/exercise/export/exercise_import.inc.php @@ -66,7 +66,6 @@ function import_exercise($file) global $resourcesLinks; $baseWorkDir = api_get_path(SYS_ARCHIVE_PATH).'qti2/'; - if (!is_dir($baseWorkDir)) { mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true); } @@ -78,12 +77,12 @@ function import_exercise($file) } // set some default values for the new exercise - $exercise_info = array(); + $exercise_info = []; $exercise_info['name'] = preg_replace('/.zip$/i', '', $file); - $exercise_info['question'] = array(); - $element_pile = array(); + $exercise_info['question'] = []; + $element_pile = []; // create parser and array to retrieve info from manifest - $element_pile = array(); //pile to known the depth in which we are + $element_pile = []; //pile to known the depth in which we are // if file is not a .zip, then we cancel all if (!preg_match('/.zip$/i', $file)) { @@ -102,7 +101,7 @@ function import_exercise($file) $file_found = false; $result = false; $filePath = null; - $resourcesLinks = array(); + $resourcesLinks = []; // parse every subdirectory to search xml question files and other assets to be imported // The assets-related code is a bit fragile as it has to deal with files renamed by Chamilo and it only works if @@ -139,7 +138,6 @@ function import_exercise($file) $resourcesLinks = qtiProcessManifest($baseWorkDir.'/'.$file); } } - } } @@ -212,6 +210,7 @@ function import_exercise($file) if (!empty($question_array['description'])) { $description .= $question_array['description']; } + $question->updateDescription($description); $question->save($exercise); @@ -222,7 +221,7 @@ function import_exercise($file) $answer->new_nbrAnswers = count($answerList); $totalCorrectWeight = 0; $j = 1; - $matchAnswerIds = array(); + $matchAnswerIds = []; if (!empty($answerList)) { foreach ($answerList as $key => $answers) { if (preg_match('/_/', $key)) { @@ -265,7 +264,6 @@ function import_exercise($file) $question->save($exercise); $answer->save(); } - // delete the temp dir where the exercise was unzipped my_delete($baseWorkDir.$uploadPath); @@ -309,18 +307,17 @@ function qti_parse_file($exercisePath, $file, $questionFile) //parse XML question file //$data = str_replace(array('

', '

', '', ''), '', $data); - $data = ChamiloApi::stripGivenTags($data, array('p', 'front')); - $qtiVersion = array(); + $data = ChamiloApi::stripGivenTags($data, ['p', 'front']); + $qtiVersion = []; $match = preg_match('/ims_qtiasiv(\d)p(\d)/', $data, $qtiVersion); $qtiMainVersion = 2; //by default, assume QTI version 2 if ($match) { $qtiMainVersion = $qtiVersion[1]; } - //used global variable start values declaration : - + //used global variable start values declaration: $record_item_body = false; - $non_HTML_tag_to_avoid = array( + $non_HTML_tag_to_avoid = [ "SIMPLECHOICE", "CHOICEINTERACTION", "INLINECHOICEINTERACTION", @@ -334,11 +331,12 @@ function qti_parse_file($exercisePath, $file, $questionFile) "ITEMBODY", "BR", "IMG" - ); + ]; $question_format_supported = true; $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, false); + if ($qtiMainVersion == 1) { xml_set_element_handler( $xml_parser, @@ -354,6 +352,7 @@ function qti_parse_file($exercisePath, $file, $questionFile) ); xml_set_character_data_handler($xml_parser, 'elementDataQti2'); } + if (!xml_parse($xml_parser, $data, feof($fp))) { // if reading of the xml file in not successful : // set errorFound, set error msg, break while statement @@ -379,9 +378,9 @@ function qti_parse_file($exercisePath, $file, $questionFile) Display::return_message( get_lang( 'Unknown question format in file %file', - array( + [ '%file' => $questionFile, - ) + ] ), 'error' ) @@ -449,7 +448,6 @@ function startElementQti2($parser, $name, $attributes) if ($current_element == 'TEXTENTRYINTERACTION') { $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id]; $current_question_item_body .= "[".$correct_answer_value."]"; - } if ($current_element == 'BR') { $current_question_item_body .= "
"; @@ -506,6 +504,7 @@ function startElementQti2($parser, $name, $attributes) break; case 'EXTENDEDTEXTINTERACTION': $exercise_info['question'][$current_question_ident]['type'] = FREE_ANSWER; + $exercise_info['question'][$current_question_ident]['description'] = ''; break; case 'SIMPLEMATCHSET': if (!isset($current_match_set)) { @@ -513,7 +512,7 @@ function startElementQti2($parser, $name, $attributes) } else { $current_match_set++; } - $exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = array(); + $exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = []; break; case 'SIMPLEASSOCIABLECHOICE': $currentAssociableChoice = $attributes['IDENTIFIER']; @@ -522,14 +521,14 @@ function startElementQti2($parser, $name, $attributes) case 'SIMPLECHOICE': $current_answer_id = $attributes['IDENTIFIER']; if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) { - $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array(); + $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = []; } break; case 'MAPENTRY': if ($parent_element == 'MAPPING' || $parent_element == 'MAPENTRY') { $answer_id = $attributes['MAPKEY']; if (!isset($exercise_info['question'][$current_question_ident]['weighting'])) { - $exercise_info['question'][$current_question_ident]['weighting'] = array(); + $exercise_info['question'][$current_question_ident]['weighting'] = []; } $exercise_info['question'][$current_question_ident]['weighting'][$answer_id] = $attributes['MAPPEDVALUE']; } @@ -599,7 +598,14 @@ function endElementQti2($parser, $name) if ($exercise_info['question'][$current_question_ident]['type'] == FIB) { $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body; } else { - $exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body; + if ($exercise_info['question'][$current_question_ident]['type'] == FREE_ANSWER) { + $current_question_item_body = trim($current_question_item_body); + if (!empty($current_question_item_body)) { + $exercise_info['question'][$current_question_ident]['description'] = $current_question_item_body; + } + } else { + $exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body; + } } break; } @@ -643,11 +649,15 @@ function elementDataQti2($parser, $data) } //treat the record of the full content of itembody tag (needed for question statment and/or FIB text: + if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) { $current_question_item_body .= $data; } switch ($current_element) { + case 'EXTENDEDTEXTINTERACTION': + $exercise_info['question'][$current_question_ident]['description'] .= $data; + break; case 'SIMPLECHOICE': if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data); @@ -703,7 +713,7 @@ function elementDataQti2($parser, $data) ); } else { if (!isset($exercise_info['question'][$current_question_ident]['wrong_answers'])) { - $exercise_info['question'][$current_question_ident]['wrong_answers'] = array(); + $exercise_info['question'][$current_question_ident]['wrong_answers'] = []; } $exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data; } @@ -778,7 +788,6 @@ function startElementQti1($parser, $name, $attributes) if ($current_element == 'TEXTENTRYINTERACTION') { $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id]; $current_question_item_body .= "[".$correct_answer_value."]"; - } if ($current_element == 'BR') { $current_question_item_body .= "
"; @@ -796,9 +805,9 @@ function startElementQti1($parser, $name, $attributes) case 'ITEM': //retrieve current question $current_question_ident = $attributes['IDENT']; - $exercise_info['question'][$current_question_ident] = array(); - $exercise_info['question'][$current_question_ident]['answer'] = array(); - $exercise_info['question'][$current_question_ident]['correct_answers'] = array(); + $exercise_info['question'][$current_question_ident] = []; + $exercise_info['question'][$current_question_ident]['answer'] = []; + $exercise_info['question'][$current_question_ident]['correct_answers'] = []; $exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir; break; case 'SECTION': @@ -1095,11 +1104,11 @@ function qtiProcessManifest($filePath) $exercisesSysPath = $sysPath.$courseDir.'/document/'; $webPath = api_get_path(WEB_CODE_PATH); $exercisesWebPath = $webPath.'document/document.php?'.api_get_cidreq().'&action=download&id='; - $links = array( - 'manifest' => array(), - 'system' => array(), - 'web' => array(), - ); + $links = [ + 'manifest' => [], + 'system' => [], + 'web' => [], + ]; $tableDocuments = Database::get_course_table(TABLE_DOCUMENT); $countResources = count($xml->resources->resource->file); for ($i = 0; $i < $countResources; $i++) { diff --git a/main/exercise/export/qti2/qti2_classes.php b/main/exercise/export/qti2/qti2_classes.php index 39b92559e0..dff84e9749 100755 --- a/main/exercise/export/qti2/qti2_classes.php +++ b/main/exercise/export/qti2/qti2_classes.php @@ -262,7 +262,7 @@ class ImsAnswerMatching extends Answer $out = ' '."\n"; $out .= ' '."\n"; - $gradeArray = array(); + $gradeArray = []; if (isset($this->leftList) && is_array($this->leftList)) { foreach ($this->leftList as $leftKey => $leftElement) { $i = 0; @@ -325,23 +325,23 @@ class ImsAnswerHotspot extends Answer switch ($answer['hotspot_type']) { case 'square': $type = 'rect'; - $res = array(); + $res = []; $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res); $coords = $res[1].','.$res[2].','.((int) $res[1] + (int) $res[3]).",".((int) $res[2] + (int) $res[4]); break; case 'circle': $type = 'circle'; - $res = array(); + $res = []; $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res); $coords = $res[1].','.$res[2].','.sqrt(pow(($res[1] - $res[3]), 2) + pow(($res[2] - $res[4]))); break; case 'poly': $type = 'poly'; - $coords = str_replace(array(';', '|'), array(',', ','), $answer['hotspot_coord']); + $coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']); break; case 'delineation': $type = 'delineation'; - $coords = str_replace(array(';', '|'), array(',', ','), $answer['hotspot_coord']); + $coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']); break; } $text .= ' '."\n"; diff --git a/main/exercise/export/qti2/qti2_export.php b/main/exercise/export/qti2/qti2_export.php index afbd9689a3..1eca4a8577 100755 --- a/main/exercise/export/qti2/qti2_export.php +++ b/main/exercise/export/qti2/qti2_export.php @@ -394,7 +394,7 @@ class ImsItem * @return string string, the XML flow for an Item. * @author Amand Tihon */ - public function export($standalone = False) + public function export($standalone = false) { global $charset; $head = $foot = ""; diff --git a/main/exercise/export/scorm/scorm_classes.php b/main/exercise/export/scorm/scorm_classes.php index dc9985b17e..317167a65b 100755 --- a/main/exercise/export/scorm/scorm_classes.php +++ b/main/exercise/export/scorm/scorm_classes.php @@ -138,7 +138,7 @@ class ScormQuestion extends Question throw new \Exception('Question not supported. Exercise: '.$this->selectTitle()); } - return array($js, $html); + return [$js, $html]; } /** @@ -311,7 +311,7 @@ class ScormAnswerMultipleChoice extends Answer } $html .= ''; - return array($js, $html); + return [$js, $html]; } } @@ -364,7 +364,7 @@ class ScormAnswerTrueFalse extends Answer $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = '.$this->weighting[1].";\n"; $js .= $jstmpw; - return array($js, $html); + return [$js, $html]; } } @@ -386,7 +386,7 @@ class ScormAnswerFillInBlanks extends Answer $js = ''; $html = ''; // get all enclosed answers - $blankList = array(); + $blankList = []; foreach ($this->answer as $i => $answer) { $blankList[] = '['.$answer.']'; } @@ -440,7 +440,7 @@ class ScormAnswerFillInBlanks extends Answer $js .= 'questions_types['.$this->questionJSId.'] = \'fib\';'."\n"; $js .= $jstmpw; - return array($js, $html); + return [$js, $html]; } } @@ -467,7 +467,7 @@ class ScormAnswerMatching extends Answer $nbrAnswers = $this->selectNbrAnswers(); $cpt1 = 'A'; $cpt2 = 1; - $Select = array(); + $Select = []; $qId = $this->questionJSId; $s = ''; $jstmp = ''; @@ -540,7 +540,7 @@ class ScormAnswerMatching extends Answer $html .= $s; $html .= '
'."\n"; - return array($js, $html); + return [$js, $html]; } } @@ -576,7 +576,7 @@ class ScormAnswerFree extends Answer $html = ''.get_lang('ThisItemIsNotExportable').''; - return array($js, $html); + return [$js, $html]; } $html .= ''; @@ -587,7 +587,7 @@ class ScormAnswerFree extends Answer $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = "0";'; $js .= $jstmpw; - return array($js, $html); + return [$js, $html]; } } @@ -679,7 +679,7 @@ HTML; // currently the free answers cannot be displayed, so ignore the textarea $html = ''.get_lang('ThisItemIsNotExportable').''; - return array($js, $html); + return [$js, $html]; } } @@ -791,7 +791,7 @@ class ScormAssessmentItem * Start the itemBody * */ - function start_js() + public function start_js() { $js = ''; if ($this->standalone) { @@ -803,7 +803,7 @@ class ScormAssessmentItem /** * Common JS functions */ - function common_js() + public function common_js() { $js = 'var questions = new Array();'; $js .= 'var questions_answers = new Array();'; @@ -857,7 +857,7 @@ class ScormAssessmentItem * End the itemBody part. * */ - function end_js() + public function end_js() { if ($this->standalone) { return ''; @@ -870,7 +870,7 @@ class ScormAssessmentItem * Start the itemBody * */ - function start_body() + public function start_body() { if ($this->standalone) { return '
'; @@ -883,7 +883,7 @@ class ScormAssessmentItem * End the itemBody part. * */ - function end_body() + public function end_body() { if ($this->standalone) { return '
'; @@ -897,7 +897,7 @@ class ScormAssessmentItem * This is a default behaviour, some classes may want to override this. * @return string|array A string, the XML flow for an Item. */ - function export() + public function export() { list($js, $html) = $this->question->export(); if ($this->standalone) { @@ -915,7 +915,7 @@ class ScormAssessmentItem . $this->end_page(); return $res; } else { - return array($js, $html); + return [$js, $html]; } } } @@ -970,7 +970,7 @@ class ScormSection * This opens the block, with correct attributes. * */ - function start_page() + public function start_page() { $charset = 'UTF-8'; $head = ''; @@ -982,7 +982,7 @@ class ScormSection * End the XML flow, closing the tag. * */ - function end_page() + public function end_page() { return ''; } @@ -990,7 +990,7 @@ class ScormSection /** * Start document header */ - function start_header() + public function start_header() { return ''; } @@ -1083,7 +1083,7 @@ class ScormSection * End the itemBody part. * */ - function end_js() + public function end_js() { return ''; } @@ -1092,7 +1092,7 @@ class ScormSection * Start the itemBody * */ - function start_body() + public function start_body() { return ''. '

'.$this->exercise->selectTitle().'

'.$this->exercise->selectDescription()."

". @@ -1104,7 +1104,7 @@ class ScormSection * End the itemBody part. * */ - function end_body() + public function end_body() { return '
'; } @@ -1117,7 +1117,7 @@ class ScormSection * @param $standalone: Boolean stating if it should be exported as a stand-alone question * @return string string, the XML flow for an Item. */ - function export() + public function export() { global $charset; @@ -1161,7 +1161,7 @@ class ScormSection * Export the questions, as a succession of * @author Amand Tihon */ - function export_questions() + public function export_questions() { $js = $html = ""; $js_id = 0; @@ -1172,6 +1172,6 @@ class ScormSection ++$js_id; } - return array($js, $html); + return [$js, $html]; } } diff --git a/main/exercise/freeanswer.class.php b/main/exercise/freeanswer.class.php index 618076505e..f655f53555 100755 --- a/main/exercise/freeanswer.class.php +++ b/main/exercise/freeanswer.class.php @@ -29,14 +29,14 @@ class FreeAnswer extends Question public function createAnswersForm($form) { $form->addElement('text', 'weighting', get_lang('Weighting')); - global $text, $class; + global $text; // setting the save button here and not in the question class.php $form->addButtonSave($text, 'submitQuestion'); if (!empty($this->id)) { - $form->setDefaults(array('weighting' => float_format($this->weighting, 1))); + $form->setDefaults(['weighting' => float_format($this->weighting, 1)]); } else { if ($this->isContent == 1) { - $form->setDefaults(array('weighting' => '10')); + $form->setDefaults(['weighting' => '10']); } } } diff --git a/main/exercise/global_multiple_answer.class.php b/main/exercise/global_multiple_answer.class.php index 4d5bf507ff..34348e67bf 100755 --- a/main/exercise/global_multiple_answer.class.php +++ b/main/exercise/global_multiple_answer.class.php @@ -52,7 +52,7 @@ class GlobalMultipleAnswer extends Question '
'.Display::return_icon('fill_field.png'), $html ); - $defaults = array(); + $defaults = []; $correct = 0; $answer = false; if (!empty($this->id)) { @@ -66,7 +66,7 @@ class GlobalMultipleAnswer extends Question // le nombre de r�ponses est bien enregistr� sous la forme int(nb) /* Ajout mise en forme nb reponse */ $form->addElement('hidden', 'nb_answers'); - $boxes_names = array(); + $boxes_names = []; if ($nb_answers < 1) { $nb_answers = 1; @@ -131,24 +131,24 @@ class GlobalMultipleAnswer extends Question 'html_editor', 'answer['.$i.']', null, - array(), - array( + [], + [ 'ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100', - ) + ] ); $form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement( 'html_editor', 'comment['.$i.']', null, - array(), - array( + [], + [ 'ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100', - ) + ] ); $form->addElement('html', ''); @@ -196,7 +196,7 @@ class GlobalMultipleAnswer extends Question $form->setDefaults($defaults); } } - $form->setConstants(array('nb_answers' => $nb_answers)); + $form->setConstants(['nb_answers' => $nb_answers]); } /** diff --git a/main/exercise/hotpotatoes.lib.php b/main/exercise/hotpotatoes.lib.php index 853235285f..07abe6251a 100755 --- a/main/exercise/hotpotatoes.lib.php +++ b/main/exercise/hotpotatoes.lib.php @@ -152,7 +152,7 @@ function WriteFileCont($full_file_path, $content) return false; } //if (!($fp = fopen(urldecode($full_file_path), 'w'))) { - //die('Could not open Quiz input.'); + //die('Could not open Quiz input.'); //} $fp = fopen(urldecode($full_file_path), 'w'); if ($fp !== false) { @@ -172,14 +172,14 @@ function WriteFileCont($full_file_path, $content) function GetImgName($imageTag) { // Select src tag from img tag. - $match = array(); + $match = []; //preg_match('/(src=(["\'])1.*(["\'])1)/i', $imageTag, $match); //src preg_match('/src(\s)*=(\s)*[\'"]([^\'"]*)[\'"]/i', $imageTag, $match); //get the img src as contained between " or ' //list($key, $srctag) = each($match); $src = $match[3]; //$src = substr($srctag, 5, (strlen($srctag) - 7)); if (stristr($src, 'http') === false) { - // Valid or invalid image name. + // Valid or invalid image name. if ($src == '') { return ''; } else { @@ -204,12 +204,12 @@ function GetImgName($imageTag) function GetSrcName($imageTag) { // Select src tag from img tag. - $match = array(); + $match = []; preg_match("|(src=\".*\" )|U", $imageTag, $match); //src list(, $srctag) = each($match); $src = substr($srctag, 5, (strlen($srctag) - 7)); if (stristr($src, 'http') === false) { - // valid or invalid image name + // valid or invalid image name return $src; } else { return ''; @@ -226,10 +226,10 @@ function GetSrcName($imageTag) function GetImgParams($fname, $fpath, &$imgparams, &$imgcount) { // Select img tags from context. - $imgparams = array(); + $imgparams = []; //phpinfo(); $contents = ReadFileCont("$fpath"."$fname"); - $matches = array(); + $matches = []; preg_match_all('()', $contents, $matches); $imgcount = 0; while (list(, $match) = each($matches)) { @@ -269,7 +269,7 @@ function GenerateHiddenList($imgparams) function myarraysearch(&$array, $node) { $match = false; - $tmp_array = array(); + $tmp_array = []; for ($i = 0; $i < count($array); $i++) { if (!strcmp($array[$i], $node)) { $match = $node; @@ -302,7 +302,7 @@ function CheckImageName(&$imgparams, $string) function ReplaceImgTag($content) { $newcontent = $content; - $matches = array(); + $matches = []; preg_match_all('()', $content, $matches); while (list(, $match) = each($matches)) { while (list(, $imageTag) = each($match)) { @@ -340,7 +340,7 @@ function FillFolderName($name, $nsize) */ function GenerateHpFolder($folder) { - $filelist = array(); + $filelist = []; if ($dir = @opendir($folder)) { while (($file = readdir($dir)) !== false) { if ($file != '.') { @@ -427,7 +427,7 @@ function CheckSubFolder($path) function HotPotGCt($folder, $flag, $user_id) { // Garbage Collector - $filelist = array(); + $filelist = []; if ($dir = @opendir($folder)) { while (($file = readdir($dir)) !== false) { if ($file != '.') { diff --git a/main/exercise/hotpotatoes.php b/main/exercise/hotpotatoes.php index 4b718d6906..bb4cf3daf9 100755 --- a/main/exercise/hotpotatoes.php +++ b/main/exercise/hotpotatoes.php @@ -20,16 +20,16 @@ if (!api_is_allowed_to_edit(null, true)) { } if (api_is_in_gradebook()) { - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('ToolGradebook') - ); + ]; } // The breadcrumbs. -$interbreadcrumb[] = array( - 'url' => api_get_path(WEB_CODE_PATH).'.exercise/exercise.php?'.api_get_cidreq(), +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises') -); +]; $is_allowedToEdit = api_is_allowed_to_edit(null, true); @@ -88,7 +88,7 @@ $form = new FormValidator( 'post', api_get_self()."?".api_get_cidreq(), null, - array('enctype' => 'multipart/form-data') + ['enctype' => 'multipart/form-data'] ); $form->addElement('header', $nameTools); $form->addElement('hidden', 'uploadPath'); diff --git a/main/exercise/hotpotatoes_exercise_report.php b/main/exercise/hotpotatoes_exercise_report.php index cce7da2edf..b9cb8171d1 100755 --- a/main/exercise/hotpotatoes_exercise_report.php +++ b/main/exercise/hotpotatoes_exercise_report.php @@ -44,7 +44,7 @@ if (empty($hotpotatoes_path)) { } if (!$is_allowedToEdit) { - // api_not_allowed(); + // api_not_allowed(); } if (!empty($_REQUEST['path'])) { @@ -99,13 +99,13 @@ $nameTools = get_lang('Results'); if ($is_allowedToEdit || $is_tutor) { $nameTools = get_lang('StudentScore'); - $interbreadcrumb[] = array("url" => "exercise.php", "name" => get_lang('Exercises')); + $interbreadcrumb[] = ["url" => "exercise.php", "name" => get_lang('Exercises')]; $objExerciseTmp = new Exercise(); - /*if ($objExerciseTmp->read($exercise_id)) { - $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name); - }*/ +/*if ($objExerciseTmp->read($exercise_id)) { + $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name); +}*/ } else { - $interbreadcrumb[] = array("url" => "exercise.php", "name" => get_lang('Exercises')); + $interbreadcrumb[] = ["url" => "exercise.php", "name" => get_lang('Exercises')]; $objExerciseTmp = new Exercise(); /*if ($objExerciseTmp->read($exercise_id)) { $nameTools = get_lang('Results').': '.$objExerciseTmp->name; @@ -113,7 +113,7 @@ if ($is_allowedToEdit || $is_tutor) { } Display :: display_header($nameTools); -$actions = Display::div($actions, array('class'=> 'actions')); +$actions = Display::div($actions, ['class'=> 'actions']); $extra = ''; $extra .= '
'; -$form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical')); -$form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label')); +$form = new FormValidator('report', 'post', null, null, ['class' => 'form-vertical']); +$form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', ['id' => 'export_format_csv_label']); //$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label')); //$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label')); -$form->setDefaults(array('export_format' => 'csv')); +$form->setDefaults(['export_format' => 'csv']); $extra .= $form->returnForm(); $extra .= '
'; @@ -168,7 +168,7 @@ $action_links = ''; // Generating group list $group_list = GroupManager::get_group_list(); -$group_parameters = array('group_all:'.get_lang('All'), 'group_none:'.get_lang('None')); +$group_parameters = ['group_all:'.get_lang('All'), 'group_none:'.get_lang('None')]; foreach ($group_list as $group) { $group_parameters[] = $group['id'].':'.$group['name']; @@ -179,7 +179,7 @@ if (!empty($group_parameters)) { if ($is_allowedToEdit || $is_tutor) { // The order is important you need to check the the $column variable in the model.ajax.php file - $columns = array( + $columns = [ get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), @@ -187,33 +187,33 @@ if ($is_allowedToEdit || $is_tutor) { get_lang('StartDate'), get_lang('Score'), get_lang('Actions') - ); + ]; - // Column config - // @todo fix search firstname/lastname that doesn't work. rmove search for the moment - $column_model = array( - array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'false'), - array( + // Column config + // @todo fix search firstname/lastname that doesn't work. rmove search for the moment + $column_model = [ + ['name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'false'], + [ 'name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'false', - ), - array( + ], + [ 'name' => 'login', 'hidden' => 'true', 'index' => 'username', 'width' => '40', 'align' => 'left', 'search' => 'false', - ), - array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'), - array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'), - array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'), - array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'), - ); + ], + ['name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'], + ['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'], + ['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'], + ['name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'], + ]; $action_links = ' // add username as title in lastname filed - ref 4226 @@ -227,19 +227,19 @@ if ($is_allowedToEdit || $is_tutor) { }'; } else { //The order is important you need to check the the $column variable in the model.ajax.php file - $columns = array( + $columns = [ get_lang('StartDate'), get_lang('Score'), get_lang('Actions') - ); + ]; //Column config // @todo fix search firstname/lastname that doesn't work. rmove search for the moment - $column_model = array( - array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'), - array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'), - array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'), - ); + $column_model = [ + ['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'], + ['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'], + ['name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'], + ]; } //Autowidth @@ -296,11 +296,12 @@ $(function() { $columns, $column_model, $extra_params, - array(), + [], $action_links, true ); - if ($is_allowedToEdit || $is_tutor) { ?> + if ($is_allowedToEdit || $is_tutor) { + ?> //setSearchSelect("status"); // //view:true, del:false, add:false, edit:false, excel:true} @@ -322,7 +323,8 @@ $(function() { var sgrid = $("#results")[0]; sgrid.triggerToolbar(); - + });
diff --git a/main/exercise/hotpotatoes_exercise_result.class.php b/main/exercise/hotpotatoes_exercise_result.class.php index ec84c69267..84eb9a429f 100755 --- a/main/exercise/hotpotatoes_exercise_result.class.php +++ b/main/exercise/hotpotatoes_exercise_result.class.php @@ -9,10 +9,10 @@ class HotpotatoesExerciseResult { //stores the list of exercises - private $exercises_list = array(); + private $exercises_list = []; //stores the results - private $results = array(); + private $results = []; /** * Gets the results of all students (or just one student if access is limited) @@ -23,7 +23,7 @@ class HotpotatoesExerciseResult */ public function getExercisesReporting($document_path, $hotpotato_name) { - $return = array(); + $return = []; $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); @@ -61,14 +61,14 @@ class HotpotatoesExerciseResult ORDER BY c_id ASC, exe_date ASC"; } - $results = array(); + $results = []; $resx = Database::query($sql); while ($rowx = Database::fetch_array($resx, 'ASSOC')) { $results[] = $rowx; } - $hpresults = array(); + $hpresults = []; $resx = Database::query($sql); while ($rowx = Database::fetch_array($resx, 'ASSOC')) { $hpresults[] = $rowx; @@ -77,7 +77,7 @@ class HotpotatoesExerciseResult // Print the Result of Hotpotatoes Tests if (is_array($hpresults)) { for ($i = 0; $i < sizeof($hpresults); $i++) { - $return[$i] = array(); + $return[$i] = []; $title = GetQuizName($hpresults[$i]['exe_name'], $document_path); if ($title == '') { $title = basename($hpresults[$i]['exe_name']); @@ -141,11 +141,11 @@ class HotpotatoesExerciseResult // Results foreach ($this->results as $row) { if (api_is_western_name_order()) { - $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; - $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; + $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; + $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; } else { - $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; - $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; + $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; + $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; } $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';'; diff --git a/main/exercise/hotspot.class.php b/main/exercise/hotspot.class.php index 0c17b0d228..796346dd11 100755 --- a/main/exercise/hotspot.class.php +++ b/main/exercise/hotspot.class.php @@ -48,21 +48,20 @@ class HotSpot extends Question $form->addElement( 'file', 'imageUpload', - array( + [ '', get_lang('UploadJpgPicture'), - ) + ] ); // setting the save button here and not in the question class.php // Saving a question $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); - //$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); $form->addRule( 'imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', - array('jpg', 'jpeg', 'png', 'gif') + ['jpg', 'jpeg', 'png', 'gif'] ); $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); } else { @@ -92,7 +91,7 @@ class HotSpot extends Question return false; } - function createAnswersForm($form) + public function createAnswersForm($form) { // nothing } @@ -136,7 +135,6 @@ class HotSpotDelineation extends HotSpot */ public function processCreation($form, $exercise) { - $file_info = $form->getSubmitValue('imageUpload'); parent::processCreation($form, $exercise); } diff --git a/main/exercise/hotspot.inc.php b/main/exercise/hotspot.inc.php index ba6bf2d6f5..0bc3f9629f 100755 --- a/main/exercise/hotspot.inc.php +++ b/main/exercise/hotspot.inc.php @@ -18,10 +18,10 @@ header('Content-Type: text/html; charset=UTF-8'); $file = file(api_get_path(SYS_LANG_PATH).'english/hotspot.inc.php'); foreach ($file as &$value) { - $variable = explode('=', $value, 2); - if (count($variable) > 1) { - $variable = substr(trim($variable[0]), 1); - $variable = '&'.$variable.'='.api_utf8_encode(get_lang($variable)).' '; - echo $variable; - } + $variable = explode('=', $value, 2); + if (count($variable) > 1) { + $variable = substr(trim($variable[0]), 1); + $variable = '&'.$variable.'='.api_utf8_encode(get_lang($variable)).' '; + echo $variable; + } } diff --git a/main/exercise/hotspot_admin.inc.php b/main/exercise/hotspot_admin.inc.php index f4e7a5faca..25f4a83c34 100755 --- a/main/exercise/hotspot_admin.inc.php +++ b/main/exercise/hotspot_admin.inc.php @@ -162,7 +162,7 @@ if ($submitAnswers || $buttonBack) { $select_question = $_POST['select_question']; $try = isset($_POST['try']) ? $_POST['try'] : []; $url = $_POST['url']; - $destination = array(); + $destination = []; $threadhold1 = $_POST['threadhold1']; $threadhold2 = $_POST['threadhold2']; @@ -374,13 +374,13 @@ if ($modifyAnswers) { } } - $reponse = array(); - $comment = array(); - $weighting = array(); - $hotspot_coordinates = array(); - $hotspot_type = array(); - $destination_items = array(); - $destination = array(); + $reponse = []; + $comment = []; + $weighting = []; + $hotspot_coordinates = []; + $hotspot_type = []; + $destination_items = []; + $destination = []; for ($i = 1; $i <= $nbrAnswers; $i++) { $reponse[$i] = $objAnswer->selectAnswer($i); @@ -433,7 +433,7 @@ if ($modifyAnswers) { $url_noerror = $destination_items[4]; } - $_SESSION['tmp_answers'] = array(); + $_SESSION['tmp_answers'] = []; $_SESSION['tmp_answers']['answer'] = $reponse; if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) { @@ -533,7 +533,7 @@ if ($modifyAnswers) { } if ($answerType == HOT_SPOT_DELINEATION) { - $hotspot_colors = array( + $hotspot_colors = [ "", "#4271B5", "#FE8E16", @@ -547,9 +547,9 @@ if ($modifyAnswers) { "#F4EB24", "#ED2024", "#3B3B3B" - ); + ]; } else { - $hotspot_colors = array( + $hotspot_colors = [ "", // $i starts from 1 on next loop (ugly fix) "#4271B5", "#FE8E16", @@ -564,7 +564,7 @@ if ($modifyAnswers) { "#ED2024", "#3B3B3B", "#F7BDE2" - ); + ]; } Display::tag( @@ -576,28 +576,30 @@ if ($modifyAnswers) { echo Display::return_message($msgErr, 'normal'); //main API } - $hotspot_admin_url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&hotspotadmin=' - .$modifyAnswers.'&exerciseId='.$exerciseId.'&'.api_get_cidreq(); - ?> + $hotspot_admin_url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&hotspotadmin='.$modifyAnswers.'&exerciseId='.$exerciseId; ?>
- + - + - + @@ -619,82 +621,80 @@ if ($modifyAnswers) { } } else { echo ''.get_lang('Comment').''; - } - ?> + } ?> * get_flat_list(); - - for ($i = 1; $i <= $nbrAnswers; $i++) { - // is an delineation - if ($answerType == HOT_SPOT_DELINEATION) { - $option_lp = ''; - - // setting the LP - $isSelected = false; - foreach ($flat_list as $id => $details) { - $selected = ''; - if (isset($lp[$i]) && $id == $lp[$i]) { - $isSelected = true; - $selected = 'selected="selected"'; - } - $option_lp .= ''; - } + // Loading list of LPs + $flat_list = $list->get_flat_list(); + + for ($i = 1; $i <= $nbrAnswers; $i++) { + // is an delineation + if ($answerType == HOT_SPOT_DELINEATION) { + $option_lp = ''; + + // setting the LP + $isSelected = false; + foreach ($flat_list as $id => $details) { + $selected = ''; + if (isset($lp[$i]) && $id == $lp[$i]) { + $isSelected = true; + $selected = 'selected="selected"'; + } + $option_lp .= ''; + } - if ($isSelected) { - $option_lp = ''.$option_lp; - } else { - $option_lp = ''.$option_lp; + } else { + $option_lp = ''.$option_lp; - } + } - // Feedback SELECT - $question_list = $objExercise->selectQuestionList(); - $option_feed = ''; - $option_feed .= ''; + // Feedback SELECT + $question_list = $objExercise->selectQuestionList(); + $option_feed = ''; + $option_feed .= ''; - foreach ($question_list as $key => $questionid) { - $selected = ''; - $question = Question::read($questionid); - $val = 'Q'.$key.' :'.substrwords($question->selectTitle(), ICON_SIZE_SMALL); + foreach ($question_list as $key => $questionid) { + $selected = ''; + $question = Question::read($questionid); + $val = 'Q'.$key.' :'.substrwords($question->selectTitle(), ICON_SIZE_SMALL); - if (isset($select_question[$i]) && $questionid == $select_question[$i]) { - $selected = 'selected="selected"'; - } + if (isset($select_question[$i]) && $questionid == $select_question[$i]) { + $selected = 'selected="selected"'; + } - $option_feed .= ''; - } + $option_feed .= ''; + } - if (isset($select_question[$i]) && $select_question[$i] == -1) { - $option_feed .= ''; - } else { - $option_feed .= ''; - } + if (isset($select_question[$i]) && $select_question[$i] == -1) { + $option_feed .= ''; + } else { + $option_feed .= ''; + } - //-------- IF it is a delineation - if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') { - $option1 = $option2 = $option3 = ''; - for ($k = 1; $k <= 100; $k++) { - $selected1 = $selected2 = $selected3 = ''; - if ($k == $threadhold1[$i]) { - $selected1 = 'selected="selected"'; - } - if ($k == $threadhold2[$i]) { - $selected2 = 'selected="selected"'; - } - if ($k == $threadhold3[$i]) { - $selected3 = 'selected="selected"'; - } - $option1 .= ''; - $option2 .= ''; - $option3 .= ''; - } - ?> + //-------- IF it is a delineation + if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') { + $option1 = $option2 = $option3 = ''; + for ($k = 1; $k <= 100; $k++) { + $selected1 = $selected2 = $selected3 = ''; + if ($k == $threadhold1[$i]) { + $selected1 = 'selected="selected"'; + } + if ($k == $threadhold2[$i]) { + $selected2 = 'selected="selected"'; + } + if ($k == $threadhold3[$i]) { + $selected3 = 'selected="selected"'; + } + $option1 .= ''; + $option2 .= ''; + $option3 .= ''; + } ?>