From dfd2f6f3ec845cc95281d96035d963c19cd9f3a2 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 15 Mar 2018 12:17:05 +0100 Subject: [PATCH] Minor - format code --- main/exercise/admin.php | 45 +++++++--------- main/exercise/showinframes.php | 8 ++- main/exercise/stats.php | 91 ++++++++++++++++++-------------- main/exercise/tests_category.php | 18 +++---- 4 files changed, 83 insertions(+), 79 deletions(-) diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 62b268ef0d..a438559f49 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -136,13 +136,13 @@ $picturePath = $documentPath.'/images'; $audioPath = $documentPath.'/audio'; // the 5 types of answers -$aType = array( +$aType = [ get_lang('UniqueSelect'), get_lang('MultipleSelect'), get_lang('FillBlanks'), get_lang('Matching'), get_lang('FreeAnswer') -); +]; // tables used in the exercise tool @@ -167,7 +167,6 @@ if (!empty($_GET['action']) && $_GET['action'] == 'exportqti2' && !empty($_GET[' unlink($temp_zip_file); unlink($temp_xml_file); rmdir($temp_zip_dir); - //DocumentManager::string_send_for_download($export,true,'qti2export_q'.$_GET['questionId'].'.xml'); exit; //otherwise following clicks may become buggy } @@ -206,7 +205,7 @@ if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) { if ($editQuestion) { // question not found if (!$objQuestion = Question::read($editQuestion)) { - api_not_allowed(); + api_not_allowed(true); } // saves the object into the session Session::write('objQuestion', $objQuestion); @@ -251,10 +250,15 @@ if (!empty($clone_question) && !empty($objExercise->id)) { $old_question_obj = Question::read($clone_question); $old_question_obj->question = $old_question_obj->question.' - '.get_lang('Copy'); - $new_id = $old_question_obj->duplicate(); + $new_id = $old_question_obj->duplicate(api_get_course_info()); $new_question_obj = Question::read($new_id); $new_question_obj->addToList($exerciseId); + // Save category to the destination course + if (!empty($old_question_obj->category)) { + $new_question_obj->saveCategory($old_question_obj->category, api_get_course_int_id()); + } + // This should be moved to the duplicate function $new_answer_obj = new Answer($clone_question); $new_answer_obj->read(); @@ -280,16 +284,16 @@ if ($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers) { } if (api_is_in_gradebook()) { - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('ToolGradebook') - ); + ]; } -$interbreadcrumb[] = array("url" => "exercise.php", "name" => get_lang('Exercises')); +$interbreadcrumb[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')]; if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) { $interbreadcrumb[] = [ - "url" => "admin.php?exerciseId=".$objExercise->id, + "url" => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(), "name" => $objExercise->selectTitle(true), ]; } else { @@ -301,18 +305,16 @@ if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) { // shows a link to go back to the question pool if (!$exerciseId && $nameTools != get_lang('ExerciseManagement')) { - $interbreadcrumb[] = array( + $interbreadcrumb[] = [ "url" => api_get_path(WEB_CODE_PATH)."exercise/question_pool.php?fromExercise=$fromExercise&".api_get_cidreq(), "name" => get_lang('QuestionPool') - ); + ]; } // if the question is duplicated, disable the link of tool name if ($modifyIn == 'thisExercise') { if ($buttonBack) { $modifyIn = 'allExercises'; - } else { - $noPHP_SELF = true; } } $htmlHeadXtra[] = ''; $htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js'); @@ -346,29 +347,22 @@ $htmlHeadXtra[] = ''; if (isset($_GET['message'])) { - if (in_array($_GET['message'], array('ExerciseStored', 'ItemUpdated', 'ItemAdded'))) { + if (in_array($_GET['message'], ['ExerciseStored', 'ItemUpdated', 'ItemAdded'])) { Display::addFlash(Display::return_message(get_lang($_GET['message']), 'confirmation')); } } Display::display_header($nameTools, 'Exercise'); -/* -if ($objExercise->exercise_was_added_in_lp) { - if ($objExercise->force_edit_exercise_in_lp == true) { - Display::addFlash(Display::return_message(get_lang('ForceEditingExerciseInLPWarning'), 'warning')); - } else { - Display::addFlash(Display::return_message(get_lang('EditingExerciseCauseProblemsInLP'), 'warning')); - } -}*/ // If we are in a test $inATest = isset($exerciseId) && $exerciseId > 0; if ($inATest) { echo '
'; - if (isset($_GET['hotspotadmin']) || isset($_GET['newQuestion']) || isset($_GET['myid'])) + if (isset($_GET['hotspotadmin']) || isset($_GET['newQuestion']) || isset($_GET['myid'])) { echo ''. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).''; + } if (!isset($_GET['hotspotadmin']) && !isset($_GET['newQuestion']) && !isset($_GET['myid']) && !isset($_GET['editQuestion'])) { echo ''. @@ -414,7 +408,6 @@ if ($inATest) { sprintf(get_lang('OnlyXQuestionsPickedRandomly'), $objExercise->random); } echo '
'; - } elseif (isset($_GET['newQuestion'])) { // we are in create a new question from question pool not in a test echo '
'; @@ -444,7 +437,7 @@ if ($newQuestion || $editQuestion) { // Question preview if teacher clicked the "switch to student" if ($studentViewActive && $is_allowedToEdit) { echo '
'; - echo Display::div($objQuestion->selectTitle(), array('class' => 'question_title')); + echo Display::div($objQuestion->selectTitle(), ['class' => 'question_title']); ExerciseLib::showQuestion( $objExercise, $editQuestion, diff --git a/main/exercise/showinframes.php b/main/exercise/showinframes.php index 2bb9954791..dad1aa472c 100755 --- a/main/exercise/showinframes.php +++ b/main/exercise/showinframes.php @@ -12,7 +12,7 @@ require_once api_get_path(SYS_CODE_PATH).'exercise/hotpotatoes.lib.php'; $_course = api_get_course_info(); $time = time(); -$doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file'])); +$doc_url = str_replace(['../', '\\', '\\0', '..'], ['', '', '', ''], urldecode($_GET['file'])); $cid = api_get_course_id(); $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'; @@ -66,15 +66,13 @@ $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url)); $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document"; $my_file = Security::remove_XSS($_GET['file']); -$my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file)); +$my_file = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], urldecode($my_file)); $title = GetQuizName($my_file, $documentPath); if ($title == '') { $title = basename($my_file); } $nameTools = $title; -$noPHP_SELF = true; - $htmlHeadXtra[] = /** @lang HTML */<< $(document).on('ready', function () { @@ -87,7 +85,7 @@ $htmlHeadXtra[] = /** @lang HTML */<< HTML; -$interbreadcrumb[] = array("url"=>"./exercise.php", "name"=> get_lang('Exercises')); +$interbreadcrumb[] = ["url"=>"./exercise.php", "name"=> get_lang('Exercises')]; if ($origin == 'learnpath') { Display::display_reduced_header($nameTools, "Exercise"); } else { diff --git a/main/exercise/stats.php b/main/exercise/stats.php index 98a4c4862a..2189db2564 100755 --- a/main/exercise/stats.php +++ b/main/exercise/stats.php @@ -5,9 +5,23 @@ require_once __DIR__.'/../inc/global.inc.php'; $this_section = SECTION_COURSES; -$exercise_id = isset($_GET['exerciseId']) && !empty($_GET['exerciseId']) ? intval($_GET['exerciseId']) : 0; +api_protect_course_script(true, false, true); + +$showPage = false; + +if (api_is_platform_admin() || api_is_course_admin() || + api_is_course_tutor() || api_is_session_general_coach() || api_is_allowed_to_edit(null, true) +) { + $showPage = true; +} + +if (!$showPage) { + api_not_allowed(true); +} + +$exerciseId = isset($_GET['exerciseId']) && !empty($_GET['exerciseId']) ? (int) $_GET['exerciseId'] : 0; $objExercise = new Exercise(); -$result = $objExercise->read($exercise_id); +$result = $objExercise->read($exerciseId); if (!$result) { api_not_allowed(true); @@ -31,9 +45,9 @@ if (empty($sessionId)) { $count_students = count($students); $question_list = $objExercise->get_validated_question_list(); -$data = array(); +$data = []; // Question title # of students who tool it Lowest score Average Highest score Maximum score -$headers = array( +$headers = [ get_lang('Question'), get_lang('QuestionType'), get_lang('NumberStudentWhoSelectedIt'), @@ -41,48 +55,48 @@ $headers = array( get_lang('AverageScore'), get_lang('HighestScore'), get_lang('Weighting'), -); +]; if (!empty($question_list)) { foreach ($question_list as $question_id) { - $question_obj = Question::read($question_id); + $questionObj = Question::read($question_id); $exercise_stats = ExerciseLib::get_student_stats_by_question( $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId ); $count_users = ExerciseLib::get_number_students_question_with_answer_count( $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId, - $question_obj->type + $questionObj->type ); - $data[$question_id]['name'] = cut($question_obj->question, 100); - $data[$question_id]['type'] = $question_obj->get_question_type_name(); - $percentange = 0; + $data[$question_id]['name'] = cut($questionObj->question, 100); + $data[$question_id]['type'] = $questionObj->get_question_type_name(); + $percentage = 0; if ($count_students) { - $percentange = $count_users / $count_students * 100; + $percentage = $count_users / $count_students * 100; } $data[$question_id]['students_who_try_exercise'] = Display::bar_progress( - $percentange, + $percentage, false, $count_users.' / '.$count_students ); $data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2); $data[$question_id]['average_score'] = round($exercise_stats['average'], 2); $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2); - $data[$question_id]['max_score'] = round($question_obj->weighting, 2); + $data[$question_id]['max_score'] = round($questionObj->weighting, 2); } } // Format A table -$table = new HTML_Table(array('class' => 'data_table')); +$table = new HTML_Table(['class' => 'data_table']); $row = 0; $column = 0; foreach ($headers as $header) { @@ -103,23 +117,22 @@ foreach ($data as $row_table) { $content = $table->toHtml(); // Format B - -$headers = array( +$headers = [ get_lang('Question'), get_lang('Answer'), get_lang('Correct'), get_lang('NumberStudentWhoSelectedIt') -); +]; -$data = array(); +$data = []; if (!empty($question_list)) { $id = 0; foreach ($question_list as $question_id) { - $question_obj = Question::read($question_id); + $questionObj = Question::read($question_id); $exercise_stats = ExerciseLib::get_student_stats_by_question( $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId ); @@ -134,7 +147,7 @@ if (!empty($question_list)) { $real_answer_id = $answer->selectAutoId($answer_id); // Overwriting values depending of the question - switch ($question_obj->type) { + switch ($questionObj->type) { case FILL_IN_BLANKS: $answer_info_db = $answer_info; $answer_info = substr($answer_info, 0, strpos($answer_info, '::')); @@ -143,7 +156,7 @@ if (!empty($question_list)) { $counter = 0; foreach ($answers as $answer_item) { if ($counter == 0) { - $data[$id]['name'] = cut($question_obj->question, 100); + $data[$id]['name'] = cut($questionObj->question, 100); } else { $data[$id]['name'] = '-'; } @@ -155,7 +168,7 @@ if (!empty($question_list)) { $data[$id]['answer'] = $answer_item; $data[$id]['correct'] = '-'; - $count = ExerciseLib::getNumberStudentsFillBlanksAnswerCount($question_id, $exercise_id); + $count = ExerciseLib::getNumberStudentsFillBlanksAnswerCount($question_id, $exerciseId); $count = isset($count[$counter]) ? $count[$counter] : 0; $percentage = 0; @@ -176,7 +189,7 @@ if (!empty($question_list)) { case MATCHING_DRAGGABLE: if ($is_correct == 0) { if ($answer_id == 1) { - $data[$id]['name'] = cut($question_obj->question, 100); + $data[$id]['name'] = cut($questionObj->question, 100); } else { $data[$id]['name'] = '-'; } @@ -194,7 +207,7 @@ if (!empty($question_list)) { $count = ExerciseLib::get_number_students_answer_count( $answer_id, $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId, MATCHING @@ -212,7 +225,7 @@ if (!empty($question_list)) { break; case HOT_SPOT: if ($answer_id == 1) { - $data[$id]['name'] = cut($question_obj->question, 100); + $data[$id]['name'] = cut($questionObj->question, 100); } else { $data[$id]['name'] = '-'; } @@ -222,7 +235,7 @@ if (!empty($question_list)) { $count = ExerciseLib::get_number_students_answer_hotspot_count( $answer_id, $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId ); @@ -238,7 +251,7 @@ if (!empty($question_list)) { break; default: if ($answer_id == 1) { - $data[$id]['name'] = cut($question_obj->question, 100); + $data[$id]['name'] = cut($questionObj->question, 100); } else { $data[$id]['name'] = '-'; } @@ -248,7 +261,7 @@ if (!empty($question_list)) { $count = ExerciseLib::get_number_students_answer_count( $real_answer_id, $question_id, - $exercise_id, + $exerciseId, $courseCode, $sessionId ); @@ -268,7 +281,7 @@ if (!empty($question_list)) { } // Format A table -$table = new HTML_Table(array('class' => 'data_table')); +$table = new HTML_Table(['class' => 'data_table']); $row = 0; $column = 0; foreach ($headers as $header) { @@ -288,17 +301,17 @@ foreach ($data as $row_table) { } $content .= $table->toHtml(); -$interbreadcrumb[] = array( +$interbreadcrumb[] = [ "url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises'), -); -$interbreadcrumb[] = array( - "url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), +]; +$interbreadcrumb[] = [ + "url" => "admin.php?exerciseId=$exerciseId&".api_get_cidreq(), "name" => $objExercise->selectTitle(true), -); +]; $tpl = new Template(get_lang('ReportByQuestion')); -$actions = ''. +$actions = ''. Display:: return_icon( 'back.png', get_lang('GoBackToQuestionList'), @@ -306,7 +319,7 @@ $actions = ' "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises'), -); +]; $action = isset($_GET['action']) ? $_GET['action'] : ''; $content = ''; @@ -125,18 +125,18 @@ function edit_category_form($action) // Setting the form elements $form->addElement('header', get_lang('EditCategory')); $form->addElement('hidden', 'category_id'); - $form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95')); + $form->addElement('text', 'category_name', get_lang('CategoryName'), ['size' => '95']); $form->addHtmlEditor( 'category_description', get_lang('CategoryDescription'), false, false, - array('ToolbarSet' => 'test_category', 'Height' => '200') + ['ToolbarSet' => 'test_category', 'Height' => '200'] ); $form->addButtonSave(get_lang('ModifyCategory'), 'SubmitNote'); // setting the defaults - $defaults = array(); + $defaults = []; $defaults["category_id"] = $objcat->id; $defaults["category_name"] = $objcat->name; $defaults["category_description"] = $objcat->description; @@ -166,7 +166,7 @@ function edit_category_form($action) } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); - $form->setConstants(array('sec_token' => $token)); + $form->setConstants(['sec_token' => $token]); return $form->returnForm(); } @@ -204,13 +204,13 @@ function add_category_form($action) $form = new FormValidator('note', 'post', api_get_self().'?action='.$action.'&'.api_get_cidreq()); // Setting the form elements $form->addElement('header', get_lang('AddACategory')); - $form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95')); + $form->addElement('text', 'category_name', get_lang('CategoryName'), ['size' => '95']); $form->addHtmlEditor( 'category_description', get_lang('CategoryDescription'), false, false, - array('ToolbarSet' => 'test_category', 'Height' => '200') + ['ToolbarSet' => 'test_category', 'Height' => '200'] ); $form->addButtonCreate(get_lang('AddTestCategory'), 'SubmitNote'); // setting the rules @@ -233,7 +233,7 @@ function add_category_form($action) } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); - $form->setConstants(array('sec_token' => $token)); + $form->setConstants(['sec_token' => $token]); return $form->returnForm(); }