You are here

public function CaseTrackerCaseController::getTotalAmountByPriority in Case Tracker 7.2

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

Parameters

int $project_id:

Return value

array of CaseTrackerCase

File

includes/controller/CaseTrackerCaseController.inc, line 105

Class

CaseTrackerCaseController
The Controller for CaseTrackerCase entities

Code

public function getTotalAmountByPriority($project_id = NULL) {
  $query = "SELECT p.field_casetracker_case_priority_value priority, count(c.cid) total\n              FROM {casetracker_case} c\n              JOIN {field_data_field_casetracker_case_priority} p ON p.entity_type = 'casetracker_case' AND p.entity_id = c.cid\n              ";
  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 priority";
  if ($project_id != NULL) {
    $results = db_query($query, array(
      ':pid' => $project_id,
    ))
      ->fetchAll();
  }
  else {
    $results = db_query($query)
      ->fetchAll();
  }
  return $results;
}