* Get contribution statuses by entity e.g. contribution, membership or 'participant'
*
* @param string $usedFor
- * @param int $id
+ * @param string $name
* Contribution ID
*
* @return array
* Array of contribution statuses in array('status id' => 'label') format
*/
- public static function getContributionStatuses($usedFor = 'contribution', $id = NULL) {
+ public static function getContributionStatuses($usedFor = 'contribution', $name = NULL) {
if ($usedFor === 'pledge') {
$statusNames = CRM_Pledge_BAO_Pledge::buildOptions('status_id', 'validate');
}
'Template',
];
// on create fetch statuses on basis of component
- if (!$id) {
+ if (!$name) {
$statusNamesToUnset = array_merge($statusNamesToUnset, [
'Refunded',
'Chargeback',
}
}
else {
- $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'contribution_status_id');
- $name = $statusNames[$contributionStatus] ?? NULL;
+
switch ($name) {
case 'Completed':
// [CRM-17498] Removing unsupported status change options.
+--------------------------------------------------------------------+
*/
+use Civi\Api4\Contribution;
use Civi\Payment\Exception\PaymentProcessorException;
/**
*/
public $submitOnce = TRUE;
+ /**
+ * Status of contribution prior to edit.
+ *
+ * @var string
+ */
+ protected $previousContributionStatus;
+
/**
* Explicitly declare the form context.
*/
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
+ * @throws \API_Exception
*/
public function buildQuickForm() {
if ($this->_id) {
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
- $component = 'contribution';
$componentDetails = [];
if ($this->_id) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
- if (!empty($componentDetails['membership'])) {
- $component = 'membership';
- }
- elseif (!empty($componentDetails['participant'])) {
- $component = 'participant';
- }
}
- if ($this->_ppID) {
- $component = 'pledge';
- }
- $status = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses($component, $this->_id);
+ $status = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('contribution', $this->getPreviousContributionStatus());
// define the status IDs that show the cancellation info, see CRM-17589
$cancelInfo_show_ids = [];
}
}
+ /**
+ * Get the contribution ID.
+ *
+ * @return int|null
+ */
+ protected function getContributionID(): ?int {
+ return $this->_id;
+ }
+
+ /**
+ * Get the selected contribution status.
+ *
+ * @return string
+ *
+ * @throws \API_Exception
+ */
+ protected function getPreviousContributionStatus(): string {
+ if (!$this->previousContributionStatus) {
+ $this->previousContributionStatus = Contribution::get(FALSE)
+ ->addWhere('id', '=', $this->getContributionID())
+ ->addSelect('contribution_status_id:name')
+ ->execute()
+ ->first()['contribution_status_id:name'];
+ }
+ return $this->previousContributionStatus;
+ }
+
}