protected function add_used($element) {
        $newused = array();
        // Iterate over all the element useds, filling $newused and
        // observing the multiple setting
        foreach ($element->get_used() as $used) {
            if (!in_array($used, $this->get_used())) { // it's a new one, add to $newused array
                $newused[] = $used;
                $this->set_used(array_merge($this->get_used(), array($used))); // add to the optigroup used array
            } else { // it's an existing one, exception on multiple optigroups
                if ($this->multiple) {
                    throw new base_optigroup_exception('multiple_optigroup_duplicate_element', $used);
                }
            }
        }
        // Finally, inform about newused to the next grand(parent/optigroupelement)
        if ($newused && $this->get_parent()) {
            $element->set_used($newused); // Only about the newused
            $grandparent = $this->get_grandoptigroupelement_or_grandparent();
            $grandparent->check_and_set_used($element);
        }
    }
protected function add_used($element) {
        $newused = array();
        // Iterate over all the element useds, filling $newused and
        // observing the multiple setting
        foreach ($element->get_used() as $used) {
            if (!in_array($used, $this->get_used())) { // it's a new one, add to $newused array
                $newused[] = $used;
                $this->set_used(array_merge($this->get_used(), array($used))); // add to the optigroup used array
            } else { // it's an existing one, exception on multiple optigroups
                if ($this->multiple) {
                    throw new base_optigroup_exception('multiple_optigroup_duplicate_element', $used);
                }
            }
        }
        // Finally, inform about newused to the next grand(parent/optigroupelement)
        if ($newused && $this->get_parent()) {
            $element->set_used($newused); // Only about the newused
            $grandparent = $this->get_grandoptigroupelement_or_grandparent();
            $grandparent->check_and_set_used($element);
        }
    }
protected function add_used ( $ element ) { $ newused = array ( ) ; // Iterate over all the element useds, filling $newused and // observing the multiple setting foreach ( $ element -> get_used ( ) as $ used ) { if ( ! in_array ( $ used , $ this -> get_used ( ) ) ) { // it's a new one, add to $newused array $ newused [ ] = $ used ; $ this -> set_used ( array_merge ( $ this -> get_used ( ) , array ( $ used ) ) ) ; // add to the optigroup used array } else { // it's an existing one, exception on multiple optigroups if ( $ this -> multiple ) { throw new base_optigroup_exception ( 'multiple_optigroup_duplicate_element' , $ used ) ; } } } // Finally, inform about newused to the next grand(parent/optigroupelement) if ( $ newused && $ this -> get_parent ( ) ) { $ element -> set_used ( $ newused ) ; // Only about the newused $ grandparent = $ this -> get_grandoptigroupelement_or_grandparent ( ) ; $ grandparent -> check_and_set_used ( $ element ) ; } }
Recalculate all the used elements in the optigroup, observing
restrictions and passing the new used to outer level
Recalculate all the used elements in the optigroup observing restrictions and passing the new used to outer level