You are here

function uc_attribute_admin in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_attribute/uc_attribute.module \uc_attribute_admin()
  2. 6.2 uc_attribute/uc_attribute.admin.inc \uc_attribute_admin()

Displays a paged list and overview of existing product attributes.

1 string reference to 'uc_attribute_admin'
uc_attribute_menu in uc_attribute/uc_attribute.module
Implements hook_menu().

File

uc_attribute/uc_attribute.admin.inc, line 11
Attribute administration menu items.

Code

function uc_attribute_admin() {
  $header = array(
    array(
      'data' => t('Name'),
      'field' => 'a.name',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Label'),
      'field' => 'a.label',
    ),
    t('Required'),
    array(
      'data' => t('List position'),
      'field' => 'a.ordering',
    ),
    t('Number of options'),
    t('Display type'),
    array(
      'data' => t('Operations'),
      'colspan' => 3,
    ),
  );
  $display_types = _uc_attribute_display_types();
  $query = db_select('uc_attributes', 'a')
    ->extend('PagerDefault')
    ->extend('TableSort')
    ->fields('a', array(
    'aid',
    'name',
    'label',
    'required',
    'ordering',
    'display',
  ))
    ->orderByHeader($header)
    ->limit(30);
  $rows = array();
  $result = $query
    ->execute();
  foreach ($result as $attr) {
    $attr->options = db_query('SELECT COUNT(*) FROM {uc_attribute_options} WHERE aid = :aid', array(
      ':aid' => $attr->aid,
    ))
      ->fetchField();
    if (empty($attr->label)) {
      $attr->label = $attr->name;
    }
    $rows[] = array(
      check_plain($attr->name),
      check_plain($attr->label),
      $attr->required == 1 ? t('Yes') : t('No'),
      $attr->ordering,
      $attr->options,
      $display_types[$attr->display],
      l(t('edit'), 'admin/store/products/attributes/' . $attr->aid . '/edit'),
      l(t('options'), 'admin/store/products/attributes/' . $attr->aid . '/options'),
      l(t('delete'), 'admin/store/products/attributes/' . $attr->aid . '/delete'),
    );
  }
  $build['attributes'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No product attributes have been added yet.'),
  );
  $build['pager'] = array(
    '#theme' => 'pager',
  );
  return $build;
}