Fix exercise edition UI see BT#17438

webservicelpcreate
Julio Montoya 5 years ago
parent 778150344a
commit fb1aeb8461
  1. 108
      main/exercise/exercise.class.php
  2. 19
      main/exercise/exercise_admin.php
  3. 4
      main/inc/lib/pear/HTML/QuickForm/checkbox.php
  4. 12
      main/inc/lib/pear/HTML/QuickForm/element.php
  5. 4
      main/inc/lib/pear/HTML/QuickForm/input.php
  6. 18
      main/inc/lib/pear/HTML/QuickForm/radio.php

@ -1203,6 +1203,30 @@ class Exercise
return Database::num_rows($result) > 0; return Database::num_rows($result) > 0;
} }
public function hasQuestionWithTypeNotInList(array $questionTypeList)
{
if (empty($questionTypeList)) {
return false;
}
$questionTypeToString = implode("','", array_map('intval', $questionTypeList));
$table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT q.id
FROM $table e
INNER JOIN $tableQuestion q
ON (e.question_id = q.id AND e.c_id = q.c_id)
WHERE
q.type NOT IN ('$questionTypeToString') AND
e.c_id = {$this->course_id} AND
e.exercice_id = ".$this->id;
$result = Database::query($sql);
return Database::num_rows($result) > 0;
}
/** /**
* changes the exercise title. * changes the exercise title.
* *
@ -1633,7 +1657,7 @@ class Exercise
api_get_user_id() api_get_user_id()
); );
if (api_get_setting('search_enabled') == 'true') { if (api_get_setting('search_enabled') === 'true') {
$this->search_engine_edit(); $this->search_engine_edit();
} }
} else { } else {
@ -1739,7 +1763,7 @@ class Exercise
$this->course $this->course
); );
if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { if (api_get_setting('search_enabled') === 'true' && extension_loaded('xapian')) {
$this->search_engine_save(); $this->search_engine_save();
} }
} }
@ -1988,7 +2012,7 @@ class Exercise
); );
$skillList = []; $skillList = [];
if ($type === 'full') { if ('full' === $type) {
// Can't modify a DirectFeedback question. // Can't modify a DirectFeedback question.
if (!in_array($this->getFeedbackType(), [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) { if (!in_array($this->getFeedbackType(), [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) {
$this->setResultFeedbackGroup($form); $this->setResultFeedbackGroup($form);
@ -2024,7 +2048,7 @@ class Exercise
$form->addGroup($radios, null, get_lang('QuestionsPerPage')); $form->addGroup($radios, null, get_lang('QuestionsPerPage'));
} else { } else {
// if is Direct feedback but has not questions we can allow to modify the question type // if is Direct feedback but has not questions we can allow to modify the question type
if ($this->getQuestionCount() === 0) { if (0 === $this->getQuestionCount()) {
$this->setResultFeedbackGroup($form); $this->setResultFeedbackGroup($form);
$this->setResultDisabledGroup($form); $this->setResultDisabledGroup($form);
@ -2040,12 +2064,13 @@ class Exercise
); );
$form->addGroup($radios, null, get_lang('ExerciseType')); $form->addGroup($radios, null, get_lang('ExerciseType'));
} else { } else {
$this->setResultFeedbackGroup($form, true);
$group = $this->setResultDisabledGroup($form); $group = $this->setResultDisabledGroup($form);
$group->freeze(); $group->freeze();
// we force the options to the DirectFeedback exercisetype // we force the options to the DirectFeedback exercisetype
$form->addElement('hidden', 'exerciseFeedbackType', $this->getFeedbackType()); //$form->addElement('hidden', 'exerciseFeedbackType', $this->getFeedbackType());
$form->addElement('hidden', 'exerciseType', ONE_PER_PAGE); //$form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
// Type of questions disposition on page // Type of questions disposition on page
$radios[] = $form->createElement( $radios[] = $form->createElement(
@ -2545,11 +2570,10 @@ class Exercise
} }
} }
/** public function setResultFeedbackGroup(FormValidator $form, $checkFreeze = true)
* @param $form
*/
public function setResultFeedbackGroup(FormValidator $form)
{ {
$freeze = false;
// Feedback type. // Feedback type.
$feedback = []; $feedback = [];
$feedback[] = $form->createElement( $feedback[] = $form->createElement(
@ -2564,43 +2588,47 @@ class Exercise
] ]
); );
if (api_get_setting('enable_quiz_scenario') === 'true') { $freeze = true;
// Can't convert a question from one feedback to another if ('true' === api_get_setting('enable_quiz_scenario')) {
// if there is more than 1 question already added if (0 === $this->getQuestionCount()) {
if ($this->selectNbrQuestions() == 0) { $freeze = false;
$feedback[] = $form->createElement( } else {
'radio', $hasDifferentQuestion = $this->hasQuestionWithTypeNotInList([UNIQUE_ANSWER, HOT_SPOT_DELINEATION]);
'exerciseFeedbackType', if (false === $hasDifferentQuestion) {
null, $freeze = false;
get_lang('DirectFeedback'), }
EXERCISE_FEEDBACK_TYPE_DIRECT,
[
'id' => 'exerciseType_'.EXERCISE_FEEDBACK_TYPE_DIRECT,
'onclick' => 'check_direct_feedback()',
]
);
} }
} }
$feedback[] = $form->createElement( $direct = $form->createElement(
'radio', 'radio',
'exerciseFeedbackType', 'exerciseFeedbackType',
null, null,
get_lang('ExerciseDirectPopUp'), get_lang('DirectFeedback'),
EXERCISE_FEEDBACK_TYPE_POPUP, EXERCISE_FEEDBACK_TYPE_DIRECT,
['id' => 'exerciseType_'.EXERCISE_FEEDBACK_TYPE_POPUP, 'onclick' => 'check_direct_feedback()'] [
'id' => 'exerciseType_'.EXERCISE_FEEDBACK_TYPE_DIRECT,
'onclick' => 'check_direct_feedback()',
]
); );
if ($freeze) {
$direct->freeze();
}
$feedback[] = $direct;
$feedback[] = $form->createElement( $feedback[] = $form->createElement(
'radio', 'radio',
'exerciseFeedbackType', 'exerciseFeedbackType',
null, null,
get_lang('NoFeedback'), get_lang('ExerciseDirectPopUp'),
EXERCISE_FEEDBACK_TYPE_EXAM, EXERCISE_FEEDBACK_TYPE_POPUP,
['id' => 'exerciseType_'.EXERCISE_FEEDBACK_TYPE_EXAM] ['id' => 'exerciseType_'.EXERCISE_FEEDBACK_TYPE_POPUP, 'onclick' => 'check_direct_feedback()']
); );
$form->addGroup( $group = $form->addGroup(
$feedback, $feedback,
null, null,
[ [
@ -2608,6 +2636,10 @@ class Exercise
get_lang('FeedbackDisplayOptions'), get_lang('FeedbackDisplayOptions'),
] ]
); );
if ($freeze) {
//$group->freeze();
}
} }
/** /**
@ -2625,6 +2657,12 @@ class Exercise
$this->updateAttempts($form->getSubmitValue('exerciseAttempts')); $this->updateAttempts($form->getSubmitValue('exerciseAttempts'));
$this->updateFeedbackType($form->getSubmitValue('exerciseFeedbackType')); $this->updateFeedbackType($form->getSubmitValue('exerciseFeedbackType'));
$this->updateType($form->getSubmitValue('exerciseType')); $this->updateType($form->getSubmitValue('exerciseType'));
// If direct feedback then force to One per page
if (EXERCISE_FEEDBACK_TYPE_DIRECT == $form->getSubmitValue('exerciseFeedbackType')) {
$this->updateType(ONE_PER_PAGE);
}
$this->setRandom($form->getSubmitValue('randomQuestions')); $this->setRandom($form->getSubmitValue('randomQuestions'));
$this->updateRandomAnswers($form->getSubmitValue('randomAnswers')); $this->updateRandomAnswers($form->getSubmitValue('randomAnswers'));
$this->updateResultsDisabled($form->getSubmitValue('results_disabled')); $this->updateResultsDisabled($form->getSubmitValue('results_disabled'));
@ -10415,13 +10453,11 @@ class Exercise
); );
if (in_array($this->getFeedbackType(), [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) { if (in_array($this->getFeedbackType(), [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) {
$group = $form->addGroup( return $form->addGroup(
$resultDisabledGroup, $resultDisabledGroup,
null, null,
get_lang('ShowResultsToStudents') get_lang('ShowResultsToStudents')
); );
return $group;
} }
$resultDisabledGroup[] = $form->createElement( $resultDisabledGroup[] = $form->createElement(

@ -112,22 +112,20 @@ $htmlHeadXtra[] = '<script>
break; break;
} }
} }
</script>';
// to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters; function setFocus(){
$htmlHeadXtra[] = '<script> $("#exercise_title").focus();
function setFocus(){ }
$("#exercise_title").focus();
} // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
$(function() { $(function() {
setFocus(); setFocus();
}); });
</script>'; </script>';
$objExercise = new Exercise(); $objExercise = new Exercise();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
//INIT FORM
if (isset($_GET['exerciseId'])) { if (isset($_GET['exerciseId'])) {
$form = new FormValidator( $form = new FormValidator(
'exercise_admin', 'exercise_admin',
@ -147,7 +145,6 @@ if (isset($_GET['exerciseId'])) {
$objExercise->createForm($form); $objExercise->createForm($form);
// VALIDATE FORM
if ($form->validate()) { if ($form->validate()) {
$objExercise->processCreation($form); $objExercise->processCreation($form);
if ($form->getSubmitValue('edit') === 'true') { if ($form->getSubmitValue('edit') === 'true') {

@ -232,9 +232,9 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
if ($this->getChecked()) { if ($this->getChecked()) {
return '<code>[x]</code>'. return '<code>[x]</code>'.
$this->_getPersistantData(); $this->_getPersistantData();
} else {
return '<code>[ ]</code>';
} }
return '<code>[ ]</code>';
} }
/** /**

@ -322,14 +322,12 @@ class HTML_QuickForm_element extends HTML_Common
'name' => $this->getName(), 'name' => $this->getName(),
'value' => $this->getValue() 'value' => $this->getValue()
) + (isset($id)? array('id' => $id): array())) . ' />'; ) + (isset($id)? array('id' => $id): array())) . ' />';
} }
/** /**
* Returns whether or not the element is frozen * Returns whether or not the element is frozen
* *
* @since 1.3 * @since 1.3
* @access public
* @return bool * @return bool
*/ */
public function isFrozen() public function isFrozen()
@ -343,10 +341,8 @@ class HTML_QuickForm_element extends HTML_Common
* *
* @param bool $persistant True if persistant value * @param bool $persistant True if persistant value
* @since 2.0 * @since 2.0
* @access public
* @return void
*/ */
function setPersistantFreeze($persistant=false) public function setPersistantFreeze($persistant=false)
{ {
$this->_persistantFreeze = $persistant; $this->_persistantFreeze = $persistant;
} }
@ -357,8 +353,6 @@ class HTML_QuickForm_element extends HTML_Common
* @param string $label Display text for the element * @param string $label Display text for the element
* @param string $label_for Optionally add a "for" attribute * @param string $label_for Optionally add a "for" attribute
* @since 1.3 * @since 1.3
* @access public
* @return void
*/ */
public function setLabel($label, $labelFor = null) public function setLabel($label, $labelFor = null)
{ {
@ -372,7 +366,6 @@ class HTML_QuickForm_element extends HTML_Common
* Returns display text for the element * Returns display text for the element
* *
* @since 1.3 * @since 1.3
* @access public
* @return string * @return string
*/ */
public function getLabel() public function getLabel()
@ -383,10 +376,9 @@ class HTML_QuickForm_element extends HTML_Common
/** /**
* Returns "for" attribute for the element * Returns "for" attribute for the element
* *
* @access public
* @return string * @return string
*/ */
function getLabelFor() public function getLabelFor()
{ {
return $this->_label_for; return $this->_label_for;
} }

@ -109,9 +109,9 @@ class HTML_QuickForm_input extends HTML_QuickForm_element
{ {
if ($this->isFrozen()) { if ($this->isFrozen()) {
return $this->getFrozenHtml(); return $this->getFrozenHtml();
} else {
return $this->_getTabs().'<input'.$this->_getAttrString($this->_attributes).' />';
} }
return $this->_getTabs().'<input'.$this->_getAttrString($this->_attributes).' />';
} }
/** /**

@ -33,12 +33,6 @@
*/ */
class HTML_QuickForm_radio extends HTML_QuickForm_input class HTML_QuickForm_radio extends HTML_QuickForm_input
{ {
/**
* Radio display text
* @var string
* @since 1.1
* @access private
*/
public $_text = ''; public $_text = '';
public $labelClass; public $labelClass;
public $radioClass; public $radioClass;
@ -54,7 +48,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* *
* @return void * @return void
* @since 1.0 * @since 1.0
* @access public
*/ */
public function __construct( public function __construct(
$elementName = null, $elementName = null,
@ -92,7 +85,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* *
* @return string * @return string
* @since 1.0 * @since 1.0
* @access public
*/ */
public function toHtml() public function toHtml()
{ {
@ -120,7 +112,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
return $label; return $label;
} }
return HTML_QuickForm_input::toHtml().$label; return parent::toHtml().$label;
} }
/** /**
@ -128,7 +120,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* *
* @return string * @return string
* @since 1.0 * @since 1.0
* @access public
*/ */
public function getChecked() public function getChecked()
{ {
@ -140,16 +131,15 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* *
* @return string * @return string
* @since 1.0 * @since 1.0
* @access public
*/ */
public function getFrozenHtml() public function getFrozenHtml()
{ {
if ($this->getChecked()) { if ($this->getChecked()) {
return '<code>(x)</code>'. return '<br /><code>(x)</code>'.
$this->_getPersistantData(); $this->_getPersistantData();
} else {
return '<code>( )</code>';
} }
return '<br /><code>( )</code>';
} }
/** /**

Loading…
Cancel
Save