You are here

function uc_dropdown_attributes_dependency in Dropdown Attributes 7

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

Retrieves the attribute dependencies.

Callback to supply attribute dependencies to Javascript.

Parameters

int $nid: Node ID.

string $id: String containing attribute ID.

Return value

object JSON structure.

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

File

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

Code

function uc_dropdown_attributes_dependency($nid, $id, $parent_id) {
  $temp = explode('-', $id);
  if ($temp[1] == 'attributes') {
    $aid = $temp[2];
  }
  else {
    $aid = $temp[4];
  }
  $result = new stdClass();
  $query = 'SELECT parent_values, required
    FROM {uc_dropdown_attributes} WHERE nid=:nid && aid=:aid';
  $db_result = db_query($query, array(
    ':nid' => $nid,
    ':aid' => $aid,
  ));
  foreach ($db_result as $item) {
    $result->status = TRUE;
    $result->nid = $nid;
    $result->id = $id;
    $result->parent_id = $parent_id;
    $result->parent_values = unserialize($item->parent_values);
    $result->required = $item->required;
    drupal_json_output($result);
    return;
  }
  $pcid = uc_dropdown_attributes_get_type($nid);
  $query = 'SELECT parent_values, required
    FROM {uc_dropdown_classes} WHERE pcid=:pcid && aid=:aid';
  $db_result = db_query($query, array(
    ':pcid' => $pcid,
    ':aid' => $aid,
  ));
  foreach ($db_result as $item) {
    $result->status = TRUE;
    $result->nid = $nid;
    $result->id = $id;
    $result->parent_id = $parent_id;
    $result->parent_values = unserialize($item->parent_values);
    $result->required = $item->required;
    drupal_json_output($result);
    return;
  }
  $result->status = FALSE;
  drupal_json_output($result);
}