You are here

function hosting_package_list in Hostmaster (Aegir) 6

Display a list of packages associated to a node @TODO Add ability to filter by additional fields @TODO Add paging.

1 string reference to 'hosting_package_list'
hosting_package_menu in modules/hosting/package/hosting_package.module
Implementation of hook_menu().

File

modules/hosting/package/hosting_package.module, line 413

Code

function hosting_package_list($ref, $type = null) {
  drupal_set_title(t('Packages on @reference', array(
    '@reference' => $ref->title,
  )));
  $header = array(
    array(
      'data' => t('Status'),
      'field' => 'status',
      'sort' => 'DESC',
    ),
    array(
      'data' => t('Package'),
      'field' => 'short_name',
    ),
    array(
      'data' => t('Release'),
      'field' => 'version',
    ),
    array(
      'data' => t('Package type'),
      'field' => 'package_type',
    ),
  );
  $args[] = $ref->nid;
  if (!is_null($type)) {
    $cond = " AND h.package_type = '%s'";
    $args[] = $type;
  }
  $sql = "SELECT h.nid as 'package', i.status, h.short_name, i.version, h.package_type, i.status FROM {hosting_package} h\n    LEFT JOIN {hosting_package_instance} i ON i.package_id=h.nid WHERE i.rid=%d" . $cond;
  $sql .= tablesort_sql($header);

  // @TODO hide deleted sites
  $result = pager_query(db_rewrite_sql($sql, 'h'), 25, 2, null, $args);
  $view_package_perm = user_access('view package');
  if (!$result) {
    return t('No packages are associated with @reference', array(
      '@reference' => $ref->title,
    ));
  }
  $rows = array();
  while ($package = db_fetch_object($result)) {
    $row_class = $package->status == 1 ? 'hosting-success' : 'hosting-info';
    $row = array();
    $row[] = array(
      'data' => $package->status ? t('Enabled') : t('Available'),
      'class' => 'hosting-status',
    );
    $row[] = $view_package_perm ? l(filter_xss($package->short_name), 'node/' . $package->package) : $package->short_name;
    $row[] = $package->version;
    $row[] = filter_xss($package->package_type);
    $rows[] = array(
      'data' => $row,
      'class' => $row_class,
    );
  }
  return theme('table', $header, $rows, array(
    'class' => 'hosting-table',
  )) . theme('pager', null, 25, 2);
}