From: Simon H. <sim...@us...> - 2010-11-26 19:04:50
|
Update of /cvsroot/stack/stack-dev/lib/items In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv32484/lib/items Modified Files: Tag: item_state_separation ItemOption.php Log Message: Index: ItemOption.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/items/ItemOption.php,v retrieving revision 1.19.8.1 retrieving revision 1.19.8.2 diff -C2 -d -r1.19.8.1 -r1.19.8.2 *** ItemOption.php 9 Nov 2010 16:51:37 -0000 1.19.8.1 --- ItemOption.php 26 Nov 2010 19:04:42 -0000 1.19.8.2 *************** *** 36,45 **** // Attributes /** ! * List of stackOptions in format name => stackOption * * @var array(stackOption) * @access private */ ! private $options; /** --- 36,53 ---- // Attributes /** ! * List of default stackOptions in format name => stackOption * * @var array(stackOption) * @access private */ ! static private $options; // the defaults ! ! /** ! * Selected values for stackOptions in format name => stackOption ! * ! * @var array(name=>value) ! * @access private ! */ ! private $selected; // the selected values - SPH /** *************** *** 49,53 **** * @access private */ ! private $errorLog; // Associations --- 57,61 ---- * @access private */ ! private static $errorLog; // Associations *************** *** 70,74 **** global $config; ! $this->errorLog = new error(); //Setup the default values/options --- 78,82 ---- global $config; ! ItemOption::errorLog = new error(); //Setup the default values/options *************** *** 77,81 **** $this->addOption('MultiplicationSign','list','dot',array('(none)' => get_string('stackOption_none', 'stack', ''),'dot'=> get_string('stackOption_dot', 'stack', ''),'cross'=> get_string('stackOption_cross', 'stack', '')),'make_multsgn','fun'); $this->addOption('ComplexNo','list','i',array('i','j','symi','symj'),'make_complexJ','fun'); ! $this->addOption('Floats','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'OPT_NoFloats','ex'); $this->addOption('SqrtSign','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'sqrtdispflag','ex'); $this->addOption('Simplify','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'simp','ex'); --- 85,89 ---- $this->addOption('MultiplicationSign','list','dot',array('(none)' => get_string('stackOption_none', 'stack', ''),'dot'=> get_string('stackOption_dot', 'stack', ''),'cross'=> get_string('stackOption_cross', 'stack', '')),'make_multsgn','fun'); $this->addOption('ComplexNo','list','i',array('i','j','symi','symj'),'make_complexJ','fun'); ! $this->addOption('Floats','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'OPT_NoFloats','ex'); $this->addOption('SqrtSign','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'sqrtdispflag','ex'); $this->addOption('Simplify','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'simp','ex'); *************** *** 98,111 **** $this->addOption('FeedbackGenericPCorrect','html',get_string('stackOptions_FeedBackGenericPCorrect_def','stack',''),''); $this->addOption('OptWorkedSol','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'',''); - } public function __clone() { ! if(!empty($this->options)) { ! foreach($this->options as $label => $opt) { ! $this->options[$label] = clone $opt; } } --- 106,120 ---- $this->addOption('FeedbackGenericPCorrect','html',get_string('stackOptions_FeedBackGenericPCorrect_def','stack',''),''); $this->addOption('OptWorkedSol','list','true',array('true' => get_string('stack_True','stack',''),'false' => get_string('stack_False', 'stack','')),'',''); } public function __clone() { ! if(!empty(ItemOption::options)) { ! ! // do we need this any more with static defaults? ! /*foreach($this->options as $label => $opt) { ! $this->selected[$label] = $opt; } } *************** *** 154,163 **** if ($valid) { ! $this->options[$name] = $tmp; } else { ! $this->errorLog->addError("Attempted to insert invalid stackOption: $name ".$tmp->getErrors()); ! $this->errorLog->addUserError('itemOptions', get_string('stackOptions_invalidOption','stack','').$name.': '.$tmp->getErrors()); } return $valid; --- 163,173 ---- if ($valid) { ! ItemOption::options[$name] = $tmp; // new option for ItemOption ! $this->selected[$name] = $value; // and value set for the instance } else { ! ItemOption::errorLog->addError("Attempted to insert invalid stackOption: $name ".$tmp->getErrors()); ! ItemOption::errorLog->addUserError('itemOptions', get_string('stackOptions_invalidOption','stack','').$name.': '.$tmp->getErrors()); } return $valid; *************** *** 178,182 **** if($valid) { ! $this->options[$name] = $option; } else --- 188,193 ---- if($valid) { ! ItemOption::options[$name] = $option; ! $this->selected[$name] = $option->getSelection(); } else *************** *** 341,345 **** if (array_key_exists($name, $this->options)) { ! return $this->options[$name]->getSelected(); } else --- 352,359 ---- if (array_key_exists($name, $this->options)) { ! if(array_key_exists($name, $this->selected)) { ! return $this->selected[$name]; ! } ! else return $this->options[$name]->getSelected(); // default } else *************** *** 358,366 **** * @return bool */ ! public function setSelected($name, $selected) { ! if(array_key_exists($name, $this->options)) { ! $this->options[$name]->setSelected($selected); return true; } --- 372,380 ---- * @return bool */ ! public function setSelected($name, $value) { ! if(array_key_exists($name, $this->selected)) // we have the option { ! $this->selected[$name] = $value; return true; } *************** *** 397,401 **** if(array_key_exists($name, $this->options)) { ! return $this->options[$name]->editWidget($name, $size); } else --- 411,418 ---- if(array_key_exists($name, $this->options)) { ! // rather kludgy way of setting Option up with correct selection ! $option = clone $this->options[$name]; ! $option->setSelected($this->selected[$name]); ! return $options->editWidget($name, $size); } else *************** *** 444,451 **** if(array_key_exists($optName, $this->options)) { ! $selected = $src->options[$optName]->getSelected(); // copy value over, involves checks. $this->options[$optName]->setSelected($src->options[$optName]->getSelected()); } else { --- 461,469 ---- if(array_key_exists($optName, $this->options)) { ! $selection = $src->selection[$optName]; // copy value over, involves checks. $this->options[$optName]->setSelected($src->options[$optName]->getSelected()); + $this->selected[$optName] = $selection; } else { *************** *** 461,465 **** { foreach($this->options as $optName => $option) { ! if($other->options[$optName]->getSelected() != $option->getSelected()) return false; } } --- 479,484 ---- { foreach($this->options as $optName => $option) { ! //if($other->options[$optName]->getSelected() != $option->getSelected()) return false; ! if($other->getSelected() != $this->option->getSelected()) } } |