Merge pull request #3880 from rohankatkar/webtestCRM-15108
[civicrm-core.git] / CRM / Report / Form / ActivitySummary.php
index 8f89c0552164dd2a2c8387b09cd8602fc3ff9bdf..f77c37475852cb00342d4dd2a132d0e3c801e22d 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -38,6 +38,12 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
   protected $_emailField = FALSE;
   protected $_phoneField = FALSE;
 
+  /**
+   *
+   */
+  /**
+   *
+   */
   function __construct() {
     $this->_columns = array(
       'civicrm_contact' =>
@@ -186,7 +192,7 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
     foreach ($this->_columns as $tableName => $table) {
       if (array_key_exists('group_bys', $table)) {
         foreach ($table['group_bys'] as $fieldName => $field) {
-          if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
+          if (!empty($this->_params['group_bys'][$fieldName])) {
 
             switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
               case 'YEARWEEK':
@@ -218,7 +224,7 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
                 $field['title'] = 'Quarter';
                 break;
             }
-            if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
+            if (!empty($this->_params['group_bys_freq'][$fieldName])) {
               $this->_interval = $field['title'];
               $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
               $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
@@ -235,16 +241,14 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
       }
       if (array_key_exists('fields', $table)) {
         foreach ($table['fields'] as $fieldName => $field) {
-          if (CRM_Utils_Array::value('required', $field) ||
-            CRM_Utils_Array::value($fieldName, $this->_params['fields'])
-          ) {
+          if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
             if ($tableName == 'civicrm_email') {
               $this->_emailField = TRUE;
             }
             if ($tableName == 'civicrm_phone') {
               $this->_phoneField = TRUE;
             }
-            if (CRM_Utils_Array::value('statistics', $field)) {
+            if (!empty($field['statistics'])) {
               foreach ($field['statistics'] as $stat => $label) {
                 switch (strtolower($stat)) {
                   case 'count':
@@ -264,7 +268,7 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
               }
             }
             elseif ($fieldName == 'activity_type_id') {
-              if (!CRM_Utils_Array::value('activity_type_id', $this->_params['group_bys'])) {
+              if (empty($this->_params['group_bys']['activity_type_id'])) {
                 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']}  ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
               }
               else {
@@ -397,13 +401,11 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
       foreach ($this->_columns as $tableName => $table) {
         if (array_key_exists('group_bys', $table)) {
           foreach ($table['group_bys'] as $fieldName => $field) {
-            if (CRM_Utils_Array::value($fieldName, $this->_params['group_bys'])) {
-              if (CRM_Utils_Array::value('chart', $field)) {
+            if (!empty($this->_params['group_bys'][$fieldName])) {
+              if (!empty($field['chart'])) {
                 $this->assign('chartSupported', TRUE);
               }
-              if (CRM_Utils_Array::value('frequency', $table['group_bys'][$fieldName]) &&
-                CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])
-              ) {
+              if (!empty($table['group_bys'][$fieldName]['frequency']) && !empty($this->_params['group_bys_freq'][$fieldName])) {
 
                 $append = "YEAR({$field['dbAlias']}),";
                 if (in_array(strtolower($this->_params['group_bys_freq'][$fieldName]),
@@ -429,14 +431,19 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
     }
   }
 
+  /**
+   * @param $fields
+   * @param $files
+   * @param $self
+   *
+   * @return array
+   */
   function formRule($fields, $files, $self) {
     $errors = array();
     $contactFields = array('sort_name', 'email', 'phone');
-    if (CRM_Utils_Array::value('group_bys', $fields)) {
+    if (!empty($fields['group_bys'])) {
 
-      if (CRM_Utils_Array::value('activity_type_id', $fields['group_bys']) &&
-        !CRM_Utils_Array::value('sort_name', $fields['group_bys'])
-      ) {
+      if (!empty($fields['group_bys']['activity_type_id']) && empty($fields['group_bys']['sort_name'])) {
         foreach ($fields['fields'] as $fieldName => $val) {
           if (in_array($fieldName, $contactFields)) {
             $errors['fields'] = ts("Please select GroupBy 'Contact' to display Contact Fields");
@@ -445,8 +452,8 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
         }
       }
 
-      if (CRM_Utils_Array::value('activity_date_time', $fields['group_bys'])) {
-        if (CRM_Utils_Array::value('sort_name', $fields['group_bys'])) {
+      if (!empty($fields['group_bys']['activity_date_time'])) {
+        if (!empty($fields['group_bys']['sort_name'])) {
           $errors['fields'] = ts("Please do not select GroupBy 'Activity Date' with GroupBy 'Contact'");
         }
         else {
@@ -468,6 +475,9 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
     parent::postProcess();
   }
 
+  /**
+   * @param $rows
+   */
   function alterDisplay(&$rows) {
     // custom code to alter rows