Cleanup phpdoc comments
[civicrm-core.git] / CRM / Pledge / BAO / Pledge.php
index f4c92d8478e6fbbfcc9ba2e0a6e2faeaca004b1a..4d027ee8b7bbf2ee0221457218f2d304b3dea45f 100644 (file)
@@ -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,7 +43,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   static $_exportableFields = NULL;
 
   /**
-   * class constructor
+   * Class constructor
    */
   function __construct() {
     parent::__construct();
@@ -59,7 +59,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
    * @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
+   * @return CRM_Pledge_BAO_Pledge object
    * @access public
    * @static
    */
@@ -74,7 +74,7 @@ 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
    *
@@ -139,11 +139,11 @@ 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
    *
-   * @return object CRM_Pledge_BAO_Pledge object
+   * @return CRM_Pledge_BAO_Pledge object
    * @access public
    * @static
    */
@@ -253,7 +253,7 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
   }
 
   /**
-   * Function to delete the pledge
+   * Delete the pledge
    *
    * @param int $id pledge id
    *
@@ -299,7 +299,13 @@ 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
+   * @param string $endDate
+   *
+   * @return array|null
    */
   static function getTotalAmountAndCount($status = NULL, $startDate = NULL, $endDate = NULL) {
     $where = array();
@@ -411,7 +417,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;
@@ -437,11 +442,11 @@ 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
    *
-   * @return return the list of pledge fields
+   * @return array return the list of pledge fields
    *
    * @access public
    * @static
@@ -482,10 +487,10 @@ 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.
+   * @param CRM_Core_Form $form form object.
+   * @param array $params an assoc array of name/value pairs.
    * @access public
    *
    * @return void.
@@ -528,7 +533,6 @@ GROUP BY  currency
         }
       }
     }
-    //end
 
     //assign pledge fields value to template.
     $pledgeFields = array(
@@ -612,7 +616,7 @@ GROUP BY  currency
       $receiptFrom = $params['from_email_id'];
     }
     elseif ($userID = $session->get('userID')) {
-      //check for loged in user.
+      //check for logged in user.
       list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     }
     else {
@@ -647,6 +651,7 @@ GROUP BY  currency
     );
     $config = CRM_Core_Config::singleton();
 
+    // FIXME: Translate
     $details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
 
     if (!$activity->find()) {
@@ -677,7 +682,7 @@ 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
@@ -740,7 +745,7 @@ GROUP BY  currency
   }
 
   /**
-   * Function to get pending or in progress pledges
+   * Get pending or in progress pledges
    *
    * @param int $contactID contact id
    *
@@ -784,11 +789,9 @@ 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
@@ -800,7 +803,7 @@ GROUP BY  currency
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @return array
    */
@@ -1073,5 +1076,58 @@ SELECT  pledge.contact_id              as contact_id,
     }
     return $paymentIDs;
   }
+
+  /**
+   * Is this pledge free from financial transactions (this is important to know as we allow editing
+   * 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?
+   */
+   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
+      return TRUE;
+    }
+    if (self::isTransactedStatus($pledgeStatusID)) {
+      return TRUE;
+    }
+
+    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
+   *
+   * @return bool is it a transactional status?
+   */
+  protected static function isTransactedStatus($statusID) {
+    if (!in_array($statusID, self::getNonTransactionalStatus())) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  /**
+   * Get array of non transactional statuses
+   * @return array non transactional status ids
+   */
+  protected static function getNonTransactionalStatus() {
+    $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+    return array_flip(array_intersect($paymentStatus, array('Overdue', 'Pending')));
+  }
+
+  /**
+   * Get array of non transactional statuses
+   * @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());
+  }
 }