INFRA-132 - Docblock @param and @return tag fixes
[civicrm-core.git] / CRM / Pledge / BAO / Pledge.php
index 8fc4197c12f2879c6612191f4899531bdd81d3a2..4726b23a79f37c8825491620554477860a602779 100644 (file)
@@ -56,11 +56,12 @@ 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 CRM_Pledge_BAO_Pledge object
-   * @access public
    * @static
    */
   public static function retrieve(&$params, &$defaults) {
@@ -76,9 +77,9 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_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
@@ -122,12 +123,15 @@ 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
+   * @return array
+   *   associated array of field values
    * @static
    */
   public static function &getValues(&$params, &$values, $returnProperties = NULL) {
@@ -141,10 +145,10 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   /**
    * 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 CRM_Pledge_BAO_Pledge object
-   * @access public
    * @static
    */
   public static function &create(&$params) {
@@ -200,7 +204,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);
@@ -209,8 +212,16 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
       //building payment params
       $paymentParams['pledge_id'] = $pledge->id;
       $paymentKeys = array(
-        'amount', 'installments', 'scheduled_date', 'frequency_unit', 'currency',
-        'frequency_day', 'frequency_interval', 'contribution_id', 'installment_amount', 'actual_amount',
+        'amount',
+        'installments',
+        'scheduled_date',
+        'frequency_unit',
+        'currency',
+        'frequency_day',
+        'frequency_interval',
+        'contribution_id',
+        'installment_amount',
+        'actual_amount',
       );
       foreach ($paymentKeys as $key) {
         $paymentParams[$key] = CRM_Utils_Array::value($key, $params, NULL);
@@ -255,12 +266,11 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   /**
    * Delete the pledge
    *
-   * @param int $id pledge id
+   * @param int $id
+   *   Pledge id.
    *
    * @return mixed
-   * @access public
    * @static
-   *
    */
   public static function deletePledge($id) {
     CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray);
@@ -280,7 +290,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
       $payment->delete();
     }
 
-    $dao     = new CRM_Pledge_DAO_Pledge();
+    $dao = new CRM_Pledge_DAO_Pledge();
     $dao->id = $id;
     $results = $dao->delete();
 
@@ -352,17 +362,18 @@ FROM   civicrm_pledge
 WHERE  $whereCond AND is_test=0
 GROUP BY  currency
 ";
-    $start   = substr($startDate, 0, 8);
-    $end     = substr($endDate, 0, 8);
-    $pCount  = 0;
+    $start = substr($startDate, 0, 8);
+    $end = substr($endDate, 0, 8);
+    $pCount = 0;
     $pamount = array();
-    $dao     = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+    $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     while ($dao->fetch()) {
       $pCount += $dao->pledge_count;
       $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"
@@ -373,31 +384,31 @@ GROUP BY  currency
     $statusId = array_search($status, $allStatus);
     switch ($status) {
       case 'Completed':
-        $select    = 'sum( total_amount ) as received_pledge , count( cd.id ) as received_count';
-        $where[]   = 'cp.status_id = ' . $statusId . ' AND cp.contribution_id = cd.id AND cd.is_test=0';
+        $select = 'sum( total_amount ) as received_pledge , count( cd.id ) as received_count';
+        $where[] = 'cp.status_id = ' . $statusId . ' AND cp.contribution_id = cd.id AND cd.is_test=0';
         $queryDate = 'receive_date';
-        $from      = ' civicrm_contribution cd, civicrm_pledge_payment cp';
+        $from = ' civicrm_contribution cd, civicrm_pledge_payment cp';
         break;
 
       case 'Cancelled':
-        $select    = 'sum( total_amount ) as received_pledge , count( cd.id ) as received_count';
-        $where[]   = 'cp.status_id = ' . $statusId . ' AND cp.contribution_id = cd.id AND cd.is_test=0';
+        $select = 'sum( total_amount ) as received_pledge , count( cd.id ) as received_count';
+        $where[] = 'cp.status_id = ' . $statusId . ' AND cp.contribution_id = cd.id AND cd.is_test=0';
         $queryDate = 'receive_date';
-        $from      = ' civicrm_contribution cd, civicrm_pledge_payment cp';
+        $from = ' civicrm_contribution cd, civicrm_pledge_payment cp';
         break;
 
       case 'Pending':
-        $select    = 'sum( scheduled_amount )as received_pledge , count( cp.id ) as received_count';
-        $where[]   = 'cp.status_id = ' . $statusId . ' AND pledge.is_test=0';
+        $select = 'sum( scheduled_amount )as received_pledge , count( cp.id ) as received_count';
+        $where[] = 'cp.status_id = ' . $statusId . ' AND pledge.is_test=0';
         $queryDate = 'scheduled_date';
-        $from      = ' civicrm_pledge_payment cp INNER JOIN civicrm_pledge pledge on cp.pledge_id = pledge.id';
+        $from = ' civicrm_pledge_payment cp INNER JOIN civicrm_pledge pledge on cp.pledge_id = pledge.id';
         break;
 
       case 'Overdue':
-        $select    = 'sum( scheduled_amount ) as received_pledge , count( cp.id ) as received_count';
-        $where[]   = 'cp.status_id = ' . $statusId . ' AND pledge.is_test=0';
+        $select = 'sum( scheduled_amount ) as received_pledge , count( cp.id ) as received_count';
+        $where[] = 'cp.status_id = ' . $statusId . ' AND pledge.is_test=0';
         $queryDate = 'scheduled_date';
-        $from      = ' civicrm_pledge_payment cp INNER JOIN civicrm_pledge pledge on cp.pledge_id = pledge.id';
+        $from = ' civicrm_pledge_payment cp INNER JOIN civicrm_pledge pledge on cp.pledge_id = pledge.id';
         break;
     }
 
@@ -417,9 +428,9 @@ GROUP BY  currency
  GROUP BY  cp.currency
 ";
     if ($select) {
-      $dao    = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+      $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
       $amount = array();
-      $count  = 0;
+      $count = 0;
 
       while ($dao->fetch()) {
         $count += $dao->received_count;
@@ -427,12 +438,13 @@ GROUP BY  currency
       }
 
       if ($count) {
-        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"
-            ),
-          ));
+        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"
+          ),
+        ));
       }
     }
     else {
@@ -444,11 +456,12 @@ GROUP BY  currency
   /**
    * 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
+   * @return array
+   *   return the list of pledge fields
    *
-   * @access public
    * @static
    */
   public static function getHonorContacts($honorId) {
@@ -489,11 +502,12 @@ GROUP BY  currency
   /**
    * Send Acknowledgment and create activity.
    *
-   * @param CRM_Core_Form $form form object.
-   * @param array $params 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.
+   * @return void
    */
   public static function sendAcknowledgment(&$form, $params) {
     //handle Acknowledgment.
@@ -520,7 +534,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),
           )
         );
@@ -528,7 +543,8 @@ GROUP BY  currency
         //get the first valid payment id.
         if (!isset($form->paymentId) && ($paymentStatusTypes[$values['status_id']] == 'Pending' ||
             $paymentStatusTypes[$values['status_id']] == 'Overdue'
-          )) {
+          )
+        ) {
           $form->paymentId = $values['id'];
         }
       }
@@ -536,8 +552,14 @@ GROUP BY  currency
 
     //assign pledge fields value to template.
     $pledgeFields = array(
-      'create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit',
-      'installments', 'frequency_day', 'scheduled_amount', 'currency',
+      'create_date',
+      'total_pledge_amount',
+      'frequency_interval',
+      'frequency_unit',
+      'installments',
+      'frequency_day',
+      'scheduled_amount',
+      'currency',
     );
     foreach ($pledgeFields as $field) {
       if (!empty($params[$field])) {
@@ -552,7 +574,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();
@@ -579,9 +602,9 @@ GROUP BY  currency
 
     //handle custom data.
     if (!empty($params['hidden_custom'])) {
-      $groupTree    = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
+      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
       $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
-      $customGroup  = array();
+      $customGroup = array();
       // retrieve custom data
       foreach ($groupTree as $groupID => $group) {
         $customFields = $customValues = array();
@@ -604,7 +627,7 @@ GROUP BY  currency
     //handle acknowledgment email stuff.
     list($pledgerDisplayName,
       $pledgerEmail
-    ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
+      ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
 
     //check for online pledge.
     $session = CRM_Core_Session::singleton();
@@ -684,8 +707,8 @@ GROUP BY  currency
   /**
    * Combine all the exportable fields from the lower levels object
    *
-   * @return array array of exportable Fields
-   * @access public
+   * @return array
+   *   array of exportable Fields
    * @static
    */
   public static function &exportableFields() {
@@ -699,21 +722,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,9 +772,11 @@ GROUP BY  currency
   /**
    * Get pending or in progress pledges
    *
-   * @param int $contactID contact id
+   * @param int $contactID
+   *   Contact id.
    *
-   * @return array associated array of pledge id(s)
+   * @return array
+   *   associated array of pledge id(s)
    * @static
    */
   public static function getContactPledges($contactID) {
@@ -760,7 +787,10 @@ GROUP BY  currency
 
     //get pending and in progress status
     foreach (array(
-      'Pending', 'In Progress', 'Overdue') as $name) {
+               'Pending',
+               'In Progress',
+               'Overdue'
+             ) as $name) {
       if ($statusId = array_search($name, $pledgeStatuses)) {
         $status[] = $statusId;
       }
@@ -793,8 +823,8 @@ GROUP BY  currency
    *
    * @param int $contactID
    *
-   * @return int count of pledge records
-   * @access public
+   * @return int
+   *   count of pledge records
    * @static
    */
   public static function getContactPledgeCount($contactID) {
@@ -817,7 +847,10 @@ GROUP BY  currency
 
     //unset statues that we never use for pledges
     foreach (array(
-      'Completed', 'Cancelled', 'Failed') as $statusKey) {
+               'Completed',
+               'Cancelled',
+               'Failed'
+             ) as $statusKey) {
       if ($key = CRM_Utils_Array::key($statusKey, $allStatus)) {
         unset($allStatus[$key]);
       }
@@ -890,7 +923,8 @@ SELECT  pledge.contact_id              as contact_id,
 
       if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($dao->scheduled_date, '%Y%m%d'),
           $now
-        ) && $dao->payment_status != array_search('Overdue', $allStatus)) {
+        ) && $dao->payment_status != array_search('Overdue', $allStatus)
+      ) {
         $pledgePayments[$dao->pledge_id][$dao->payment_id] = $dao->payment_id;
       }
     }
@@ -913,7 +947,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(),
       );
 
@@ -1057,7 +1092,8 @@ SELECT  pledge.contact_id              as contact_id,
    * Find payments which can be safely canceled.
    *
    * @param int $pledgeID
-   * @return array of int (civicrm_pledge_payment.id)
+   * @return array
+   *   of int (civicrm_pledge_payment.id)
    */
   public static function findCancelablePayments($pledgeID) {
     $statuses = array_flip(CRM_Contribute_PseudoConstant::contributionStatus());
@@ -1082,11 +1118,12 @@ 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
-   * @return bool do financial transactions exist for this pledge?
+   * @param int $pledgeID
+   * @param int $pledgeStatusID
+   * @return bool
+   *   do financial transactions exist for this pledge?
    */
-   public 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
@@ -1096,14 +1133,19 @@ SELECT  pledge.contact_id              as contact_id,
       return TRUE;
     }
 
-    return civicrm_api3('pledge_payment', 'getcount', array('pledge_id' => $pledgeID, 'status_id' => array('IN' => self::getTransactionalStatus())));
-    }
+    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?
+   * @return bool
+   *   is it a transactional status?
    */
   protected static function isTransactedStatus($statusID) {
     if (!in_array($statusID, self::getNonTransactionalStatus())) {
@@ -1114,7 +1156,8 @@ SELECT  pledge.contact_id              as contact_id,
 
   /**
    * Get array of non transactional statuses
-   * @return array non transactional status ids
+   * @return array
+   *   non transactional status ids
    */
   protected static function getNonTransactionalStatus() {
     $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
@@ -1123,11 +1166,11 @@ SELECT  pledge.contact_id              as contact_id,
 
   /**
    * Get array of non transactional statuses
-   * @return array non transactional status ids
+   * @return array
+   *   non transactional status ids
    */
   protected static function getTransactionalStatus() {
     $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     return array_diff(array_flip($paymentStatus), self::getNonTransactionalStatus());
   }
 }
-