Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-03-23-46-36
[civicrm-core.git] / CRM / Report / Form / Member / Summary.php
index 94b14e264c996ab2703cf8093cfd86b4ff677697..886f564eea83a33e12ccb81a8ab17efb59a15b54 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | 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.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -137,6 +137,14 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
           array(
             'no_display' => TRUE,
           ),
+          'contact_type' =>
+          array(
+            'title' => ts('Contact Type'),
+          ),
+          'contact_sub_type' =>
+          array(
+            'title' => ts('Contact SubType'),
+          ),
         ),
       ),
       'civicrm_contribution' =>
@@ -210,7 +218,7 @@ class CRM_Report_Form_Member_Summary 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':
@@ -242,7 +250,7 @@ class CRM_Report_Form_Member_Summary 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'];
@@ -262,12 +270,10 @@ class CRM_Report_Form_Member_Summary 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])) {
 
             // only include statistics columns if set
-            if (CRM_Utils_Array::value('statistics', $field)) {
+            if (!empty($field['statistics'])) {
               $this->_statFields[] = 'civicrm_membership_member_count';
               foreach ($field['statistics'] as $stat => $label) {
                 switch (strtolower($stat)) {
@@ -295,9 +301,7 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
               }
             }
             elseif ($fieldName == 'membership_type_id') {
-              if (!CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']) &&
-                CRM_Utils_Array::value('join_date', $this->_params['group_bys'])
-              ) {
+              if (empty($this->_params['group_bys']['membership_type_id']) && !empty($this->_params['group_bys']['join_date'])) {
                 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']}  ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
               }
               else {
@@ -342,45 +346,9 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
   // end of from
 
   function where() {
-    $clauses = array();
-    foreach ($this->_columns as $tableName => $table) {
-      if (array_key_exists('filters', $table)) {
-        foreach ($table['filters'] as $fieldName => $field) {
-          $clause = NULL;
-
-          if ($field['operatorType'] & 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);
-
-            if ($relative || $from || $to) {
-              $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
-            }
-          }
-          else {
-            $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
-            if ($op) {
-              $clause = $this->whereClause($field,
-                $op,
-                CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
-                CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
-                CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
-              );
-            }
-          }
-          if (!empty($clause)) {
-            $clauses[$fieldName] = $clause;
-          }
-        }
-      }
-    }
-
-    if (!empty($clauses)) {
-      $this->_where = "WHERE {$this->_aliases['civicrm_membership']}.is_test = 0 AND " . implode(' AND ', $clauses);
-    }
-    else {
-      $this->_where = "WHERE {$this->_aliases['civicrm_membership']}.is_test = 0";
-    }
+    $this->_whereClauses[] = "{$this->_aliases['civicrm_membership']}.is_test = 0 AND 
+                              {$this->_aliases['civicrm_contact']}.is_deleted = 0";
+    parent::where();
   }
 
   function groupBy() {
@@ -391,13 +359,11 @@ class CRM_Report_Form_Member_Summary 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]),
@@ -485,7 +451,7 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
     $membershipTypeValues = CRM_Member_PseudoConstant::membershipType();
     $isMembershipType = CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']);
     $isJoiningDate = CRM_Utils_Array::value('join_date', $this->_params['group_bys']);
-    if (CRM_Utils_Array::value('charts', $this->_params)) {
+    if (!empty($this->_params['charts'])) {
       foreach ($rows as $key => $row) {
         if (!($row['civicrm_membership_join_date_subtotal'] &&
             $row['civicrm_membership_membership_type_id']
@@ -498,7 +464,7 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
           if ($join_date) {
             list($year, $month) = explode('-', $join_date);
           }
-          if (CRM_Utils_Array::value('civicrm_membership_join_date_subtotal', $row)) {
+          if (!empty($row['civicrm_membership_join_date_subtotal'])) {
 
             switch ($this->_interval) {
               case 'Month':
@@ -557,8 +523,7 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
     $entryFound = FALSE;
     foreach ($rows as $rowNum => $row) {
       // make count columns point to detail report
-      if (CRM_Utils_Array::value('join_date', $this->_params['group_bys']) &&
-        CRM_Utils_Array::value('civicrm_membership_join_date_start', $row) &&
+      if (!empty($this->_params['group_bys']['join_date']) && !empty($row['civicrm_membership_join_date_start']) &&
         $row['civicrm_membership_join_date_start'] &&
         $row['civicrm_membership_join_date_subtotal']
       ) {
@@ -595,7 +560,7 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
             break;
         }
         $typeUrl = '';
-        if (CRM_Utils_Array::value('membership_type_id', $this->_params['group_bys']) &&
+        if (!empty($this->_params['group_bys']['membership_type_id']) &&
           $typeID = $row['civicrm_membership_membership_type_id']
         ) {
           $typeUrl = "&tid_op=in&tid_value={$typeID}";