diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 85dad02b8d..d81f5a9729 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2283,7 +2283,8 @@ class Exercise break; case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: if ($from_database) { - $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = ".$exeId." AND question_id= ".$questionId; + $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." + WHERE exe_id = ".$exeId." AND question_id= ".$questionId; $resultans = Database::query($queryans); while ($row = Database::fetch_array($resultans)) { $ind = $row['answer']; @@ -2315,7 +2316,8 @@ class Exercise break; case MULTIPLE_ANSWER_COMBINATION: if ($from_database) { - $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'"; + $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." + WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'"; $resultans = Database::query($queryans); while ($row = Database::fetch_array($resultans)) { $ind = $row['answer']; @@ -3787,34 +3789,40 @@ class Exercise $lp_item_view_id = 0, $filter_by_admin = true ) { - //1. By default the exercise is visible + // 1. By default the exercise is visible $is_visible = true; $message = null; - //1.1 Admins and teachers can access to the exercise + // 1.1 Admins and teachers can access to the exercise if ($filter_by_admin) { if (api_is_platform_admin() || api_is_course_admin()) { return array('value' => true, 'message' => ''); } } - //Checking visibility in the item_property table + // Checking visibility in the item_property table. $visibility = api_get_item_visibility(api_get_course_info(), TOOL_QUIZ, $this->id, api_get_session_id()); if ($visibility == 0) { $this->active = 0; } - //2. If the exercise is not active + // 2. If the exercise is not active. if (empty($lp_id)) { //2.1 LP is OFF if ($this->active == 0) { - return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)); + return array( + 'value' => false, + 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false) + ); } } else { //2.1 LP is loaded if ($this->active == 0 AND !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) { - return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)); + return array( + 'value' => false, + 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false) + ); } } @@ -3851,6 +3859,7 @@ class Exercise // 4. We check if the student have attempts $exerciseAttempts = $this->selectAttempts(); + if ($is_visible) { if ($exerciseAttempts > 0) { diff --git a/main/exercice/fill_blanks.class.php b/main/exercice/fill_blanks.class.php index b92b48f8a8..98a26c6a22 100755 --- a/main/exercice/fill_blanks.class.php +++ b/main/exercice/fill_blanks.class.php @@ -1,21 +1,8 @@ getSubmitValue('answer'); //remove the :: eventually written by the user - $answer = str_replace('::','',$answer); + $answer = str_replace('::', '', $answer); - // get the blanks weightings - $nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks); - if (isset($_GET['editQuestion'])) { - $this -> weighting = 0; - } + // get the blanks weightings + $nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks); + if (isset($_GET['editQuestion'])) { + $this ->weighting = 0; + } - if ($nb>0) { + if ($nb > 0) { $answer .= '::'; - for($i=0 ; $i<$nb ; ++$i) { - $blankItem = $blanks[0][$i]; - $replace = array("[", "]"); - $newBlankItem = str_replace($replace, "", $blankItem); - $newBlankItem = "[".trim($newBlankItem)."]"; - $answer = str_replace($blankItem, $newBlankItem, $answer); - $answer .= $form->getSubmitValue('weighting['.$i.']').','; - $this -> weighting += $form->getSubmitValue('weighting['.$i.']'); - } - $answer = api_substr($answer,0,-1); + for ($i=0 ; $i < $nb; ++$i) { + $blankItem = $blanks[0][$i]; + $replace = array("[", "]"); + $newBlankItem = str_replace($replace, "", $blankItem); + $newBlankItem = "[".trim($newBlankItem)."]"; + $answer = str_replace($blankItem, $newBlankItem, $answer); + $answer .= $form->getSubmitValue('weighting['.$i.']').','; + $this -> weighting += $form->getSubmitValue('weighting['.$i.']'); + } + $answer = api_substr($answer, 0, -1); } $is_multiple = $form->getSubmitValue('multiple_answer'); - - $answer.='@'.$is_multiple; + $answer.= '@'.$is_multiple; $this->save(); $objAnswer = new answer($this->id); @@ -196,7 +182,13 @@ class FillBlanks extends Question $objAnswer->save(); } - function return_header($feedback_type = null, $counter = null, $score = null) + /** + * @param null $feedback_type + * @param null $counter + * @param null $score + * @return null|string + */ + function return_header($feedback_type = null, $counter = null, $score = null) { $header = parent::return_header($feedback_type, $counter, $score); $header .= '