From: Ben H. <bdv...@us...> - 2010-11-22 23:06:28
|
Update of /cvsroot/stack/stack-dev/lib/ui/inputTypes In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv29766/lib/ui/inputTypes Modified Files: Tag: question_reporting TextArea.php TrueFalseIT.php DropDownList.php StringIT.php AlgebraIT.php CreatingNewInteractionElements.txt ListIT.php Matrix.php SingleCharIT.php InputTypeController.php AnswerInputType.php Added Files: Tag: question_reporting Slider.php Log Message: Merging from the current HEAD into question_reporting. Apologies in advance if this all goes horribly wrong. Index: SingleCharIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/SingleCharIT.php,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -C2 -d -r1.5 -r1.5.2.1 *** SingleCharIT.php 27 Aug 2009 16:23:00 -0000 1.5 --- SingleCharIT.php 22 Nov 2010 23:05:49 -0000 1.5.2.1 *************** *** 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.10 retrieving revision 1.10.2.1 diff -C2 -d -r1.10 -r1.10.2.1 *** AnswerInputType.php 27 Aug 2009 16:23:00 -0000 1.10 --- AnswerInputType.php 22 Nov 2010 23:05:49 -0000 1.10.2.1 *************** *** 137,141 **** /** ! * Transforms the students input into a casstring if needed. From most returns same as went in. * * @param array|string $in --- 137,141 ---- /** ! * Transforms the student's input into a casstring if needed. From most returns same as went in. * * @param array|string $in *************** *** 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.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** DropDownList.php 27 Aug 2009 16:23:00 -0000 1.6 --- DropDownList.php 22 Nov 2010 23:05:49 -0000 1.6.2.1 *************** *** 118,124 **** else { ! $values = $this->parameters['ddl_values']->getSelection(); ! $values = trim($values); ! $exploded = explode(',', $values); if(!empty($values)) --- 118,125 ---- else { ! $values = $this->parameters['ddl_values']->getSelection(); ! $values = trim($values); ! $su = new stringUtil('['.$values.']'); ! $exploded = $su->listToArray(false); if(!empty($values)) *************** *** 156,160 **** } ! } ?> \ 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.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** TextArea.php 27 Aug 2009 16:23:00 -0000 1.2 --- TextArea.php 22 Nov 2010 23:05:49 -0000 1.2.2.1 *************** *** 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.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** Matrix.php 27 Aug 2009 16:23:00 -0000 1.6 --- Matrix.php 22 Nov 2010 23:05:49 -0000 1.6.2.1 *************** *** 20,24 **** require_once 'AnswerInputType.php'; require_once('AnswerInputTypeInterface.php'); ! //require_once($root.'/lib/items/Meta.php'); /** * Generates a grid for input of Matricies. --- 20,24 ---- require_once 'AnswerInputType.php'; require_once('AnswerInputTypeInterface.php'); ! require_once($root.'/lib/stringUtil.php'); /** * Generates a grid for input of Matricies. *************** *** 157,163 **** for($j=0; $j < $width; $j++) { ! $name = $this->name.'-'.$i.'-'.$j; $default = empty($this->defaults) ? '' : $this->defaults[$i][$j]; ! $xhtml .= '<td><input type="text" name="'.$name.'" value="'.$default.'" size="'.$this->boxWidth.'" onfocus="this.value=\'\'" ></td>'; } if($i == 0) --- 157,163 ---- for($j=0; $j < $width; $j++) { ! $name = $this->name.'|'.$i.'|'.$j; $default = empty($this->defaults) ? '' : $this->defaults[$i][$j]; ! $xhtml .= '<td><input type="text" name="'.$name.'" value="'.$default.'" size="'.$this->boxWidth.'" ></td>'; } if($i == 0) *************** *** 215,219 **** /*echo '<hr>Defaults:<pre>'; var_dump($this->defaults); ! echo '</pre>';*/ } } --- 215,220 ---- /*echo '<hr>Defaults:<pre>'; var_dump($this->defaults); ! echo '</pre>'; ! */ } } *************** *** 404,433 **** 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; ! } } ! 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.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** StringIT.php 27 Aug 2009 16:23:00 -0000 1.6 --- StringIT.php 22 Nov 2010 23:05:49 -0000 1.6.2.1 *************** *** 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.7.2.1 diff -C2 -d -r1.7 -r1.7.2.1 *** AlgebraIT.php 27 Aug 2009 16:23:00 -0000 1.7 --- AlgebraIT.php 22 Nov 2010 23:05:49 -0000 1.7.2.1 *************** *** 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.12.2.1 diff -C2 -d -r1.12 -r1.12.2.1 *** InputTypeController.php 27 Aug 2009 16:23:00 -0000 1.12 --- InputTypeController.php 22 Nov 2010 23:05:49 -0000 1.12.2.1 *************** *** 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.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** ListIT.php 27 Aug 2009 16:23:00 -0000 1.4 --- ListIT.php 22 Nov 2010 23:05:49 -0000 1.4.2.1 *************** *** 22,25 **** --- 22,26 ---- require_once($root.'/lib/items/QTTuple.php'); require_once($root.'/lib/items/QTList.php'); + require_once($root.'/lib/stringUtil.php'); /** * A general input type for producing lists of answers for the student to pick from. *************** *** 97,101 **** if($param == NULL) { ! $param['list_input_type'] = new Meta('optional', 'radio', array('radio' => 'radio buttons', 'dropdown'=>'drop down list' )); for($i=3; $i > 0; $i--) --- 98,102 ---- if($param == NULL) { ! $param['list_input_type'] = new Meta('optional', 'radio', array('radio' => 'radio buttons', 'dropdown'=>'drop down list', 'checkbox'=>'check boxes')); for($i=3; $i > 0; $i--) *************** *** 229,241 **** $result = $this->parameters['list_values']->purgeEmpty(); $no = $this->parameters['list_no_display']->getSelection(); $range = $this->parameters['list_values']->size(); - $range = $range -1; //range should start at 0, not 1 - $no--; //adding in the teachers answer, so need one fewer ! $randomSet = $this->randomSelection($this->parameters['seed'], $no, ($range)); //insert the teacher's answer into a random position - srand($this->parameters['seed']); $tPos = rand(0, $no); --- 230,243 ---- $result = $this->parameters['list_values']->purgeEmpty(); + // The number of distractors the teacher wants to show. $no = $this->parameters['list_no_display']->getSelection(); + $no--; //adding in the teachers answer, so need one fewer from the selection + // The number of distractors entered by the teacher. $range = $this->parameters['list_values']->size(); ! // Generate random positions for the distractors ! $randomSet = $this->randomSelection($this->parameters['seed'], $no, $range); //insert the teacher's answer into a random position srand($this->parameters['seed']); $tPos = rand(0, $no); *************** *** 244,248 **** $result = $this->parameters['list_values']->CASProcess('t'); ! $teachers = $this->parameters['list_correct_ans']->casProcess('t'); if($result !== true) --- 246,259 ---- $result = $this->parameters['list_values']->CASProcess('t'); ! $teachers = $this->parameters['list_correct_ans']->CASProcess('t'); ! ! /* Remove random positioning - useful for testing */ ! /* ! $randomSet=array(); ! for($i=$no-1; $i >= -1; $i--) ! { ! $randomSet[$i]=$i; ! } ! */ if($result !== true) *************** *** 255,283 **** $displayVals[-1] = $this->parameters['list_correct_ans']->getDisplayValue(); if($this->parameters['list_input_type']->getSelection() == 'radio') { if(($this->default == NULL)) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="" checked />'.$ns_s.'<br />'; foreach($randomSet as $id) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display'].'<br />'; } } else { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="" />'.$ns_s.'<br />'; foreach($randomSet as $id) { 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 />'; } else { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display'].'<br />'; } } } } ! else { $xhtml .= '<select name="'.$this->name.'">'; --- 266,295 ---- $displayVals[-1] = $this->parameters['list_correct_ans']->getDisplayValue(); + $xhtml .= "\n"; if($this->parameters['list_input_type']->getSelection() == 'radio') { if(($this->default == NULL)) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="" checked />'.$ns_s."<br />\n"; foreach($randomSet as $id) { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="'.$displayVals[$id]['list_label'].'" />'.stripslashes($displayVals[$id]['list_display'])."<br />\n"; } } else { ! $xhtml .= '<input type="radio" name="'.$this->name.'" value="" />'.$ns_s."<br />\n"; foreach($randomSet as $id) { 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"; } } } } ! else if($this->parameters['list_input_type']->getSelection() == 'dropdown') { $xhtml .= '<select name="'.$this->name.'">'; *************** *** 305,308 **** --- 317,355 ---- $xhtml .= '</select>'; } + else if($this->parameters['list_input_type']->getSelection() == 'checkbox') + { + $i=0; + + // Split up a list into an array, so we can tick checkboxes. + $ans = trim($this->default); + if (NULL!== $ans and ''!==trim(ans)) { + $su = new stringUtil($ans); + $ans_array = $su->listToArray(false); + } + + if(($this->default == NULL)) + { + // Don't need "not selected" in checkbox type. + //$xhtml .= '<input type="checkbox" name="'.$this->name.'|'.$i++.'" value="" checked />'.$ns_s."<br />\n"; + foreach($randomSet as $id) + { + $xhtml .= '<input type="checkbox" name="'.$this->name.'|'.$i++.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display']."<br />\n"; + } + } else { + // Don't need "not selected" in checkbox type. + //$xhtml .= '<input type="checkbox" name="'.$this->name.'|'.$i++.'" value="" />'.$ns_s."<br />\n"; + foreach($randomSet as $id) + { + if(in_array($displayVals[$id]['list_label'],$ans_array)) + { + $xhtml .= '<input type="checkbox" name="'.$this->name.'|'.$i++.'" value="'.$displayVals[$id]['list_label'].'" checked />'.$displayVals[$id]['list_display']."<br />\n"; + } + else + { + $xhtml .= '<input type="checkbox" name="'.$this->name.'|'.$i++.'" value="'.$displayVals[$id]['list_label'].'" />'.$displayVals[$id]['list_display']."<br />\n"; + } + } + } + } } } *************** *** 310,315 **** } /** ! * Produces a psuedo random set of numbers the seed. Each number will be in the set only once. * Returns NULL if requested set size > max range * --- 357,416 ---- } + + /** + * Converts the array of inputs passed in into a maxima matrix string + * + * @param string|array $in + * @return string + * @access public + */ + public function transform($in) + { + + // Only checkboxes will send in an array. These need to be turned into a list. + if (is_array($in)) { + $out = ''; + foreach($in as $ans) { + $out .= ','.$ans; + } + $in = '['.substr($out,1).']'; + } + + return $in; + } + + /** + * 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) + { + + if($this->parameters['list_input_type']->getSelection() == 'radio') { + $post_data= array($this->name=>$value); + } else if($this->parameters['list_input_type']->getSelection() == 'dropdown') { + $post_data = array($this->name=>$value); + } else if($this->parameters['list_input_type']->getSelection() == 'checkbox') { + + $su = new stringUtil($value); + $ans_array = $su->listToArray(false); + + $post_data = array(); + foreach ($ans_array as $key=>$val) + { + $post_data[$this->name.'-'.$key] = $val; + } + } + + return $post_data; + } + + /** ! * Produces a psuedo random set of numbers from the seed. ! * Each number will be in the set only once. * Returns NULL if requested set size > max range * *************** *** 328,331 **** --- 429,434 ---- else { + // Range should start at zero, so subtract one. + $range--; srand($seed); $return = array(); *************** *** 344,347 **** --- 447,454 ---- } } + + public static function getOptionsUsed() { + return array('teacherAns', 'studentVerify', 'hideFeedback'); + } } ?> \ No newline at end of file Index: CreatingNewInteractionElements.txt =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/CreatingNewInteractionElements.txt,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -C2 -d -r1.1 -r1.1.4.1 *** CreatingNewInteractionElements.txt 2 Jul 2009 10:46:41 -0000 1.1 --- CreatingNewInteractionElements.txt 22 Nov 2010 23:05:49 -0000 1.1.4.1 *************** *** 8,9 **** --- 8,12 ---- If a new interaction element fails to work through Moodle, look here. + + Where an interaction element needs to create more than one form + element, look at the Matrix type. Index: TrueFalseIT.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/inputTypes/TrueFalseIT.php,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -C2 -d -r1.9 -r1.9.2.1 *** TrueFalseIT.php 27 Aug 2009 16:23:00 -0000 1.9 --- TrueFalseIT.php 22 Nov 2010 23:05:49 -0000 1.9.2.1 *************** *** 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'); + } } |