You are here

function _casetracker_dashboard_getProjects in Case Tracker 5

Function to get all the projects

Parameters

void:

Return value

array

1 call to _casetracker_dashboard_getProjects()
_casetracker_dashboard_states in ./casetracker_dashboard.module
Function to get an overview of all projects and their states count

File

./casetracker_dashboard.module, line 217

Code

function _casetracker_dashboard_getProjects() {
  static $projects;
  if (!is_array($projects)) {
    $filter_sql = NULL;
    $filter_args = array_filter(variable_get('casetracker_project_node_types', array(
      'casetracker_basic_project',
    )));

    // this is an interisting feature
    if ($project_filter == 'my') {
      global $user;
      $filter_sql = 'AND n.uid = %d';
      $filter_args[] = $user->uid;
    }

    // build the query
    $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 (\'' . implode('\',\'', $filter_args) . '\') ' . 'AND n.status = 1 ' . $filter_sql);
    $sql .= 'ORDER BY n.title ASC';
    $results = db_query($sql);
    $projects = array();
    while ($row = db_fetch_object($results)) {
      $projects[$row->nid] = array(
        'project_number' => $row->project_number,
        'title' => $row->title,
      );
    }
  }
  return $projects;
}