You are here

function casetracker_projects_overview in Case Tracker 5

Menu callback; displays a list of all projects in a table. See the README.txt for the various URLs we support.

Parameters

$project_filter: Whether 'all' or only 'my' (current user) projects are shown.

1 string reference to 'casetracker_projects_overview'
casetracker_menu in ./casetracker.module
Implementation of hook_menu().

File

./casetracker.module, line 977
Enables the handling of projects and their cases.

Code

function casetracker_projects_overview($project_filter = 'all') {
  drupal_set_breadcrumb(array(
    l(t('Home'), NULL),
    l(t('Case Tracker'), 'casetracker'),
    l(t('All projects'), 'casetracker/projects'),
  ));

  // we'll count how many node types can be cases so that we know how many
  // columns our Operations will span. array_filter will, in the absence of a
  // callback, return only indexes whose values do not evaluate to FALSE.
  $case_types = _casetracker_getCaseTypes();
  $colspan_count = count($case_types) + 1;

  // one more for the 'view all cases' link.
  $headers = array(
    array(
      'data' => t('#'),
      'field' => 'cp.project_number',
    ),
    array(
      'data' => t('Title'),
      'field' => 'n.title',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => $colspan_count,
    ),
  );
  $filter_sql = NULL;
  $filter_args = array_filter(variable_get('casetracker_project_node_types', array(
    'casetracker_basic_project',
  )));
  if ($project_filter == 'my') {
    global $user;
    $filter_sql = 'AND n.uid = %d';
    $filter_args[] = $user->uid;
  }
  $sql = db_rewrite_sql('SELECT n.nid, n.title, cp.project_number FROM {node} n LEFT JOIN {casetracker_project} cp ON (n.vid = cp.vid) WHERE n.type IN (' . str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array(
    'casetracker_basic_project',
  )))) * 5 - 1, "'%s',") . ') AND n.status = 1 ' . $filter_sql);
  $results = pager_query($sql . tablesort_sql($headers), 15, 0, NULL, $filter_args);
  $node_types = node_get_types('names');
  $rows = array();
  while ($result = db_fetch_object($results)) {

    // @todo: this would be better if it is in the add case form and not in a query string!
    // providing preselected audience checkboxes for projects as groups (og)
    // checking if project is group
    $node_result = node_load($result->nid);
    $querystring = _casetracker_get_og_query_string($node_result);

    // create the operations
    $operations = array(
      l(t('view cases'), 'casetracker/cases/' . $result->nid . '/all'),
    );
    foreach ($case_types as $case_type) {
      $operations[] = l(t('add !name', array(
        '!name' => $node_types[$case_type],
      )), 'node/add/' . $case_type . '/' . $result->nid, array(), $querystring);
    }

    // create row
    $rows[] = array_merge(array(
      $result->project_number,
      l($result->title, 'node/' . $result->nid),
    ), $operations);
  }
  if (count($rows) == 0) {
    $rows[] = array(
      array(
        'data' => t('No projects found.'),
        'colspan' => 3 + $colspan_count,
      ),
    );
  }

  // set a sensible page title.
  if ($project_filter == 'all') {
    drupal_set_title(t('all projects'));
  }
  if ($project_filter == 'my') {
    drupal_set_title(t('my projects'));
  }
  $output .= theme('table', $headers, $rows, array(
    'id' => 'casetracker-projects-overview',
  ));
  $output .= theme('pager', NULL, 15, 0);
  return $output;
}