You are here

function uc_dropdown_attributes_remove_values in Dropdown Attributes 7

Same name and namespace in other branches
  1. 8 uc_dropdown_attributes.module \uc_dropdown_attributes_remove_values()

Unset values of orphaned children.

Called recursively to remove orphaned values from form_state.

Parameters

int $parent_aid: Attribute ID of the triggering element.

int $parent_value: Option ID of the value of the triggering element.

int $id: Node ID or product class ID.

string $type: 'node' or 'class'.

array $form_values: Part of the form_state array containing the attributes.

7 calls to uc_dropdown_attributes_remove_values()
_uc_dropdown_attributes_class_build in ./uc_dropdown_attributes.module
Form build for classes.
_uc_dropdown_attributes_kit_build in ./uc_dropdown_attributes.module
Form build for product kits.
_uc_dropdown_attributes_order_class_build in ./uc_dropdown_attributes.module
Form build for classes for the order page.
_uc_dropdown_attributes_order_class_kit_build in ./uc_dropdown_attributes.module
Form build for classes in product kits for the order page.
_uc_dropdown_attributes_order_product_build in ./uc_dropdown_attributes.module
Form build for products for the order page.

... See full list

File

./uc_dropdown_attributes.module, line 494
Show/hide attributes based on the values of other attributes.

Code

function uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $id, $type, &$form_values) {
  switch ($type) {
    case 'node':
      $sql = 'SELECT aid, required, parent_values FROM {uc_dropdown_attributes}
        WHERE nid=:nid AND parent_aid=:parent_aid';
      $children = db_query($sql, array(
        ':nid' => $id,
        ':parent_aid' => $parent_aid,
      ));
      break;
    case 'class':
      $sql = 'SELECT aid, required, parent_values FROM {uc_dropdown_classes}
        WHERE pcid=:pcid AND parent_aid=:parent_aid';
      $children = db_query($sql, array(
        ':pcid' => $id,
        ':parent_aid' => $parent_aid,
      ));
      break;
    default:
      $children = array();
      break;
  }
  foreach ($children as $child) {
    if ($child->required) {
      $value = $form_values['attributes'][$child->aid];
      $form_values['attributes'][$child->aid] = '';
      if ($value) {
        $values = unserialize($child->parent_values);
        if (!array_key_exists($parent_value, $values)) {
          uc_dropdown_attributes_remove_values($child->aid, $value, $id, $type, $form_values);
        }
      }
    }
  }
}