You are here

function uc_dropdown_attributes_dependency in Dropdown Attributes 6

Same name and namespace in other branches
  1. 7 uc_dropdown_attributes.module \uc_dropdown_attributes_dependency()

Retrieves the attribute dependencies.

1 string reference to 'uc_dropdown_attributes_dependency'
uc_dropdown_attributes_menu in ./uc_dropdown_attributes.module
Implement hook_menu().

File

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

Code

function uc_dropdown_attributes_dependency($nid, $aid) {
  $result = new stdClass();
  $type = uc_dropdown_attributes_dependency_type($nid);
  if (is_null($type)) {
    $result->status = FALSE;
    drupal_json($result);
    return;
  }
  switch ($type) {
    case 'node':
      $query = 'SELECT parent_aid, parent_values, required
        FROM {uc_dropdown_attributes} WHERE nid=%d && aid=%d';
      $item = db_fetch_object(db_query($query, $nid, $aid));
      break;
    case 'class':
      $pcid = uc_dropdown_attributes_get_type($nid);
      $query = 'SELECT parent_aid, parent_values, required
        FROM {uc_dropdown_classes} WHERE pcid=%d && aid=%d';
      $item = db_fetch_object(db_query($query, $pcid, $aid));
      break;
  }
  if (!$item) {
    $result->status = FALSE;
    drupal_json($result);
  }
  else {
    $result->status = TRUE;
    $result->aid = $aid;
    $result->parent_aid = $item->parent_aid;
    $result->parent_values = unserialize($item->parent_values);
    $result->required = $item->required;
    drupal_json($result);
  }
}