Ian province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Report / Form / Extended.php
index 8e3bb49db87e586a7f73eebd4ea16ee052632ccd..1f60de6f9542a5ebf5065bc599e7a150c088e584 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -42,9 +42,6 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
   protected $_customGroupExtends = array();
   protected $_baseTable = 'civicrm_contact';
 
-  /**
-   *
-   */
   /**
    *
    */
@@ -52,16 +49,22 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     parent::__construct();
   }
 
+  /**
+   *
+   */
   public function preProcess() {
     parent::preProcess();
   }
 
+  /**
+   *
+   */
   public function select() {
     parent::select();
   }
 
 
-  /*
+  /**
    * From clause build where baseTable & fromClauses are defined
    */
   public function from() {
@@ -79,10 +82,9 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     }
   }
 
-  /*
-   * Define any from clauses in use (child classes to override)
-   */
   /**
+   * Define any from clauses in use (child classes to override)
+   *
    * @return array
    */
   public function fromClauses() {
@@ -110,7 +112,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
   }
 
   /**
-   * @param $rows
+   * @param array $rows
    *
    * @return array
    */
@@ -126,7 +128,13 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
   }
 
   /**
-   * @param $rows
+   * Alter display of rows.
+   *
+   * Iterate through the rows retrieved via SQL and make changes for display purposes,
+   * such as rendering contacts as links.
+   *
+   * @param array $rows
+   *   Rows generated by SQL, with an array for each row.
    */
   public function alterDisplay(&$rows) {
     parent::alterDisplay($rows);
@@ -244,16 +252,16 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
             'title' => ts('Price Field Value Label'),
           ),
         ),
-        'group_bys' =>        //note that we have a requirement to group by label such that all 'Promo book' lines
+        'group_bys' => //note that we have a requirement to group by label such that all 'Promo book' lines
         // are grouped together across price sets but there may be a separate need to group
         // by id so that entries in one price set are distinct from others. Not quite sure what
         // to call the distinction for end users benefit
-          array(
-            'price_field_value_label' => array(
-              'title' => ts('Price Field Value Label'),
-              'name' => 'label',
-            ),
+        array(
+          'price_field_value_label' => array(
+            'title' => ts('Price Field Value Label'),
+            'name' => 'label',
           ),
+        ),
       ),
     );
   }
@@ -358,7 +366,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
           'event_id' => array(
             'title' => ts('Event'),
             'default_weight' => '1',
-            'default_order' => 'ASC'
+            'default_order' => 'ASC',
           ),
         ),
         'group_bys' => array(
@@ -509,7 +517,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
             'alter_display' => 'alterContributionType',
           ),
           'payment_instrument_id' => array(
-            'title' => ts('Payment Instrument'),
+            'title' => ts('Payment Method'),
             'alter_display' => 'alterPaymentType',
           ),
           'source' => array('title' => 'Contribution Source'),
@@ -545,7 +553,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
         ),
         'order_bys' => array(
           'payment_instrument_id' => array(
-            'title' => ts('Payment Instrument'),
+            'title' => ts('Payment Method'),
           ),
           'financial_type_id' => array(
             'title' => ts('Financial Type'),
@@ -553,7 +561,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
         ),
         'group_bys' => array(
           'financial_type_id' => array('title' => ts('Financial Type')),
-          'payment_instrument_id' => array('title' => ts('Payment Instrument')),
+          'payment_instrument_id' => array('title' => ts('Payment Method')),
           'contribution_id' => array(
             'title' => ts('Individual Contribution'),
             'name' => 'id',
@@ -594,8 +602,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
         'filters' => array(
           'id' => array(
             'title' => ts('Contact ID'),
-          )
-        ,
+          ),
           'sort_name' => array(
             'title' => ts('Contact Name'),
           ),
@@ -623,41 +630,41 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
         'fields' => array(
           'id' => array(
             'title' => ts('Case ID'),
-            'required' => FALSE
+            'required' => FALSE,
           ),
           'subject' => array(
             'title' => ts('Case Subject'),
-            'default' => TRUE
+            'default' => TRUE,
           ),
           'status_id' => array(
             'title' => ts('Status'),
-            'default' => TRUE
+            'default' => TRUE,
           ),
           'case_type_id' => array(
             'title' => ts('Case Type'),
-            'default' => TRUE
+            'default' => TRUE,
           ),
           'case_start_date' => array(
             'title' => ts('Case Start Date'),
             'name' => 'start_date',
-            'default' => TRUE
+            'default' => TRUE,
           ),
           'case_end_date' => array(
             'title' => ts('Case End Date'),
             'name' => 'end_date',
-            'default' => TRUE
+            'default' => TRUE,
           ),
           'case_duration' => array(
             'name' => 'duration',
             'title' => ts('Duration (Days)'),
-            'default' => FALSE
+            'default' => FALSE,
           ),
           'case_is_deleted' => array(
             'name' => 'is_deleted',
             'title' => ts('Case Deleted?'),
             'default' => FALSE,
-            'type' => CRM_Utils_Type::T_INT
-          )
+            'type' => CRM_Utils_Type::T_INT,
+          ),
         ),
         'filters' => array(
           'case_start_date' => array(
@@ -670,18 +677,18 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
             'title' => ts('Case End Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
             'type' => CRM_Utils_Type::T_DATE,
-            'name' => 'end_date'
+            'name' => 'end_date',
           ),
           'case_type_id' => array(
             'title' => ts('Case Type'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'options' => $this->case_types
+            'options' => $this->case_types,
           ),
           'case_status_id' => array(
             'title' => ts('Case Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => $this->case_statuses,
-            'name' => 'status_id'
+            'name' => 'status_id',
           ),
           'case_is_deleted' => array(
             'title' => ts('Case Deleted?'),
@@ -689,37 +696,27 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
             'operatorType' => CRM_Report_Form::OP_SELECT,
             'options' => $this->deleted_labels,
             'default' => 0,
-            'name' => 'is_deleted'
-          )
-        )
-      )
+            'name' => 'is_deleted',
+          ),
+        ),
+      ),
     );
   }
 
-  /*
-   * adding address fields to construct function in reports
-   * @param array $options Options for the report
-   * - prefix prefix to add (e.g. 'honor' when getting address details for honor contact
-   * - prefix_label optional prefix lable eg. "Honoree " for front end
-   * - group_by enable these fields for group by - default false
-   * - order_by enable these fields for order by
-   * - filters enable these fields for filtering
-   * - defaults - (is this working?) values to pre-populate
-   * @return array address fields for construct clause
-   */
   /**
-   * Get address columns to add to array
+   * Get address columns to add to array.
    *
    * @param array $options
-   *  - prefix Prefix to add to table (in case of more than one instance of the table)
-   *  - prefix_label Label to give columns from this address table instance
-   *
-   * @return array address columns definition
-   */
-  /**
-   * @param array $options
+   *   Options for the report.
+   *   - prefix prefix to add (e.g. 'honor' when getting address details for honor contact
+   *   - prefix_label optional prefix lable eg. "Honoree " for front end
+   *   - group_by enable these fields for group by - default false
+   *   - order_by enable these fields for order by
+   *   - filters enable these fields for filtering
+   *   - defaults - (is this working?) values to pre-populate
    *
    * @return array
+   *   address columns definition
    */
   public function getAddressColumns($options = array()) {
     $defaultOptions = array(
@@ -729,7 +726,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
       'order_by' => TRUE,
       'filters' => TRUE,
       'defaults' => array(
-        'country_id' => TRUE
+        'country_id' => TRUE,
       ),
     );
 
@@ -768,21 +765,18 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
             'title' => ts($options['prefix_label'] . 'Street Number'),
             'type' => 1,
             'default' => CRM_Utils_Array::value('street_number', $options['defaults'], FALSE),
-            'name' => 'street_number',
           ),
           $options['prefix'] . 'street_name' => array(
             'name' => 'street_name',
             'title' => ts($options['prefix_label'] . 'Street Name'),
             'type' => 1,
             'default' => CRM_Utils_Array::value('street_name', $options['defaults'], FALSE),
-            'name' => 'street_name',
           ),
           $options['prefix'] . 'street_unit' => array(
             'name' => 'street_unit',
             'title' => ts($options['prefix_label'] . 'Street Unit'),
             'type' => 1,
             'default' => CRM_Utils_Array::value('street_unit', $options['defaults'], FALSE),
-            'name' => 'street_unit',
           ),
           $options['prefix'] . 'city' => array(
             'title' => ts($options['prefix_label'] . 'City'),
@@ -920,10 +914,9 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     return $addressFields;
   }
 
-  /*
-   * Get Information about advertised Joins
-   */
   /**
+   * Get Information about advertised Joins.
+   *
    * @return array
    */
   public function getAvailableJoins() {
@@ -1011,11 +1004,10 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     );
   }
 
-  /*
+  /**
    * Add join from contact table to address. Prefix will be added to both tables
    * as it's assumed you are using it to get address of a secondary contact
-   */
-  /**
+   *
    * @param string $prefix
    */
   public function joinAddressFromContact($prefix = '') {
@@ -1038,8 +1030,8 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
      ";
   }
 
-  /*
-   * Define join from line item table to participant table
+  /**
+   * Define join from line item table to participant table.
    */
   public function joinParticipantFromLineItem() {
     $this->_from .= " LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
@@ -1048,7 +1040,7 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     ";
   }
 
-  /*
+  /**
    * Define join from line item table to Membership table. Seems to be still via contribution
    * as the entity. Have made 'inner' to restrict does that make sense?
    */
@@ -1063,8 +1055,8 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
     ";
   }
 
-  /*
-   * Define join from Participant to Contribution table
+  /**
+   * Define join from Participant to Contribution table.
    */
   public function joinContributionFromParticipant() {
     $this->_from .= " LEFT JOIN civicrm_participant_payment pp
@@ -1074,8 +1066,8 @@ class CRM_Report_Form_Extended extends CRM_Report_Form {
       ";
   }
 
-  /*
-   * Define join from Membership to Contribution table
+  /**
+   * Define join from Membership to Contribution table.
    */
   public function joinContributionFromMembership() {
     $this->_from .= " LEFT JOIN civicrm_membership_payment pp
@@ -1225,31 +1217,29 @@ WHERE   line_item_civireport.id IS NOT NULL
                         {$this->_aliases['civicrm_event']}.is_template = 0)";
   }
 
-  /*
-    * Retrieve text for financial type from pseudoconstant
-    */
   /**
+   * Retrieve text for financial type from pseudoconstant.
+   *
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return string
    */
   public function alterNickName($value, &$row) {
     if (empty($row['civicrm_contact_id'])) {
-      return;
+      return NULL;
     }
     $contactID = $row['civicrm_contact_id'];
     return "<div id=contact-{$contactID} class='crm-entity'>
-           <span class='crm-editable crmf-nick_name crm-editable-enabled' data-action='create'>
+           <span class='crm-editable crmf-nick_name crm-editable-enabled'>
            " . $value . "</span></div>";
   }
 
-  /*
-   * Retrieve text for contribution type from pseudoconstant
-   */
   /**
+   * Retrieve text for contribution type from pseudoconstant.
+   *
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array|string
    */
@@ -1257,12 +1247,11 @@ WHERE   line_item_civireport.id IS NOT NULL
     return is_string(CRM_Contribute_PseudoConstant::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant::financialType($value, FALSE) : '';
   }
 
-  /*
-   * Retrieve text for contribution status from pseudoconstant
-   */
   /**
+   * Retrieve text for contribution status from pseudoconstant.
+   *
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array
    */
@@ -1270,12 +1259,11 @@ WHERE   line_item_civireport.id IS NOT NULL
     return CRM_Contribute_PseudoConstant::contributionStatus($value);
   }
 
-  /*
-   * Retrieve text for payment instrument from pseudoconstant
-   */
   /**
+   * Retrieve text for payment instrument from pseudoconstant.
+   *
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array
    */
@@ -1285,7 +1273,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array|string
    */
@@ -1295,7 +1283,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array|string
    */
@@ -1305,7 +1293,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    *
    * @return array|string
    */
@@ -1315,7 +1303,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    * @param $selectedfield
    * @param string $criteriaFieldName
    *
@@ -1334,7 +1322,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    * @param $selectedfield
    * @param string $criteriaFieldName
    *
@@ -1353,7 +1341,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    * @param $selectedfield
    * @param string $criteriaFieldName
    *
@@ -1373,7 +1361,7 @@ WHERE   line_item_civireport.id IS NOT NULL
 
   /**
    * @param $value
-   * @param $row
+   * @param array $row
    * @param string $fieldname
    *
    * @return mixed
@@ -1391,7 +1379,7 @@ WHERE   line_item_civireport.id IS NOT NULL
    */
   public function alterParticipantStatus($value) {
     if (empty($value)) {
-      return;
+      return NULL;
     }
     return CRM_Event_PseudoConstant::participantStatus($value, FALSE, 'label');
   }
@@ -1399,11 +1387,11 @@ WHERE   line_item_civireport.id IS NOT NULL
   /**
    * @param $value
    *
-   * @return string
+   * @return string|void
    */
   public function alterParticipantRole($value) {
     if (empty($value)) {
-      return;
+      return NULL;
     }
     $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
     $value = array();
@@ -1422,5 +1410,5 @@ WHERE   line_item_civireport.id IS NOT NULL
     $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
     return $paymentInstruments[$value];
   }
-}
 
+}