INFRA-132 - CRM/Pledge - phpcbf
[civicrm-core.git] / CRM / Pledge / BAO / Pledge.php
index 5d18a9734d50a9bcaa30a2232cc38faa0ceac9e8..ca226f7f81381888dbb5ed1e22211d75de9dbf5a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -35,7 +35,7 @@
 class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
 
   /**
-   * static field for all the pledge information that we can potentially export
+   * Static field for all the pledge information that we can potentially export
    *
    * @var array
    * @static
@@ -43,9 +43,9 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   static $_exportableFields = NULL;
 
   /**
-   * class constructor
+   * Class constructor
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
@@ -56,14 +56,15 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
    * of time. This is the inverse function of create. It also stores all the retrieved
    * values in the default array
    *
-   * @param array $params   (reference ) an assoc array of name/value pairs
-   * @param array $defaults (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $defaults
+   *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return object CRM_Pledge_BAO_Pledge object
-   * @access public
+   * @return CRM_Pledge_BAO_Pledge object
    * @static
    */
-  static function retrieve(&$params, &$defaults) {
+  public static function retrieve(&$params, &$defaults) {
     $pledge = new CRM_Pledge_DAO_Pledge();
     $pledge->copyValues($params);
     if ($pledge->find(TRUE)) {
@@ -74,16 +75,16 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   }
 
   /**
-   * function to add pledge
+   * Add pledge
    *
-   * @param array $params reference array contains the values submitted by the form
+   * @param array $params
+   *   Reference array contains the values submitted by the form.
    *
-   * @access public
    * @static
    *
    * @return object
    */
-  static function add(&$params) {
+  public static function add(&$params) {
     if (!empty($params['id'])) {
       CRM_Utils_Hook::pre('edit', 'Pledge', $params['id'], $params);
     }
@@ -122,15 +123,17 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
    * Given the list of params in the params array, fetch the object
    * and store the values in the values array
    *
-   * @param array $params input parameters to find object
-   * @param array $values output values of the object
-   * @param array $returnProperties  if you want to return specific fields
+   * @param array $params
+   *   Input parameters to find object.
+   * @param array $values
+   *   Output values of the object.
+   * @param array $returnProperties
+   *   If you want to return specific fields.
    *
    * @return array associated array of field values
-   * @access public
    * @static
    */
-  static function &getValues(&$params, &$values, $returnProperties = NULL) {
+  public static function &getValues(&$params, &$values, $returnProperties = NULL) {
     if (empty($params)) {
       return NULL;
     }
@@ -139,15 +142,15 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   }
 
   /**
-   * takes an associative array and creates a pledge object
+   * Takes an associative array and creates a pledge object
    *
-   * @param array $params (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return object CRM_Pledge_BAO_Pledge object
-   * @access public
+   * @return CRM_Pledge_BAO_Pledge object
    * @static
    */
-  static function &create(&$params) {
+  public static function &create(&$params) {
     //FIXME: a cludgy hack to fix the dates to MySQL format
     $dateFields = array('start_date', 'create_date', 'acknowledge_date', 'modified_date', 'cancel_date', 'end_date');
     foreach ($dateFields as $df) {
@@ -200,7 +203,6 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
     // skip payment stuff inedit mode
     if (!isset($params['id']) || !empty($params['is_pledge_pending'])) {
 
-
       //if pledge is pending delete all payments and recreate.
       if (!empty($params['is_pledge_pending'])) {
         CRM_Pledge_BAO_PledgePayment::deletePayments($pledge->id);
@@ -253,16 +255,16 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   }
 
   /**
-   * Function to delete the pledge
+   * Delete the pledge
    *
-   * @param int $id pledge id
+   * @param int $id
+   *   Pledge id.
    *
    * @return mixed
-   * @access public
    * @static
    *
    */
-  static function deletePledge($id) {
+  public static function deletePledge($id) {
     CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray);
 
     $transaction = new CRM_Core_Transaction();
@@ -299,7 +301,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   }
 
   /**
-   * function to get the amount details date wise.
+   * Get the amount details date wise.
    *
    * @param string $status
    * @param string $startDate
@@ -307,7 +309,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
    *
    * @return array|null
    */
-  static function getTotalAmountAndCount($status = NULL, $startDate = NULL, $endDate = NULL) {
+  public static function getTotalAmountAndCount($status = NULL, $startDate = NULL, $endDate = NULL) {
     $where = array();
     $select = $from = $queryDate = NULL;
     //get all status
@@ -362,7 +364,8 @@ GROUP BY  currency
       $pamount[] = CRM_Utils_Money::format($dao->pledge_amount, $dao->currency);
     }
 
-    $pledge_amount = array('pledge_amount' => implode(', ', $pamount),
+    $pledge_amount = array(
+    'pledge_amount' => implode(', ', $pamount),
       'pledge_count' => $pCount,
       'purl' => CRM_Utils_System::url('civicrm/pledge/search',
         "reset=1&force=1&pstatus={$statusId}&pstart={$start}&pend={$end}&test=0"
@@ -417,7 +420,6 @@ GROUP BY  currency
  GROUP BY  cp.currency
 ";
     if ($select) {
-      // CRM_Core_Error::debug($status . ' start:' . $startDate . '- end:' . $endDate, $query);
       $dao    = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
       $amount = array();
       $count  = 0;
@@ -428,7 +430,8 @@ GROUP BY  currency
       }
 
       if ($count) {
-        return array_merge($pledge_amount, array('received_amount' => implode(', ', $amount),
+        return array_merge($pledge_amount, array(
+        'received_amount' => implode(', ', $amount),
             'received_count' => $count,
             'url' => CRM_Utils_System::url('civicrm/pledge/search',
               "reset=1&force=1&status={$statusId}&start={$start}&end={$end}&test=0"
@@ -443,16 +446,16 @@ GROUP BY  currency
   }
 
   /**
-   * Function to get list of pledges In Honor of contact Ids
+   * Get list of pledges In Honor of contact Ids
    *
-   * @param int $honorId In Honor of Contact ID
+   * @param int $honorId
+   *   In Honor of Contact ID.
    *
    * @return array return the list of pledge fields
    *
-   * @access public
    * @static
    */
-  static function getHonorContacts($honorId) {
+  public static function getHonorContacts($honorId) {
     $params = array();
     $honorDAO = new CRM_Contribute_DAO_ContributionSoft();
     $honorDAO->contact_id = $honorId;
@@ -488,15 +491,16 @@ GROUP BY  currency
   }
 
   /**
-   * Function to send Acknowledgment and create activity.
+   * Send Acknowledgment and create activity.
    *
-   * @param object $form form object.
-   * @param array  $params (reference ) an assoc array of name/value pairs.
-   * @access public
+   * @param CRM_Core_Form $form
+   *   Form object.
+   * @param array $params
+   *   An assoc array of name/value pairs.
    *
    * @return void.
    */
-  static function sendAcknowledgment(&$form, $params) {
+  public static function sendAcknowledgment(&$form, $params) {
     //handle Acknowledgment.
     $allPayments = $payments = array();
 
@@ -521,7 +525,8 @@ GROUP BY  currency
           );
         }
         $payments[$payID] = array_merge($contributionValue,
-          array('amount' => CRM_Utils_Array::value('scheduled_amount', $values),
+          array(
+        'amount' => CRM_Utils_Array::value('scheduled_amount', $values),
             'due_date' => CRM_Utils_Array::value('scheduled_date', $values),
           )
         );
@@ -534,7 +539,6 @@ GROUP BY  currency
         }
       }
     }
-    //end
 
     //assign pledge fields value to template.
     $pledgeFields = array(
@@ -554,7 +558,8 @@ GROUP BY  currency
 
     //handle domain token values
     $domain = CRM_Core_BAO_Domain::getDomain();
-    $tokens = array('domain' => array('name', 'phone', 'address', 'email'),
+    $tokens = array(
+    'domain' => array('name', 'phone', 'address', 'email'),
       'contact' => CRM_Core_SelectValues::contactTokens(),
     );
     $domainValues = array();
@@ -684,13 +689,12 @@ GROUP BY  currency
   }
 
   /**
-   * combine all the exportable fields from the lower levels object
+   * Combine all the exportable fields from the lower levels object
    *
    * @return array array of exportable Fields
-   * @access public
    * @static
    */
-  static function &exportableFields() {
+  public static function &exportableFields() {
     if (!self::$_exportableFields) {
       if (!self::$_exportableFields) {
         self::$_exportableFields = array();
@@ -701,21 +705,23 @@ GROUP BY  currency
       $fields = array_merge($fields, CRM_Pledge_DAO_PledgePayment::export());
 
       //set title to calculated fields
-      $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')),
+      $calculatedFields = array(
+      'pledge_total_paid' => array('title' => ts('Total Paid')),
         'pledge_balance_amount' => array('title' => ts('Balance Amount')),
         'pledge_next_pay_date' => array('title' => ts('Next Payment Date')),
         'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')),
         'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')),
         'pledge_payment_paid_date' => array('title' => ts('Paid Date')),
-        'pledge_payment_status' => array('title' => ts('Pledge Payment Status'),
+        'pledge_payment_status' => array(
+      'title' => ts('Pledge Payment Status'),
           'name' => 'pledge_payment_status',
           'data_type' => CRM_Utils_Type::T_STRING,
         ),
       );
 
-
       $pledgeFields = array(
-        'pledge_status' => array('title' => 'Pledge Status',
+        'pledge_status' => array(
+      'title' => 'Pledge Status',
           'name' => 'pledge_status',
           'data_type' => CRM_Utils_Type::T_STRING,
         ),
@@ -747,14 +753,15 @@ GROUP BY  currency
   }
 
   /**
-   * Function to get pending or in progress pledges
+   * Get pending or in progress pledges
    *
-   * @param int $contactID contact id
+   * @param int $contactID
+   *   Contact id.
    *
    * @return array associated array of pledge id(s)
    * @static
    */
-  static function getContactPledges($contactID) {
+  public static function getContactPledges($contactID) {
     $pledgeDetails = array();
     $pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
 
@@ -791,23 +798,20 @@ GROUP BY  currency
   }
 
   /**
-   * Function to get pledge record count for a Contact
+   * Get pledge record count for a Contact
    *
-   * @param $contactID
-   *
-   * @internal param int $contactId Contact ID
+   * @param int $contactID
    *
    * @return int count of pledge records
-   * @access public
    * @static
    */
-  static function getContactPledgeCount($contactID) {
+  public static function getContactPledgeCount($contactID) {
     $query = "SELECT count(*) FROM civicrm_pledge WHERE civicrm_pledge.contact_id = {$contactID} AND civicrm_pledge.is_test = 0";
     return CRM_Core_DAO::singleValueQuery($query);
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @return array
    */
@@ -917,7 +921,8 @@ SELECT  pledge.contact_id              as contact_id,
     if ($sendReminders) {
       // retrieve domain tokens
       $domain = CRM_Core_BAO_Domain::getDomain();
-      $tokens = array('domain' => array('name', 'phone', 'address', 'email'),
+      $tokens = array(
+      'domain' => array('name', 'phone', 'address', 'email'),
         'contact' => CRM_Core_SelectValues::contactTokens(),
       );
 
@@ -1086,11 +1091,11 @@ SELECT  pledge.contact_id              as contact_id,
    * when no transactions have taken place - the editing process currently involves deleting all pledge payments & contributions
    * & recreating so we want to block that if appropriate
    *
-   * @param integer $pledgeID
-   * @param integer $pledgeStatusID
+   * @param int $pledgeID
+   * @param int $pledgeStatusID
    * @return bool do financial transactions exist for this pledge?
    */
-   static function pledgeHasFinancialTransactions($pledgeID, $pledgeStatusID) {
+  public static function pledgeHasFinancialTransactions($pledgeID, $pledgeStatusID) {
     if (empty($pledgeStatusID)) {
       //why would this happen? If we can see where it does then we can see if we should look it up
       //but assuming from form code it CAN be empty
@@ -1101,11 +1106,12 @@ SELECT  pledge.contact_id              as contact_id,
     }
 
     return civicrm_api3('pledge_payment', 'getcount', array('pledge_id' => $pledgeID, 'status_id' => array('IN' => self::getTransactionalStatus())));
-    }
+  }
 
   /**
    * Does this pledge / pledge payment status mean that a financial transaction has taken place?
-   * @param int $statusID pledge status id
+   * @param int $statusID
+   *   Pledge status id.
    *
    * @return bool is it a transactional status?
    */
@@ -1134,4 +1140,3 @@ SELECT  pledge.contact_id              as contact_id,
     return array_diff(array_flip($paymentStatus), self::getNonTransactionalStatus());
   }
 }
-