You are here

public function CaseTrackerCaseController::getTotalAmountByBundle in Case Tracker 7.2

Sums the amount of Cases grouped by bundle and optionally filter by project.

Parameters

int $project_id:

Return value

array of CaseTrackerCase

File

includes/controller/CaseTrackerCaseController.inc, line 133

Class

CaseTrackerCaseController
The Controller for CaseTrackerCase entities

Code

public function getTotalAmountByBundle($project_id = NULL) {
  $query = "SELECT t.label bundle, count(c.cid) total\n              FROM {casetracker_case} c\n              INNER JOIN {casetracker_case_type} t ON t.type = c.type";
  if ($project_id != NULL) {
    $query .= " JOIN {field_data_field_casetracker_project_ref} proj ON proj.entity_type = 'casetracker_case' AND proj.entity_id = c.cid AND proj.field_casetracker_project_ref_target_id = :pid";
  }
  $query .= " GROUP BY c.type";
  if ($project_id != NULL) {
    $results = db_query($query, array(
      ':pid' => $project_id,
    ))
      ->fetchAll();
  }
  else {
    $results = db_query($query)
      ->fetchAll();
  }
  return $results;
}