You are here

function pm_attribute_list in Drupal PM (Project Management) 7

Provides a list of attributes.

2 string references to 'pm_attribute_list'
pm_attribute_list_form in ./pm.admin.inc
Defines form for attribute list.
pm_menu in ./pm.module
Implements hook_menu().

File

./pm.admin.inc, line 11
List functions for the Project Management module.

Code

function pm_attribute_list() {
  $i = new stdClass();
  $i->type = 'pm_attribute';
  $header = array(
    array(
      'data' => t('Domain'),
      'field' => 'domain',
    ),
    array(
      'data' => t('Key'),
      'field' => 'akey',
    ),
    array(
      'data' => t('Value'),
      'field' => 'avalue',
    ),
    array(
      'data' => t('Active'),
    ),
    array(
      'data' => t('Default'),
    ),
    array(
      'data' => t('Weight'),
      'field' => 'weight',
      'sort' => 'asc',
    ),
    array(
      'data' => pm_icon_add('pm/attributes/add', $i, $_GET),
      'class' => 'pm_list_operations',
    ),
  );
  $query = db_select('pmattribute', 'sa')
    ->fields('sa');
  $where = array();
  $args = array();
  $filterfields = array();
  if (isset($_SESSION['pmattribute_list_filter']['domain']) && $_SESSION['pmattribute_list_filter']['domain'] != '') {
    $where[] = "domain='%s'";
    $args[] = $_SESSION['pmattribute_list_filter']['domain'];
    $filterfields[] = t('Domain');
  }
  if (isset($_SESSION['pmattribute_list_filter']['akey']) && $_SESSION['pmattribute_list_filter']['akey'] != '') {
    $where[] = "LOWER(akey) LIKE LOWER('%s')";
    $args[] = $_SESSION['pmattribute_list_filter']['akey'];
    $filterfields[] = t('Key');
  }
  if (isset($_SESSION['pmattribute_list_filter']['avalue']) && $_SESSION['pmattribute_list_filter']['avalue'] != '') {
    $where[] = "LOWER(avalue) LIKE LOWER('%s')";
    $args[] = $_SESSION['pmattribute_list_filter']['avalue'];
    $filterfields[] = t('Value');
  }
  if (isset($_SESSION['pmattribute_list_filter']['isactive']) && $_SESSION['pmattribute_list_filter']['isactive'] != '-') {
    $where[] = "isactive = %d";
    $args[] = $_SESSION['pmattribute_list_filter']['isactive'];
    $filterfields[] = t('Active');
  }
  if (isset($_SESSION['pmattribute_list_filter']['isdefault']) && $_SESSION['pmattribute_list_filter']['isdefault'] != '-') {
    $where[] = "isdefault = %d";
    $args[] = $_SESSION['pmattribute_list_filter']['isdefault'];
    $filterfields[] = t('Default');
  }
  $itemsperpage = isset($_SESSION['pmattribute_list_filter']['itemsperpage']) ? $_SESSION['pmattribute_list_filter']['itemsperpage'] : variable_get('pm_default_items_per_page', 10);
  $query = $query
    ->extend('TableSort')
    ->orderByHeader($header);
  if (count($filterfields) == 0) {
    $filterdesc = t('Not filtered');
  }
  else {
    $filterdesc = t('Filtered by !fields', array(
      '!fields' => implode(", ", array_unique($filterfields)),
    ));
  }
  $filterdesc .= ' | ' . t('!items items per page', array(
    '!items' => $itemsperpage,
  ));
  $pm_attribute_list_filter = drupal_get_form('pm_attribute_list_filter', $filterdesc);
  $o = drupal_render($pm_attribute_list_filter);
  $result = $query
    ->execute();
  $attributes = array();
  while ($attribute = $result
    ->fetchObject()) {
    $attributes[] = $attribute;
  }
  $pm_attribute_list_form = drupal_get_form('pm_attribute_list_form', $header, $attributes);
  $o .= drupal_render($pm_attribute_list_form);
  $o .= theme('pager', array());
  return $o;
}