CRM-17504 -- Case activities reporting
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 6 Nov 2015 13:26:04 +0000 (18:56 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Mon, 16 Nov 2015 06:10:43 +0000 (11:40 +0530)
CRM/Report/Form/Activity.php

index f905fad83519da44d141c161828a38e0ffa32151..265cb14c1f7730fa7ba888260bab94b12c0f678a 100644 (file)
@@ -49,6 +49,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
 
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
+    $caseEnabled = in_array("CiviCase", $config->enableComponents);
     if ($campaignEnabled) {
       $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
       $this->activeCampaigns = $getCampaigns['campaigns'];
@@ -279,6 +280,18 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
       ),
     ) + $this->addressFields(TRUE);
 
+    if ($caseEnabled && CRM_Core_Permission::check('access all cases and activities')) {
+      $this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
+      $this->_columns['civicrm_activity']['filters']['activity_type_id']['options'] = $this->activityTypes;
+      $this->_columns['civicrm_activity']['filters']['include_case_activities'] = array(
+        'name' => 'include_case_activities',
+        'title' => ts('Include Case Activities'),
+        'type' => CRM_Utils_Type::T_INT,
+        'operatorType' => CRM_Report_Form::OP_SELECT,
+        'options' => array('0' => ts('No'), '1' => ts('Yes')),
+      );
+    }
+
     if ($campaignEnabled) {
       // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
 
@@ -572,6 +585,9 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
                 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
                 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
               );
+              if ($field['name'] == 'include_case_activities') {
+                $clause = NULL;
+              }
               if ($fieldName == 'activity_type_id' &&
                 empty($this->_params['activity_type_id_value'])
               ) {
@@ -698,6 +714,27 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
     }
   }
 
+  /**
+   * @param $fields
+   * @param $files
+   * @param $self
+   *
+   * @return array
+   */
+  public static function formRule($fields, $files, $self) {
+    $errors = array();
+    $componentId = CRM_Core_Component::getComponentID('CiviCase');
+    $caseActivityTypes = CRM_Core_OptionGroup::values('activity_type', TRUE, FALSE, FALSE," AND v.component_id={$componentId}");
+    if (!empty($fields['activity_type_id_value']) && is_array($fields['activity_type_id_value']) && empty($fields['include_case_activities_value'])) {
+      foreach ($fields['activity_type_id_value'] as $activityTypeId) {
+        if (in_array($activityTypeId, $caseActivityTypes)) {
+          $errors['fields'] = ts("Please enable 'Include Case Activities' to filter with Case Activity types.");
+        }
+      }
+    }
+    return $errors;
+  }
+
   public function postProcess() {
     //reset value of activity_date
     if (!empty($this->_force)) {