From: Simon H. <sim...@us...> - 2010-09-30 16:56:55
|
Update of /cvsroot/stack/stack-dev/lib/ui/inputTypes In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv28438/lib/ui/inputTypes Modified Files: DropDownList.php SingleCharIT.php StringIT.php TextArea.php AnswerInputType.php AlgebraIT.php InputTypeController.php ListIT.php TrueFalseIT.php Matrix.php Added Files: Slider.php Log Message: Merging 2.2 branch (with some additional fixes to ensure seamless updating for version lines) Index: SingleCharIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/SingleCharIT.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SingleCharIT.php 27 Aug 2009 16:23:00 -0000 1.5 --- SingleCharIT.php 30 Sep 2010 16:56:13 -0000 1.6 *************** *** 104,108 **** return $box; } ! } --- 104,110 ---- return $box; } ! public static function getOptionsUsed() { ! return array('teacherAns', 'forbid', 'sameType', 'studentVerify', 'hideFeedback'); ! } } Index: AnswerInputType.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/AnswerInputType.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** AnswerInputType.php 11 Jan 2010 17:23:36 -0000 1.11 --- AnswerInputType.php 30 Sep 2010 16:56:13 -0000 1.12 *************** *** 160,163 **** --- 160,176 ---- } + /** + * Default is to assume all options used. Subclasses can overide with more restrictive sets. + */ + public static function getOptionsUsed() { + return array('teacherAns', 'boxSize','informalSyntax','insertStars', 'syntaxHint', 'forbid','allow','floats','lowest','sameType','studentVerify', 'hideFeedback'); + } + + /** + * Default is to specify no defaults. Subclasses can overide with some. + */ + public static function getOptionDefaults() { + return NULL; + } } Index: DropDownList.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/DropDownList.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DropDownList.php 11 Jan 2010 17:23:36 -0000 1.7 --- DropDownList.php 30 Sep 2010 16:56:13 -0000 1.8 *************** *** 157,161 **** } ! } ?> \ No newline at end of file --- 157,167 ---- } ! public static function getOptionsUsed() { ! return array('teacherAns', 'studentVerify', 'hideFeedback'); ! } + public static function getOptionDefaults() { + return array('studentVerify'=>'false', 'hideFeedback'=>'true'); + } + } ?> \ No newline at end of file Index: TextArea.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/TextArea.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TextArea.php 26 Jul 2010 09:25:14 -0000 1.4 --- TextArea.php 30 Sep 2010 16:56:13 -0000 1.5 *************** *** 113,117 **** $rows = $this->modinput_tokenizer(substr($this->default, 1, -1)); // array("[a,b]","[c,d]"); ! $norows = count($rows)+4; $dispval = ''; $cols = $this->boxWidth; --- 113,117 ---- $rows = $this->modinput_tokenizer(substr($this->default, 1, -1)); // array("[a,b]","[c,d]"); ! $norows = count($rows)+3; $dispval = ''; $cols = $this->boxWidth; *************** *** 126,130 **** /** ! * Converts the inputs passed in into a textares into a Maxima list * * @param string|array $in --- 126,130 ---- /** ! * Converts the inputs passed in into a textareas into a Maxima list * * @param string|array $in *************** *** 134,137 **** --- 134,141 ---- public function transform($in) { + if(''==trim($in)) { + return(''); + } + $vals = explode("\n",$in); $out = '['; *************** *** 231,235 **** --- 235,254 ---- } + /** + * Returns an array in the form of the $_POST data, used for the question tests. + * + * @param string $value + * @access public + * @return array + */ + public function getTestPostData($value) + { + $post_data=substr($value,1,strlen($value)-2); + return array($this->name=>$post_data); + } + public static function getOptionDefaults() { + return array('boxSize'=>25, 'studentVerify'=>'true', 'hideFeedback'=>'false'); + } } ?> \ No newline at end of file --- NEW FILE: Slider.php --- <?php /** * * Welcome to STACK. A system for teaching and assessment using a * computer algebra kernel. * * This file is licensed under the GPL License. * * A copy of the license is in your STACK distribution called * license.txt. If you are missing this file you can obtain * it from: * http://www.stack.bham.ac.uk/license.txt * * @author Benjamin Holmes (ma...@be...) * * @package stackInputType */ global $config; require_once 'AnswerInputType.php'; // A jQuery UI slider, see http://jqueryui.com/demos/slider class Slider extends AnswerInputType { // Attributes //protected $min; //protected $max; //protected $step; public function __construct($name, $width = null, $default = null, $maxLength = null, $height = null, $param = null) { //if (!isset($width)) $width = '200'; $this->name = $name; $this->boxWidth = $width; if($param == NULL) { $this->parameters['slider_min'] = new Meta('required', '0'); $this->parameters['slider_max'] = new Meta('required', '100'); $this->parameters['slider_step'] = new Meta('required', '1'); } else $this->parameters = $param; // parent::__construct($name, $width); //$this->min = $param['min']; //$this->max = $param['max']; //$this->step = $param['step']; parent::__construct($name, $width, $default, $maxLength, $height, $param); } public function getXHTML() { $url = $GLOBALS['config']->get('weburl'); // include jQuery and jQuery UI scripts $slider = '<link rel="stylesheet" type="text/css" href="' . $url . '/other/jqueryCSS/jquery.ui.css" /> <script type="text/javascript" src="' . $url . '/other/jquery.js"></script> <script type="text/javascript" src="' . $url . '/other/jquery.ui.js"></script>'; $slider .= '<div id="' . $this->name . '_slider" style="width: ' . $this->boxWidth . 'px;"></div> <div id="' . $this->name . '_value">'.$this->default.'</div> <input id="' . $this->name . '" name="' . $this->name . '" type="hidden" value="'.$this->default.'" />'; $slider .= '<script type="text/javascript"> $(document).ready(function() { $("#' . $this->name . '_slider").slider({' . (is_numeric($this->default) ? "value: {$this->default}," : '') . (isset($this->parameters['slider_min']) ? "min: {$this->parameters['slider_min']}," : '') . (isset($this->parameters['slider_max']) ? "max: {$this->parameters['slider_max']}," : '') . (isset($this->parameters['slider_step']) ? "step: {$this->parameters['slider_step']}," : '') . ' slide: function(event, ui) { $("#' . $this->name . '").val(ui.value) $("#' . $this->name . '_value").text(ui.value); } }); }); </script>'; return $slider; } /** * Modifies the default parameters of this Input type based on the authors inputs * If authors input is null, returns the defaults. * * @access public * @param array $param * @return array */ public function getDefaultParam($param=NULL) { if(!empty($param['slider_min'])) { $this->parameters['slider_min']->setSelection($param['slider_min']); } if(!empty($param['slider_max'])) { $this->parameters['slider_max']->setSelection($param['slider_max']); } return $this->parameters; } public static function getOptionsUsed() { return array('teacherAns', 'boxSize', 'studentVerify', 'hideFeedback'); } public static function getOptionDefaults() { return array('boxSize'=>'200', 'studentVerify'=>'false', 'hideFeedback'=>'true'); } } ?> Index: Matrix.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/Matrix.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Matrix.php 9 Feb 2010 10:40:31 -0000 1.11 --- Matrix.php 30 Sep 2010 16:56:13 -0000 1.12 *************** *** 215,219 **** /*echo '<hr>Defaults:<pre>'; var_dump($this->defaults); ! echo '</pre>';*/ } } --- 215,220 ---- /*echo '<hr>Defaults:<pre>'; var_dump($this->defaults); ! echo '</pre>'; ! */ } } *************** *** 320,333 **** } - /** - * Supercedes OLDmodinput_tokenizer() below - */ - /* - private function BROKENmodinput_tokenizer($in) { - $list = new stringUtil($in); - return $list->listToArray(); - } - */ - /** * Takes comma separated list of elements and returns them as an array --- 321,324 ---- *************** *** 414,449 **** public function getTestPostData($value) { - $post_data = array(); ! /* ! $cs = 'matrix_size('.$this->parameters['teacherAns'].')'; ! $matrixSize = new CasString($cs); ! ! $mct = new MultiCasText(array('size' => $matrixSize)); ! $mct->casValidate('t'); ! ! $size = $mct->getRawValues('size'); ! $dimensions = explode(',',$size[$cs]); ! $height = trim($dimensions[0], '[]'); ! $width = trim($dimensions[1], '[]'); ! for($i=0; $i < $height; $i++) { ! for($j=0; $j < $width; $j++) { ! $name = $this->name.'|'.$i.'|'.$j; ! $default = empty($this->defaults) ? '' : $this->defaults[$i][$j]; ! $post_data[$name] = $default; ! } } - */ - - echo "HERE"; - print_r($post_data); ! return $post_data; } ! } ?> \ No newline at end of file --- 405,432 ---- public function getTestPostData($value) { ! $this -> setDefault($value); ! $post_data = array(); ! $height = count($this->defaults); ! if ($height>0) { ! $width = count($this->defaults[1]); ! for($i=0; $i < $height; $i++) { ! for($j=0; $j < $width; $j++) { ! $name = $this->name.'|'.$i.'|'.$j; ! $default = empty($this->defaults) ? '' : $this->defaults[$i][$j]; ! $post_data[$name] = $default; ! } ! } } ! return $post_data; } ! public static function getOptionsUsed() { ! return array('teacherAns', 'informalSyntax', 'insertStars', 'syntaxHint', 'forbid', 'allow', 'floats', 'lowest', 'sameType', 'studentVerify', 'hideFeedback'); ! } } ?> \ No newline at end of file Index: StringIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/StringIT.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** StringIT.php 27 Aug 2009 16:23:00 -0000 1.6 --- StringIT.php 30 Sep 2010 16:56:13 -0000 1.7 *************** *** 113,116 **** --- 113,123 ---- } + public static function getOptionsUsed() { + return array('teacherAns', 'forbid', 'allow', 'floats', 'lowest', 'sameType', 'studentVerify', 'hideFeedback'); + } + + public static function getOptionDefaults() { + return array('boxSize'=>20, 'studentVerify'=>'false', 'hideFeedback'=>'true'); + } } Index: AlgebraIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/AlgebraIT.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** AlgebraIT.php 27 Aug 2009 16:23:00 -0000 1.7 --- AlgebraIT.php 30 Sep 2010 16:56:13 -0000 1.8 *************** *** 117,120 **** --- 117,138 ---- return $box; } + + public static function getOptionsUsed() { + return parent::getOptionsUsed(); + } + + + /** + * Returns the default options. + * Only need to specify where they differ from QuestionPart defaults, so does not contain all used options (see setOptionsUsed()) + * String keys MUST match QuestionPart variable names. + * + * @param array $param + * @access public + * @return Array(String) + */ + public static function getOptionDefaults() { + return array('boxSize'=>'20'); + } } ?> \ No newline at end of file Index: InputTypeController.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/InputTypeController.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** InputTypeController.php 27 Aug 2009 16:23:00 -0000 1.12 --- InputTypeController.php 30 Sep 2010 16:56:13 -0000 1.13 *************** *** 34,37 **** --- 34,38 ---- require_once $root.'/lib/ui/inputTypes/ListIT.php'; require_once $root.'/lib/ui/inputTypes/TextArea.php'; + require_once $root.'/lib/ui/inputTypes/Slider.php'; class InputTypeController *************** *** 44,48 **** * @access private */ ! private $avaliableTypes; /** --- 45,49 ---- * @access private */ ! private $availableTypes; /** *************** *** 110,125 **** $this->answerBox = new TextArea($name, $width, $default, $maxLength, $height, $param); break; } } //set list of avaliable input types, in a format that can be translated ! $this->avaliableTypes['Algebraic Input'] = get_string('stackInputType_Algebraic', 'stack', ''); ! $this->avaliableTypes['True/False'] = get_string('stackInputType_truefalse', 'stack', ''); ! $this->avaliableTypes['Single Character'] = get_string('stackInputType_singlechar', 'stack', ''); ! $this->avaliableTypes['DropDownList'] = get_string('stackInputType_dropdownlist', 'stack', ''); ! $this->avaliableTypes['Matrix'] = get_string('stackInputType_matrix', 'stack', ''); ! $this->avaliableTypes['List'] = get_string('stackInputType_list', 'stack', ''); ! $this->avaliableTypes['Textarea'] = get_string('stackInputType_Textarea', 'stack', ''); // We currently don't allow strings to be passed to the CAS, so remove this type. ! //$this->avaliableTypes['String'] = get_string('stackInputType_String', 'stack', ''); // Currently there are too many bugs with DragMath - so don't offer it! //$this->avaliableTypes['Dragmath with input box'] = get_string('stackInputType_dragmathInputBox', 'stack', ''); --- 111,131 ---- $this->answerBox = new TextArea($name, $width, $default, $maxLength, $height, $param); break; + + case 'Slider': + $this->answerBox = new Slider($name, $width, $default, $maxLength, $height, $param); + break; } } //set list of avaliable input types, in a format that can be translated ! $this->availableTypes['Algebraic Input'] = get_string('stackInputType_Algebraic', 'stack', ''); ! $this->availableTypes['True/False'] = get_string('stackInputType_truefalse', 'stack', ''); ! $this->availableTypes['Single Character'] = get_string('stackInputType_singlechar', 'stack', ''); ! $this->availableTypes['DropDownList'] = get_string('stackInputType_dropdownlist', 'stack', ''); ! $this->availableTypes['Matrix'] = get_string('stackInputType_matrix', 'stack', ''); ! $this->availableTypes['List'] = get_string('stackInputType_list', 'stack', ''); ! $this->availableTypes['Textarea'] = get_string('stackInputType_Textarea', 'stack', ''); ! $this->availableTypes['Slider'] = get_string('stackInputType_slider', 'stack', ''); // We currently don't allow strings to be passed to the CAS, so remove this type. ! //$this->availableTypes['String'] = get_string('stackInputType_String', 'stack', ''); // Currently there are too many bugs with DragMath - so don't offer it! //$this->avaliableTypes['Dragmath with input box'] = get_string('stackInputType_dragmathInputBox', 'stack', ''); *************** *** 166,170 **** //display a drop down list $widget = '<select name="'.$prefix.'">'; ! foreach($this->avaliableTypes as $key => $val) { //if indexed array of values, use val for both display and return --- 172,176 ---- //display a drop down list $widget = '<select name="'.$prefix.'">'; ! foreach($this->availableTypes as $key => $val) { //if indexed array of values, use val for both display and return *************** *** 222,226 **** return $this->answerBox->transform($in); } - } ?> \ No newline at end of file --- 228,280 ---- return $this->answerBox->transform($in); } + public function getTestPostData($in) + { + return $this->answerBox->getTestPostData($in); + } + + /** + * Return array of arrays for each IT to be used by authoring interface. + */ + public static function getOptionsUsed() + { + // HTML option values mapping to array of options to be shown + $used['Algebraic Input'] = AlgebraIT::getOptionsUsed(); + //$used['DragMathAppletOnly'] = DragMathAppletOnly::getOptionsUsed(); + //$used['DragMathInputBox'] = DragMathInputBox::getOptionsUsed(); + $used['Single Character'] = SingleCharIT::getOptionsUsed(); + //$used['StringIT'] = StringIT::getOptionsUsed(); + $used['True/False'] = TrueFalseIT::getOptionsUsed(); + $used['DropDownList'] = DropDownList::getOptionsUsed(); + $used['Matrix'] = Matrix::getOptionsUsed(); + $used['List'] = ListIT::getOptionsUsed(); + $used['Textarea'] = TextArea::getOptionsUsed(); + $used['Slider'] = Slider::getOptionsUsed(); + + foreach($used as $type => $value) { + $used[$type][] = 'inputType'; // obviously required for all + } + + return $used; + } + + /** + * Return array of arrays for each IT to be used by authoring interface. + */ + public static function getOptionDefaults() { + $defaults['Algebraic Input'] = AlgebraIT::getOptionDefaults(); + //$defaults['DragMathAppletOnly'] = DragMathAppletOnly::getOptionDefaults(); + //$defaults['DragMathInputBox'] = DragMathInputBox::getOptionDefaults(); + $defaults['Single Character'] = SingleCharIT::getOptionDefaults(); + //$defaults['StringIT'] = StringIT::getOptionDefaults(); + $defaults['True/False'] = TrueFalseIT::getOptionDefaults(); + $defaults['DropDownList'] = DropDownList::getOptionDefaults(); + $defaults['Matrix'] = Matrix::getOptionDefaults(); + $defaults['List'] = ListIT::getOptionDefaults(); + $defaults['Textarea'] = TextArea::getOptionDefaults(); + $defaults['Slider'] = Slider::getOptionDefaults(); + + return $defaults; + } + } ?> \ No newline at end of file Index: ListIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/ListIT.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ListIT.php 1 Feb 2010 14:27:05 -0000 1.6 --- ListIT.php 30 Sep 2010 16:56:13 -0000 1.7 *************** *** 274,278 **** foreach($randomSet as $id) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display']."<br />\n"; } } else { --- 274,278 ---- foreach($randomSet as $id) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.stripslashes($displayVals[$id]['list_display'])."<br />\n"; } } else { *************** *** 282,290 **** if($this->default == $displayVals[$id]['list_label']) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" checked />'.$displayVals[$id]['list_display']."<br />\n"; } else { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display']."<br />\n"; } } --- 282,290 ---- if($this->default == $displayVals[$id]['list_label']) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" checked />'.stripslashes($displayVals[$id]['list_display'])."<br />\n"; } else { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.stripslashes($displayVals[$id]['list_display'])."<br />\n"; } } *************** *** 402,406 **** foreach ($ans_array as $key=>$val) { ! $post_data[] = array($this->name.'-'.$key=>$val); } } --- 402,406 ---- foreach ($ans_array as $key=>$val) { ! $post_data[$this->name.'-'.$key] = $val; } } *************** *** 447,450 **** --- 447,454 ---- } } + + public static function getOptionsUsed() { + return array('teacherAns', 'studentVerify', 'hideFeedback'); + } } ?> \ No newline at end of file Index: TrueFalseIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/TrueFalseIT.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TrueFalseIT.php 27 Aug 2009 16:23:00 -0000 1.9 --- TrueFalseIT.php 30 Sep 2010 16:56:13 -0000 1.10 *************** *** 124,127 **** --- 124,153 ---- } + + /** + * Returns an array of all options that are relevant to this type (overiding ALL options) + * Used to determine which options to show in authoring, for example. + * String keys MUST match QuestionPart variable names. + * + * @access public + * @return Array(String) + */ + public static function getOptionsUsed() + { + return array('teacherAns', 'studentVerify', 'hideFeedback'); + } + + /** + * Returns the default options. + * Only need to specify where they differ from QuestionPart defaults, so does not contain all used options (see setUsedoptions()) + * String keys MUST match QuestionPart variable names. + * + * @param array $param + * @access public + * @return Array(StackOption) + */ + public static function getOptionDefaults() { + return array('studentVerify'=>'false', 'hideFeedback'=>'true'); + } } |