From: Simon H. <sim...@us...> - 2010-11-28 16:15:53
|
Update of /cvsroot/stack/stack-dev/lib/items In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv31317/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.2 retrieving revision 1.19.8.3 diff -C2 -d -r1.19.8.2 -r1.19.8.3 *** ItemOption.php 26 Nov 2010 19:04:42 -0000 1.19.8.2 --- ItemOption.php 28 Nov 2010 16:15:45 -0000 1.19.8.3 *************** *** 78,82 **** global $config; ! ItemOption::errorLog = new error(); //Setup the default values/options --- 78,82 ---- global $config; ! self::$errorLog = new error(); //Setup the default values/options *************** *** 110,122 **** 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; ! } ! } } --- 110,114 ---- public function __clone() { ! // obsolete? } *************** *** 131,135 **** { $valid = true; ! foreach($this->options as $name => $option) { $tmp = $option->validate(); --- 123,127 ---- { $valid = true; ! foreach(self::$options as $name => $option) { $tmp = $option->validate(); *************** *** 137,142 **** { $valid = false; ! $this->errorLog->addError("$name invalid: $option->getErrors"); ! $this->errorLog->addUserError('itemOptions', $name.' '.get_string('','stack','').' '.$option->getError); } } --- 129,134 ---- { $valid = false; ! self::$errorLog->addError("$name invalid: $option->getErrors"); ! self::$errorLog->addUserError('itemOptions', $name.' '.get_string('','stack','').' '.$option->getError); } } *************** *** 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; --- 155,165 ---- if ($valid) { ! self::$options[$name] = $tmp; // new option for ItemOption $this->selected[$name] = $value; // and value set for the instance } else { ! self::$errorLog->addError("Attempted to insert invalid stackOption: $name ".$tmp->getErrors()); ! self::$errorLog->addUserError('itemOptions', get_string('stackOptions_invalidOption','stack','').$name.': '.$tmp->getErrors()); } return $valid; *************** *** 188,198 **** if($valid) { ! ItemOption::options[$name] = $option; $this->selected[$name] = $option->getSelection(); } else { ! $this->errorLog->addError("Attempted to insert invalid stackOption: $option->getErrors"); ! $this->errorLog->addUserError('itemOptions', get_string('stackOptions_invalidOption','stack','').$tmp->getErrors()); } return $valid; --- 180,190 ---- if($valid) { ! self::$options[$name] = $option; $this->selected[$name] = $option->getSelection(); } else { ! self::$errorLog->addError("Attempted to insert invalid stackOption: $option->getErrors"); ! self::$errorLog->addUserError('itemOptions', get_string('stackOptions_invalidOption','stack','').$tmp->getErrors()); } return $valid; *************** *** 208,218 **** public function getOption($name) { ! if (array_key_exists($name, $this->options)) { ! return $this->options[$name]; } else { ! $this->errorLog->addError('Attempted to retrieve option '.$name.' which does not exist.'); return NULL; } --- 200,210 ---- public function getOption($name) { ! if (array_key_exists($name, self::$options)) { ! return self::$options[$name]; } else { ! self::$errorLog->addError('Attempted to retrieve option '.$name.' which does not exist.'); return NULL; } *************** *** 228,239 **** public function getDefault($name) { ! if (array_key_exists($name, $this->options)) { ! $default = $this->options[$name]->getDefault(); return $default; } else { ! $this->errorLog->addError('Attempted to retrieve default for '.$name.' which does not exist.'); return NULL; } --- 220,231 ---- public function getDefault($name) { ! if (array_key_exists($name, self::$options)) { ! $default = self::$options[$name]->getDefault(); return $default; } else { ! self::$errorLog->addError('Attempted to retrieve default for '.$name.' which does not exist.'); return NULL; } *************** *** 249,259 **** public function getType($name) { ! if (array_key_exists($name, $this->options)) { ! return $this->options[$name]->getType(); } else { ! $this->errorLog->addError('Attempted to retrieve type of '.$name.' which does not exist.'); return NULL; } --- 241,251 ---- public function getType($name) { ! if (array_key_exists($name, self::$options)) { ! return self::$options[$name]->getType(); } else { ! self::$errorLog->addError('Attempted to retrieve type of '.$name.' which does not exist.'); return NULL; } *************** *** 269,279 **** public function getValues($name) { ! if (array_key_exists($name, $this->options)) { ! return $this->options[$name]->getValues(); } else { ! $this->errorLog->addError('Attempted to retrieve value of '.$name.' which does not exist.'); return NULL; } --- 261,271 ---- public function getValues($name) { ! if (array_key_exists($name, self::$options)) { ! return self::$options[$name]->getValues(); } else { ! self::$errorLog->addError('Attempted to retrieve value of '.$name.' which does not exist.'); return NULL; } *************** *** 289,299 **** public function getCasKey($name) { ! if (array_key_exists($name, $this->options)) { ! return $this->options[$name]->getCasKey(); } else { ! $this->errorLog->addError('Attempted to retrieve caskey of '.$name.' which does not exist.'); return NULL; } --- 281,291 ---- public function getCasKey($name) { ! if (array_key_exists($name, self::$options)) { ! return self::$options[$name]->getCasKey(); } else { ! self::$errorLog->addError('Attempted to retrieve caskey of '.$name.' which does not exist.'); return NULL; } *************** *** 310,320 **** public function getCasType($name) { ! if (array_key_exists($name, $this->options)) { ! return $this->options[$name]->getCasType(); } else { ! $this->errorLog->addError('Attempted to retrieve castype of '.$name.' which does not exist.'); return NULL; } --- 302,312 ---- public function getCasType($name) { ! if (array_key_exists($name, self::$options)) { ! return self::$options[$name]->getCasType(); } else { ! self::$errorLog->addError('Attempted to retrieve castype of '.$name.' which does not exist.'); return NULL; } *************** *** 330,334 **** { $returnArray; ! foreach($this->options as $name => $option) { --- 322,326 ---- { $returnArray; ! foreach(self::$options as $name => $option) { *************** *** 350,363 **** public function getSelected($name) { ! 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 { ! $this->errorLog->addError('Attempted to retrieve selected of '.$name.' which does not exist.'); return NULL; } --- 342,355 ---- public function getSelected($name) { ! if (array_key_exists($name, self::$options)) { if(array_key_exists($name, $this->selected)) { return $this->selected[$name]; } ! else return self::$options[$name]->getSelected(); // default } else { ! self::$errorLog->addError('Attempted to retrieve selected of '.$name.' which does not exist.'); return NULL; } *************** *** 381,385 **** else { ! $this->errorLog->addError('Attempted to set selected of '.$name.' which does not exist.'); return false; } --- 373,377 ---- else { ! self::$errorLog->addError('Attempted to set selected of '.$name.' which does not exist.'); return false; } *************** *** 392,401 **** public function getErrors() { ! return $this->errorLog->displayErrors(); } public function getErrorLog() { ! return $this->errorLog; } --- 384,393 ---- public function getErrors() { ! return self::$errorLog->displayErrors(); } public function getErrorLog() { ! return self::$errorLog; } *************** *** 412,416 **** { // 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); --- 404,408 ---- { // rather kludgy way of setting Option up with correct selection ! $option = clone self::$options[$name]; $option->setSelected($this->selected[$name]); return $options->editWidget($name, $size); *************** *** 425,429 **** public function getUserErrors() { ! return $this->errorLog->getUserErrors(); } --- 417,421 ---- public function getUserErrors() { ! return self::$errorLog->getUserErrors(); } *************** *** 438,444 **** { $node = $dom->createElement($name); ! if(!empty($this->options)) { ! foreach($this->options as $optName => $option) { $optNode = $option->toXML($dom, $optName); --- 430,436 ---- { $node = $dom->createElement($name); ! if(!empty(self::$options)) { ! foreach(self::$options as $optName => $option) { $optNode = $option->toXML($dom, $optName); *************** *** 464,472 **** // copy value over, involves checks. ! $this->options[$optName]->setSelected($src->options[$optName]->getSelected()); $this->selected[$optName] = $selection; } else { ! $this->errorLog->addError('Attempted to copy selection of '.$optName.' which does not exist in current item.'); } } --- 456,464 ---- // copy value over, involves checks. ! self::$options[$optName]->setSelected($src->options[$optName]->getSelected()); $this->selected[$optName] = $selection; } else { ! self::$errorLog->addError('Attempted to copy selection of '.$optName.' which does not exist in current item.'); } } *************** *** 475,484 **** public function equals($other) { ! if(empty($this->options) != empty($other->options)) return false; ! if(!empty($this->options)) { ! foreach($this->options as $optName => $option) { //if($other->options[$optName]->getSelected() != $option->getSelected()) return false; ! if($other->getSelected() != $this->option->getSelected()) } } --- 467,477 ---- public function equals($other) { ! if(empty($this->selected) != empty($other->selected)) return false; ! if(!empty($this->selected)) { ! foreach($this->selected as $key => $value) { //if($other->options[$optName]->getSelected() != $option->getSelected()) return false; ! //if($other->getSelected() != $this->option->getSelected()); ! if($other->selected[$key] != $this->selected[$key]) return false; } } |