copyright and version fixes
[civicrm-core.git] / CRM / Report / Form / Pledge / Pbnp.php
index c97ea579ba6d11bddaae6d25750a99e446118d01..6dfcb83e70c0e9033aa34d1497e865adf6470cbf 100644 (file)
@@ -1,11 +1,9 @@
 <?php
-// $Id$
-
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -30,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -41,11 +39,21 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
     'pieChart' => 'Pie Chart',
   );
   public $_drilldownReport = array('pledge/summary' => 'Link to Detail Report');
-  
+
   protected $_customGroupExtends = array(
     'Pledge');
-  
+
   function __construct() {
+
+    // Check if CiviCampaign is a) enabled and b) has active campaigns
+    $config = CRM_Core_Config::singleton();
+    $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
+    if ($campaignEnabled) {
+      $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
+      $this->activeCampaigns = $getCampaigns['campaigns'];
+      asort($this->activeCampaigns);
+    }
+
     $this->_columns = array(
       'civicrm_contact' =>
       array(
@@ -96,13 +104,14 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
         array(
           'pledge_create_date' =>
           array(
-            'title' => 'Pledge Made',
+            'title' => ts('Pledge Made'),
             'operatorType' => CRM_Report_Form::OP_DATE,
           ),
           'currency' =>
           array('title' => 'Currency',
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'options' => CRM_Core_PseudoConstant::currencySymbols('name','name'),
+            'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
+            'default' => NULL,
             'type' => CRM_Utils_Type::T_STRING,
           ),
           'financial_type_id' =>
@@ -124,6 +133,14 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
             'required' => TRUE,
           ),
         ),
+        'filters' =>
+        array(
+          'scheduled_date' =>
+          array(
+            'title' => ts('Next Payment Due'),
+            'operatorType' => CRM_Report_Form::OP_DATE,
+          ),
+        ),
         'grouping' => 'pledge-fields',
       ),
       'civicrm_address' =>
@@ -169,6 +186,18 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
       ),
     );
 
+    // If we have a campaign, build out the relevant elements
+    if ($campaignEnabled && !empty($this->activeCampaigns)) {
+      $this->_columns['civicrm_pledge']['fields']['campaign_id'] = array(
+        'title' => 'Campaign',
+        'default' => 'false',
+      );
+      $this->_columns['civicrm_pledge']['filters']['campaign_id'] = array('title' => ts('Campaign'),
+        'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+        'options' => $this->activeCampaigns,
+      );
+    }
+
     $this->_tagFilter = TRUE;
     $this->_currencyColumn = 'civicrm_pledge_currency';
     parent::__construct();
@@ -185,9 +214,7 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
     foreach ($this->_columns as $tableName => $table) {
       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])) {
             // to include optional columns address and email, only if checked
             if ($tableName == 'civicrm_address') {
               $this->_addressField = TRUE;
@@ -222,9 +249,9 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
 
     $this->_from = "
         FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
-             INNER JOIN civicrm_pledge  {$this->_aliases['civicrm_pledge']} 
+             INNER JOIN civicrm_pledge  {$this->_aliases['civicrm_pledge']}
                         ON ({$this->_aliases['civicrm_pledge']}.contact_id =
-                            {$this->_aliases['civicrm_contact']}.id)  AND 
+                            {$this->_aliases['civicrm_contact']}.id)  AND
                             {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
              LEFT  JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
                         ON ({$this->_aliases['civicrm_pledge']}.id =
@@ -233,8 +260,8 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
     // include address field if address column is to be included
     if ($this->_addressField) {
       $this->_from .= "
-             LEFT  JOIN civicrm_address {$this->_aliases['civicrm_address']} 
-                        ON ({$this->_aliases['civicrm_contact']}.id = 
+             LEFT  JOIN civicrm_address {$this->_aliases['civicrm_address']}
+                        ON ({$this->_aliases['civicrm_contact']}.id =
                             {$this->_aliases['civicrm_address']}.contact_id) AND
                             {$this->_aliases['civicrm_address']}.is_primary = 1\n";
     }
@@ -242,16 +269,16 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
     // include email field if email column is to be included
     if ($this->_emailField) {
       $this->_from .= "
-            LEFT  JOIN civicrm_email {$this->_aliases['civicrm_email']} 
-                       ON ({$this->_aliases['civicrm_contact']}.id = 
-                           {$this->_aliases['civicrm_email']}.contact_id) AND 
+            LEFT  JOIN civicrm_email {$this->_aliases['civicrm_email']}
+                       ON ({$this->_aliases['civicrm_contact']}.id =
+                           {$this->_aliases['civicrm_email']}.contact_id) AND
                            {$this->_aliases['civicrm_email']}.is_primary = 1\n";
     }
   }
 
   function groupBy() {
     $this->_groupBy = "
-         GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id, 
+         GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
                   {$this->_aliases['civicrm_pledge']}.id,
                   {$this->_aliases['civicrm_pledge']}.currency";
   }
@@ -306,7 +333,7 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
       //handle the Financial Type Ids
       if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
         if ($value = $row['civicrm_pledge_financial_type_id']) {
-          $rows[$rowNum]['civicrm_pledge_financial_type_id'] = 
+          $rows[$rowNum]['civicrm_pledge_financial_type_id'] =
             CRM_Contribute_PseudoConstant::financialType($value, false);
         }
         $entryFound = TRUE;
@@ -350,6 +377,14 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
         $entryFound = TRUE;
       }
 
+      // If using campaigns, convert campaign_id to campaign title
+      if (array_key_exists('civicrm_pledge_campaign_id', $row)) {
+        if ($value = $row['civicrm_pledge_campaign_id']) {
+          $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns[$value];
+        }
+        $entryFound = TRUE;
+      }
+
       // skip looking further in rows, if first row itself doesn't
       // have the column we need
       if (!$entryFound) {