Skip to content

Commit

Permalink
Merge pull request #27148 from eileenmcnaughton/fee_block
Browse files Browse the repository at this point in the history
Undefined property fix
  • Loading branch information
yashodha authored Aug 25, 2023
2 parents 33a70cb + 2e351b6 commit 3a85b8d
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
*
* @var int
*/
public $_paymentId = NULL;
public $_paymentId;

/**
* @var null
Expand Down Expand Up @@ -282,8 +282,6 @@ public function getDefaultContext(): string {
*/
public function preProcess() {
parent::preProcess();
$this->_showFeeBlock = $_GET['eventId'] ?? NULL;
$this->assign('showFeeBlock', FALSE);
$this->assign('feeBlockPaid', FALSE);

// @todo eliminate this duplication.
Expand Down Expand Up @@ -327,13 +325,14 @@ public function preProcess() {

$this->assign('participantMode', $this->_mode);

$this->assign('showFeeBlock', $this->_showFeeBlock);
if ($this->_showFeeBlock) {
$isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary');
if ($isMonetary) {
$isOverloadFeesMode = $this->isOverloadFeesMode();
$this->assign('showFeeBlock', $isOverloadFeesMode);
if ($isOverloadFeesMode) {
if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $_GET['eventId'], 'is_monetary')) {
$this->assign('feeBlockPaid', TRUE);
}
return CRM_Event_Form_EventFees::preProcess($this);
CRM_Event_Form_EventFees::preProcess($this);
return;
}

$this->assignUrlPath();
Expand Down Expand Up @@ -422,7 +421,7 @@ public function preProcess() {
* @throws \CRM_Core_Exception
*/
public function setDefaultValues(): array {
if ($this->_showFeeBlock) {
if ($this->isOverloadFeesMode()) {
return CRM_Event_Form_EventFees::setDefaultValues($this);
}

Expand Down Expand Up @@ -582,7 +581,7 @@ public function buildQuickForm() {
$partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
$this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);

if ($this->_showFeeBlock) {
if ($this->isOverloadFeesMode()) {
return $this->buildEventFeeForm($this);
}

Expand Down Expand Up @@ -626,7 +625,7 @@ public function buildQuickForm() {

if ($this->_single) {
$contactField = $this->addEntityRef('contact_id', ts('Participant'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE);
if ($this->_context != 'standalone') {
if ($this->_context !== 'standalone') {
$contactField->freeze();
}
}
Expand Down Expand Up @@ -828,7 +827,7 @@ public static function formRule($values, $files, $self) {
// For single additions - show validation error if the contact has already been registered
// for this event.
if (($self->_action & CRM_Core_Action::ADD)) {
if ($self->_context == 'standalone') {
if ($self->_context === 'standalone') {
$contactId = $values['contact_id'] ?? NULL;
}
else {
Expand Down Expand Up @@ -1215,7 +1214,7 @@ public function submit($params) {

foreach ($recordContribution as $f) {
$contributionParams[$f] = $this->_params[$f] ?? NULL;
if ($f == 'trxn_id') {
if ($f === 'trxn_id') {
$this->assign('trxn_id', $contributionParams[$f]);
}
}
Expand Down Expand Up @@ -1304,7 +1303,7 @@ public function submit($params) {
) {
foreach ($this->_contactIds as $num => $contactID) {
foreach ($this->_lineItem as $key => $value) {
if (is_array($value) && $value != 'skip') {
if (is_array($value) && $value !== 'skip') {
foreach ($value as $lineKey => $line) {
//10117 update the line items for participants if contribution amount is recorded
if ($this->isQuickConfig() && !empty($params['total_amount']) &&
Expand Down Expand Up @@ -2335,4 +2334,23 @@ public function isQuickConfig(): bool {
return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID());
}

/**
* Is the form being accessed in overload fees mode.
*
* Overload fees mode is when we are accessing the same form for a different
* purpose - to load the fees via ajax. We have historically fixed this for
* some forms by creating a new form class to move the functionality to and
* updating the path to call that (e.g CRM_Financial_Form_Payment was historically
* split in this way).
*
* This is much cleaner but the trap to be
* aware of is that the fields must be added to the quick form. It does require
* a bit of UI testing to do this. For now, adding comment...
*
* @return bool
*/
protected function isOverloadFeesMode(): bool {
return (bool) ($_GET['eventId'] ?? NULL);
}

}

0 comments on commit 3a85b8d

Please sign in to comment.