Add question type validator - loosely refs CT#7705

1.10.x
Yannick Warnier 10 years ago
parent 47c98206c0
commit 11819bd9ee
  1. 25
      main/inc/lib/api.lib.php
  2. 51
      main/inc/lib/pear/HTML/QuickForm/Rule/QuestionType.php
  3. 6
      main/inc/lib/pear/HTML/QuickForm/RuleRegistry.php

@ -459,7 +459,7 @@ define('RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES', 3); //Show final
define('EXERCISE_MAX_NAME_SIZE', 80);
// Question types
// Question types (edit next array as well when adding values)
// @todo move into a class
define('UNIQUE_ANSWER', 1);
define('MULTIPLE_ANSWER', 2);
@ -481,6 +481,29 @@ define('UNIQUE_ANSWER_IMAGE', 17);
define('DRAGGABLE', 18);
define('MATCHING_DRAGGABLE', 19);
// one big string with all question types, for the validator in pear/HTML/QuickForm/Rule/QuestionType
define('QUESTION_TYPES',
UNIQUE_ANSWER.':'.
MULTIPLE_ANSWER.':'.
FILL_IN_BLANKS.':'.
MATCHING.':'.
FREE_ANSWER.':'.
HOT_SPOT.':'.
HOT_SPOT_ORDER.':'.
HOT_SPOT_DELINEATION.':'.
MULTIPLE_ANSWER_COMBINATION.':'.
UNIQUE_ANSWER_NO_OPTION.':'.
MULTIPLE_ANSWER_TRUE_FALSE.':'.
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE.':'.
ORAL_EXPRESSION.':'.
GLOBAL_MULTIPLE_ANSWER.':'.
MEDIA_QUESTION.':'.
CALCULATED_ANSWER.':'.
UNIQUE_ANSWER_IMAGE.':'.
DRAGGABLE.':'.
MATCHING_DRAGGABLE
);
//Some alias used in the QTI exports
define('MCUA', 1);
define('TF', 1);

@ -0,0 +1,51 @@
<?php
/**
* Required elements validation
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Required elements validation
*
* @category HTML
* @package HTML_QuickForm
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @version Based on release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_QuestionType extends HTML_QuickForm_Rule
{
/**
* Checks if a value is one of the accepted question types
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
public function validate($value, $options = null)
{
// It seems this is a file.
if (in_array($value, preg_split('/:/', QUESTION_TYPES))) {
return true;
}
return false;
}
}

@ -94,7 +94,7 @@ class HTML_QuickForm_RuleRegistry
} elseif ($type == 'function' || $type == 'callback') {
// Callback function
$rule =& $this->getRule('callback');
$rule = $this->getRule('callback');
$rule->addData($ruleName, $data1, $data2, 'function' == $type);
} elseif (is_object($data1)) {
// An instance of HTML_QuickForm_Rule
@ -148,7 +148,9 @@ class HTML_QuickForm_RuleRegistry
'uploadedfile' => 'HTML_QuickForm_Rule_UploadFile',
'maxfilesize', 'HTML_QuickForm_Rule_MaxFileSize',
'mimetype', 'HTML_QuickForm_Rule_MimeType',
'filename', 'HTML_QuickForm_Rule_FileName'
'filename', 'HTML_QuickForm_Rule_FileName',
'validquestiontype' => 'HTML_QuickForm_Rule_QuestionType',
);
$class = $rules[$ruleName];

Loading…
Cancel
Save