You are here

function hosting_package_list in Hosting 5

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 package/hosting_package.module

File

package/hosting_package.module, line 322

Code

function hosting_package_list($rid, $type = null) {
  $ref = node_load($rid);
  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[] = $rid;
  if (!is_null($type)) {
    $cond = " AND n.package_type = '%s'";
    $args[] = $type;
  }
  $sql = "SELECT n.nid as 'package', i.status, n.short_name, i.version, n.package_type, i.status FROM {hosting_package} n\n    LEFT JOIN {hosting_package_instance} i ON i.package_id=n.nid WHERE i.rid=%d" . $cond;
  $sql .= tablesort_sql($header);

  // @TODO hide deleted sites
  $result = pager_query(db_rewrite_sql($sql), 25, 2, null, $args);
  $view_package_perm = user_access('view package');
  if (!db_num_rows($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);
}