INFRA-132 - Trailing commas for multiline arrays
[civicrm-core.git] / CRM / Report / Form / Case / Detail.php
index b93c689609b696ba69b5788a25875cf1a0642a7c..1ce27a138a10b259cdd4ea400563d89819a454f5 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -51,8 +51,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
 
   protected $_includeCaseDetailExtra = FALSE;
 
-  protected $_caseDetailExtra = array(
-    );
+  protected $_caseDetailExtra = array();
 
   /**
    *
@@ -60,15 +59,19 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
   /**
    *
    */
-  function __construct() {
+  public function __construct() {
     $this->case_statuses = CRM_Core_OptionGroup::values('case_status');
-    $this->case_types    = CRM_Case_PseudoConstant::caseType();
-    $rels                = CRM_Core_PseudoConstant::relationshipType();
+    $this->case_types = CRM_Case_PseudoConstant::caseType();
+    $rels = CRM_Core_PseudoConstant::relationshipType();
     foreach ($rels as $relid => $v) {
       $this->rel_types[$relid] = $v['label_b_a'];
     }
 
-    $this->deleted_labels = array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes'));
+    $this->deleted_labels = array(
+      '' => ts('- select -'),
+      0 => ts('No'),
+      1 => ts('Yes'),
+    );
 
     $this->caseActivityTypes = array();
     foreach (CRM_Case_PseudoConstant::caseActivityType() as $typeDetail) {
@@ -76,50 +79,57 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     }
 
     $this->_columns = array(
-      'civicrm_case' =>
-      array(
+      'civicrm_case' => array(
         'dao' => 'CRM_Case_DAO_Case',
-        'fields' =>
-        array(
-          'id' => array('title' => ts('Case ID'),
+        'fields' => array(
+          'id' => array(
+            'title' => ts('Case ID'),
             'no_display' => TRUE,
             'required' => TRUE,
           ),
-          'subject' => array('title' => ts('Subject'),
+          'subject' => array(
+            'title' => ts('Subject'),
             'required' => TRUE,
           ),
-          'start_date' => array('title' => ts('Start Date'),
+          'start_date' => array(
+            'title' => ts('Start Date'),
             'type' => CRM_Utils_Type::T_DATE,
           ),
-          'end_date' => array('title' => ts('End Date'),
+          'end_date' => array(
+            'title' => ts('End Date'),
             'type' => CRM_Utils_Type::T_DATE,
           ),
           'status_id' => array('title' => ts('Case Status')),
           'case_type_id' => array('title' => ts('Case Type')),
-          'is_deleted' => array('title' => ts('Deleted?'),
+          'is_deleted' => array(
+            'title' => ts('Deleted?'),
             'default' => FALSE,
             'type' => CRM_Utils_Type::T_INT,
           ),
         ),
-        'filters' =>
-        array(
-          'start_date' => array('title' => ts('Start Date'),
+        'filters' => array(
+          'start_date' => array(
+            'title' => ts('Start Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
             'type' => CRM_Utils_Type::T_DATE,
           ),
-          'end_date' => array('title' => ts('End Date'),
+          'end_date' => array(
+            'title' => ts('End Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
             'type' => CRM_Utils_Type::T_DATE,
           ),
-          'status_id' => array('title' => ts('Case Status'),
+          'status_id' => array(
+            'title' => ts('Case Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => $this->case_statuses,
           ),
-          'case_type_id' => array('title' => ts('Case Type'),
+          'case_type_id' => array(
+            'title' => ts('Case Type'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => $this->case_types,
           ),
-          'is_deleted' => array('title' => ts('Deleted?'),
+          'is_deleted' => array(
+            'title' => ts('Deleted?'),
             'type' => CRM_Utils_Type::T_INT,
             'operatorType' => CRM_Report_Form::OP_SELECT,
             'options' => $this->deleted_labels,
@@ -127,11 +137,9 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
           ),
         ),
       ),
-      'civicrm_contact' =>
-      array(
+      'civicrm_contact' => array(
         'dao' => 'CRM_Contact_DAO_Contact',
-        'fields' =>
-        array(
+        'fields' => array(
           'client_sort_name' => array(
             'name' => 'sort_name',
             'title' => ts('Client Name'),
@@ -142,24 +150,20 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
             'required' => TRUE,
           ),
         ),
-        'filters' =>
-        array(
+        'filters' => array(
           'sort_name' => array('title' => ts('Client Name')),
         ),
       ),
-      'civicrm_relationship' =>
-      array(
+      'civicrm_relationship' => array(
         'dao' => 'CRM_Contact_DAO_Relationship',
-        'fields' =>
-        array(
-          'case_role' => array('name' => 'relationship_type_id',
+        'fields' => array(
+          'case_role' => array(
+            'name' => 'relationship_type_id',
             'title' => ts('Case Role(s)'),
           ),
         ),
-        'filters' =>
-        array(
-          'case_role' =>
-          array(
+        'filters' => array(
+          'case_role' => array(
             'name' => 'relationship_type_id',
             'title' => ts('Case Role(s)'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
@@ -167,80 +171,70 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
           ),
         ),
       ),
-      'civicrm_email' =>
-      array(
+      'civicrm_email' => array(
         'dao' => 'CRM_Core_DAO_Email',
-        'fields' =>
-        array('email' => array('title' => ts('Email'),
+        'fields' => array(
+          'email' => array(
+            'title' => ts('Email'),
             'no_repeat' => TRUE,
           ),
         ),
         'grouping' => 'contact-fields',
       ),
-      'civicrm_phone' =>
-      array(
+      'civicrm_phone' => array(
         'dao' => 'CRM_Core_DAO_Phone',
-        'fields' =>
-        array(
-          'phone' =>
-          array('title' => ts('Phone'),
+        'fields' => array(
+          'phone' => array(
+            'title' => ts('Phone'),
             'no_repeat' => TRUE,
           ),
         ),
         'grouping' => 'contact-fields',
       ),
-      'civicrm_address' =>
-      array(
+      'civicrm_address' => array(
         'dao' => 'CRM_Core_DAO_Address',
-        'fields' =>
-        array(
+        'fields' => array(
           'street_address' => NULL,
-          'state_province_id' => array('title' => ts('State/Province'),
+          'state_province_id' => array(
+            'title' => ts('State/Province'),
           ),
           'country_id' => array('title' => ts('Country')),
         ),
         'grouping' => 'contact-fields',
-        'filters' =>
-        array(
-          'country_id' =>
-          array('title' => ts('Country'),
+        'filters' => array(
+          'country_id' => array(
+            'title' => ts('Country'),
             'type' => CRM_Utils_Type::T_INT,
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::country(),
           ),
-          'state_province_id' =>
-          array('title' => ts('State/Province'),
+          'state_province_id' => array(
+            'title' => ts('State/Province'),
             'type' => CRM_Utils_Type::T_INT,
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::stateProvince(),
           ),
         ),
       ),
-      'civicrm_worldregion' =>
-      array(
+      'civicrm_worldregion' => array(
         'dao' => 'CRM_Core_DAO_Worldregion',
-        'filters' =>
-        array(
+        'filters' => array(
           'worldregion_id' => array(
             'name' => 'id',
-            'title' => ts('WorldRegion'),
+            'title' => ts('World Region'),
             'type' => CRM_Utils_Type::T_INT,
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::worldRegion(),
           ),
         ),
       ),
-      'civicrm_country' =>
-      array(
+      'civicrm_country' => array(
         'dao' => 'CRM_Core_DAO_Country',
       ),
-      'civicrm_activity_last' =>
-      array(
+      'civicrm_activity_last' => array(
         'dao' => 'CRM_Activity_DAO_Activity',
-        'filters' =>
-        array(
-          'last_activity_date_time' =>
-          array(
+        'filters' => array(
+          'last_activity_date_time' => array(
             'name' => 'activity_date_time',
             'title' => ts('Last Action Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
@@ -248,18 +242,14 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
         ),
         'alias' => 'civireport_activity_last',
       ),
-      'civicrm_activity_last_completed' =>
-      array(
+      'civicrm_activity_last_completed' => array(
         'dao' => 'CRM_Activity_DAO_Activity',
-        'fields' =>
-        array(
-          'last_completed_activity_subject' =>
-          array(
+        'fields' => array(
+          'last_completed_activity_subject' => array(
             'name' => 'subject',
             'title' => ts('Subject of the last completed activity in the case'),
           ),
-          'last_completed_activity_type' =>
-          array(
+          'last_completed_activity_type' => array(
             'name' => 'activity_type_id',
             'title' => ts('Activity type of the last completed activity'),
           ),
@@ -268,32 +258,35 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     );
 
     $this->_options = array(
-      'my_cases' =>
-      array('title' => ts('My Cases'),
+      'my_cases' => array(
+        'title' => ts('My Cases'),
         'type' => 'checkbox',
       ),
     );
     parent::__construct();
   }
 
-  function preProcess() {
+  public function preProcess() {
     parent::preProcess();
   }
 
-  function buildQuickForm() {
+  public function buildQuickForm() {
     parent::buildQuickForm();
     $this->caseDetailSpecialColumnsAdd();
   }
 
-  function caseDetailSpecialColumnsAdd() {
+  public function caseDetailSpecialColumnsAdd() {
     $elements = array();
     $elements[] = &$this->createElement('select', 'case_activity_all_dates', NULL,
       array(
-        '' => ts('-- select --')) + $this->caseActivityTypes
+        '' => ts('- select -'),
+      ) + $this->caseActivityTypes
     );
     $this->addGroup($elements, 'case_detail_extra');
 
-    $this->_caseDetailExtra = array('case_activity_all_dates' => array('title' => ts('List of all dates of activities of Type'),
+    $this->_caseDetailExtra = array(
+      'case_activity_all_dates' => array(
+        'title' => ts('List of all dates of activities of Type'),
         'name' => 'activity_date_time',
       ),
     );
@@ -301,7 +294,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     $this->assign('caseDetailExtra', $this->_caseDetailExtra);
   }
 
-  function select() {
+  public function select() {
     $select = array();
     $this->_columnHeaders = array();
     foreach ($this->_columns as $tableName => $table) {
@@ -310,7 +303,9 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
           if ($tableName == 'civicrm_address') {
             $this->_addressField = TRUE;
           }
-          if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
+          if (!empty($field['required']) ||
+            !empty($this->_params['fields'][$fieldName])
+          ) {
             if ($tableName == 'civicrm_email') {
               $this->_emailField = TRUE;
             }
@@ -345,7 +340,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
   }
 
-  function from() {
+  public function from() {
 
     $case = $this->_aliases['civicrm_case'];
     $conact = $this->_aliases['civicrm_contact'];
@@ -398,7 +393,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     }
   }
 
-  function where() {
+  public function where() {
     $clauses = array();
     $this->_having = '';
     foreach ($this->_columns as $tableName => $table) {
@@ -408,18 +403,21 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
 
           if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
             $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
-            $from     = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
-            $to       = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
+            $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
+            $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
 
             $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type']);
           }
           else {
 
             $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
-            if ($fieldName == 'case_type_id' && !empty($this->_params['case_type_id_value'])) {
+            if ($fieldName == 'case_type_id' &&
+              !empty($this->_params['case_type_id_value'])
+            ) {
               foreach ($this->_params['case_type_id_value'] as $key => $value) {
                 if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) === FALSE) {
-                  $value = CRM_Core_DAO::VALUE_SEPARATOR . $value . CRM_Core_DAO::VALUE_SEPARATOR;
+                  $value = CRM_Core_DAO::VALUE_SEPARATOR . $value .
+                    CRM_Core_DAO::VALUE_SEPARATOR;
 
                   $this->_params['case_type_id_value'][$key] = "'{$value}'";
                 }
@@ -447,8 +445,8 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     }
 
     if (isset($this->_params['options']['my_cases'])) {
-      $session   = CRM_Core_Session::singleton();
-      $userID    = $session->get('userID');
+      $session = CRM_Core_Session::singleton();
+      $userID = $session->get('userID');
       $clauses[] = "{$this->_aliases['civicrm_contact']}.id = {$userID}";
     }
 
@@ -460,7 +458,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     }
   }
 
-  function groupBy() {
+  public function groupBy() {
     $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_case']}.id";
   }
 
@@ -469,20 +467,20 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
    *
    * @return array
    */
-  function statistics(&$rows) {
+  public function statistics(&$rows) {
     $statistics = parent::statistics($rows);
 
-    $select       = "select COUNT( DISTINCT( {$this->_aliases['civicrm_address']}.country_id))";
-    $sql          = "{$select} {$this->_from} {$this->_where}";
+    $select = "select COUNT( DISTINCT( {$this->_aliases['civicrm_address']}.country_id))";
+    $sql = "{$select} {$this->_from} {$this->_where}";
     $countryCount = CRM_Core_DAO::singleValueQuery($sql);
 
     //CaseType statistics
     if (array_key_exists('filters', $statistics)) {
       foreach ($statistics['filters'] as $id => $value) {
         if ($value['title'] == 'Case Type') {
-          $statistics['filters'][$id]['value'] = 'Is ' . $this->case_types[substr($statistics['filters'][$id]
-            ['value'], -3, -2
-          )];
+          $statistics['filters'][$id]['value'] = 'Is ' .
+            $this->case_types[substr($statistics['filters'][$id]['value'], -3, -2
+            )];
         }
       }
     }
@@ -498,11 +496,11 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     return $statistics;
   }
 
-  function orderBy() {
+  public function orderBy() {
     $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_case']}.start_date DESC ";
   }
 
-  function caseDetailSpecialColumnProcess() {
+  public function caseDetailSpecialColumnProcess() {
     if (!$this->_includeCaseDetailExtra) {
       return;
     }
@@ -517,7 +515,8 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
                         LEFT JOIN civicrm_activity civireport_activity_all_{$activityType} ON ( civireport_activity_all_{$activityType}.id = civireport_case_activity_all_{$activityType}.activity_id AND civireport_activity_all_{$activityType}.activity_type_id = {$activityType})";
 
       $this->_columnHeaders['case_activity_all_dates'] = array(
-        'title' => $this->_caseDetailExtra['case_activity_all_dates']['title'] . ": {$this->caseActivityTypes[$activityType]}",
+        'title' => $this->_caseDetailExtra['case_activity_all_dates']['title'] .
+          ": {$this->caseActivityTypes[$activityType]}",
         'type' => CRM_Utils_Array::value('type', $this->_caseDetailExtra['case_activity_all_dates']),
       );
     }
@@ -526,7 +525,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     $this->_from .= ' ' . implode(' ', $from) . ' ';
   }
 
-  function postProcess() {
+  public function postProcess() {
 
     $this->beginPostProcess();
 
@@ -547,8 +546,10 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     $this->endPostProcess($rows);
   }
 
-  function checkEnabledFields() {
-    if (isset($this->_params['worldregion_id_value']) && !empty($this->_params['worldregion_id_value'])) {
+  public function checkEnabledFields() {
+    if (isset($this->_params['worldregion_id_value']) &&
+      !empty($this->_params['worldregion_id_value'])
+    ) {
       $this->_addressField = TRUE;
       $this->_worldRegionField = TRUE;
     }
@@ -559,7 +560,8 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
       $this->_relField = TRUE;
     }
 
-    if (!empty($this->_params['activity_date_time_relative']) || !empty($this->_params['activity_date_time_from']) ||
+    if (!empty($this->_params['activity_date_time_relative']) ||
+      !empty($this->_params['activity_date_time_from']) ||
       CRM_Utils_Array::value('activity_date_time_to', $this->_params)
     ) {
       $this->_activityLast = TRUE;
@@ -576,7 +578,7 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
   /**
    * @param $rows
    */
-  function alterDisplay(&$rows) {
+  public function alterDisplay(&$rows) {
     $entryFound = FALSE;
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
 
@@ -597,9 +599,11 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
       }
       if (array_key_exists('civicrm_case_subject', $row)) {
         if ($value = $row['civicrm_case_subject']) {
-          $caseId = $row['civicrm_case_id'];
-          $contactId = $row['civicrm_contact_id'];
-          $rows[$rowNum]['civicrm_case_subject'] = "<a href= 'javascript:viewCase( $caseId,$contactId );'>$value</a>";
+          $url = CRM_Utils_System::url("civicrm/case/ajax/details",
+            "caseId={$row['civicrm_case_id']}&contactId={$row['civicrm_contact_id']}",
+            $this->_absoluteUrl
+          );
+          $rows[$rowNum]['civicrm_case_subject'] = "<a class=\"crm-popup\" href=\"$url\">$value</a>";
           $rows[$rowNum]['civicrm_case_subject_hover'] = ts('View Details of Case.');
 
           $entryFound = TRUE;
@@ -627,7 +631,9 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
         }
         $entryFound = TRUE;
       }
-      if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_subject', $row) && empty($row['civicrm_activity_last_completed_last_completed_activity_subject'])) {
+      if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_subject', $row) &&
+        empty($row['civicrm_activity_last_completed_last_completed_activity_subject'])
+      ) {
         $rows[$rowNum]['civicrm_activity_last_completed_last_completed_activity_subject'] = ts('(no subject)');
         $entryFound = TRUE;
       }
@@ -672,4 +678,3 @@ class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
     }
   }
 }
-