/**
  * (non-PHPdoc)
  * @see lib/form/data/collection/phDataCollection::validate()
  */
 public function validate(phFormViewElement $element, phNameInfo $name, phCompositeDataCollection $collection)
 {
     /*
      * check uniqueness of name
      */
     if (!$name->hasAutoKey()) {
         $elementsCollection = $element->createDataCollection();
         $ourItem = $this->find($name->getFullName());
         if ($ourItem) {
             // we already have an item registered in this collection with this name
             throw new phFormException("The element with name {$name->getFullName()} is not unique");
         } else {
             if (get_class($elementsCollection) == get_class($this)) {
                 // the item will be stored in this collection - check uniqueness of name
                 $item = $collection->find($name->getFullName());
                 if ($item) {
                     throw new phFormException("The element with name {$name->getFullName()} is not unique");
                 }
             }
         }
     }
     /*
      * make sure we are not mixing arrays and normal types
      */
     $rootItem = $collection->find($name->getName());
     if ($rootItem && $name->isArray() && !$rootItem instanceof phArrayFormDataItem) {
         throw new phFormException("There is already a data item registered at {$name->getFullName()} and it is not an array data type so I cannot add to it!");
     }
 }
 /**
  * (non-PHPdoc)
  * @see lib/form/data/collection/phSimpleDataCollection::validate()
  */
 public function validate(phFormViewElement $element, phNameInfo $name, phCompositeDataCollection $collection)
 {
     if ($name->isArray()) {
         $arrayInfo = $name->getArrayInfo();
         $keys = $arrayInfo->getKeys();
         $lastKey = array_pop($keys);
         if ($lastKey->isAutoKey()) {
             throw new phFormException("The name {$name->getFullName()} is invalid, you cannot use an auto key with a radio button");
         }
     }
     if (!$element instanceof phRadioButtonElement) {
         return;
         // not interested from here on
     }
     if (array_key_exists($name->getFullName(), $this->_radioValues)) {
         if (in_array($element->getRawValue(), $this->_radioValues[$name->getFullName()])) {
             throw new phFormException("Non unique value for radio button with name \"{$name->getFullName()}\"");
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see lib/form/data/collection/phSimpleDataCollection::validate()
  */
 public function validate(phFormViewElement $element, phNameInfo $name, phCompositeDataCollection $collection)
 {
     /*
      * go through the name and, if it's an array, build it back up, BUT - skip
      * the last key if it's an auto key.  We do this because checkboxes with auto 
      * key's cannot be mixed with any other data type.
      */
     $nameString = $name->getName();
     $hasAutoKey = false;
     if ($name->isArray()) {
         $keys = $name->getArrayInfo()->getKeys();
         foreach ($keys as $k) {
             if ($k->isAutoKey()) {
                 $hasAutoKey = true;
                 break;
             }
             $nameString .= "[{$k->getKey()}]";
         }
     }
     $item = $collection->find($nameString);
     if ($hasAutoKey && $item !== null) {
         if (!$element instanceof phCheckboxElement && $item instanceof phSimpleArrayDataItem) {
             // not ok - checkbox registered here previously and someone is trying to add another datatype to the same array
             throw new phFormException("Trying to mix checkboxes with auto keys with another type of element at {$name}");
         }
         if ($element instanceof phCheckboxElement && !$item instanceof phSimpleArrayDataItem) {
             // not ok - checkbox with auto key trying to be registered to a normal array type
             throw new phFormException("Trying to mix checkboxes with auto keys with another type of element at {$name}");
         }
     }
     if (!$element instanceof phCheckboxElement) {
         return;
         // not interested at this point if it's not a checkbox
     }
     /*
      * check unique values
      */
     if (array_key_exists($name->getFullName(), $this->_checkboxValues) && in_array($element->getRawValue(), $this->_checkboxValues[$name->getFullName()])) {
         // value is not unique
         throw new phFormException("Duplicate value for checkbox with name {$name->getFullName()}");
     }
     if (!$name->isArray() && $item !== null) {
         throw new phFormException("Cannot register checkbox with name {$name->getFullName()}, an item of data with the same name already exists.  If you are trying to use multiple checkboxes with the same name then please note that these must have array names e.g. \"ids[]\"");
     }
 }
 /**
  * (non-PHPdoc)
  * @see lib/form/data/collection/phSimpleArrayDataCollection::needsSimpleArrayType()
  */
 public function needsSimpleArrayType(phArrayKeyInfo $info, phFormViewElement $element)
 {
     /*
      * if the select list is a multi select and the key is an auto key then
      * we'll need the simple array type
      */
     return $element instanceof phSelectListElement && $element->isMultiple() && $info->isAutoKey();
 }
 /**
  * Registers an element with this collection
  * 
  * @param phFormViewElement $element
  * @param phNameInfo $name
  */
 public function register(phFormViewElement $element, phNameInfo $name, phCompositeDataCollection $collection)
 {
     $item = new phFormDataItem($name->getName());
     $this->_dataItems[$name->getName()] = $item;
     $element->bindDataItem($item);
 }