Skip to content

Commit

Permalink
Merge pull request #18464 from eileenmcnaughton/urlparamms
Browse files Browse the repository at this point in the history
[REF] Start the process of separating the search action from the participant form
  • Loading branch information
monishdeb authored Sep 16, 2020
2 parents b520b57 + 8535cf1 commit 86517dd
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static function tasks() {
if (CRM_Core_Permission::access('CiviEvent')) {
self::$_tasks[self::ADD_EVENT] = array(
'title' => ts('Register participants for event'),
'class' => 'CRM_Event_Form_Participant',
'class' => 'CRM_Event_Form_Task_Register',
);
}

Expand Down
3 changes: 2 additions & 1 deletion CRM/Event/Form/EventFees.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public static function setDefaultValues(&$form) {
if (in_array(get_class($form),
[
'CRM_Event_Form_Participant',
'CRM_Event_Form_Task_Register',
'CRM_Event_Form_Registration_Register',
'CRM_Event_Form_Registration_AdditionalParticipant',
]
Expand All @@ -173,7 +174,7 @@ public static function setDefaultValues(&$form) {
foreach ($form->_priceSet['fields'] as $key => $val) {
foreach ($val['options'] as $keys => $values) {
if ($values['is_default']) {
if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) {
if (!in_array(get_class($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register']) && !empty($values['is_full'])) {
continue;
}

Expand Down
11 changes: 6 additions & 5 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment

/**
* Are we operating in "single mode", i.e. adding / editing only
* one participant record, or is this a batch add operation
* one participant record, or is this a batch add operation.
*
* Note the goal is to disentangle all the non-single stuff
* to CRM_Event_Form_Task_Register and discontinue this param.
*
* @var bool
*/
public $_single = FALSE;
public $_single = TRUE;

/**
* If event is paid or unpaid.
Expand Down Expand Up @@ -337,8 +340,7 @@ public function preProcess() {

//check the mode when this form is called either single or as
//search task action
if ($this->_id || $this->_contactId || $this->_context == 'standalone') {
$this->_single = TRUE;
if ($this->_single) {
$this->assign('urlPath', 'civicrm/contact/view/participant');
if (!$this->_id && !$this->_contactId) {
$breadCrumbs = [
Expand Down Expand Up @@ -379,7 +381,6 @@ public function preProcess() {
}
CRM_Contact_Form_Task::preProcessCommon($this);

$this->_single = FALSE;
$this->_contactId = NULL;

//set ajax path, this used for custom data building
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public static function initEventFee(&$form, $eventID, $includeExpiredFields = TR
}
}
if ($isPaidEvent && empty($form->_values['fee'])) {
if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') {
if (!in_array(CRM_Utils_System::getClassName($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register'])) {
CRM_Core_Error::statusBounce(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', [1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)]));
}
}
Expand Down
7 changes: 4 additions & 3 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
(CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) ||
$className == 'CRM_Event_Form_Participant' ||
$className === 'CRM_Event_Form_Task_Register' ||
$className == 'CRM_Event_Form_ParticipantFeeSelection'
) {
$fieldId = $field['id'];
Expand All @@ -589,7 +590,7 @@ public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)

//user might modified w/ hook.
$options = $field['options'] ?? NULL;
$formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_ParticipantFeeSelection'];
$formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register', 'CRM_Event_Form_ParticipantFeeSelection'];

if (!is_array($options)) {
continue;
Expand Down Expand Up @@ -636,7 +637,7 @@ public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)

//CRM-7632, CRM-6201
$totalAmountJs = NULL;
if ($className == 'CRM_Event_Form_Participant') {
if ($className == 'CRM_Event_Form_Participant' || $className === 'CRM_Event_Form_Task_Register') {
$totalAmountJs = ['onClick' => "fillTotalAmount(" . $fee['value'] . ")"];
}

Expand Down Expand Up @@ -755,7 +756,7 @@ public static function formatFieldsForOptionFull(&$form) {
}

//ignore option full for offline registration.
if ($className == 'CRM_Event_Form_Participant') {
if ($className == 'CRM_Event_Form_Participant' || $className === 'CRM_Event_Form_Task_Register') {
$optionFullIds = [];
}

Expand Down
40 changes: 40 additions & 0 deletions CRM/Event/Form/Task/Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* This class provides the register functionality from a search context.
*
* Originally the functionality was all munged into the main Participant form.
*
* Ideally it would be entirely separated but for now this overrides the main form,
* just providing a better separation of the functionality for the search vs main form.
*/
class CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant {


/**
* Are we operating in "single mode", i.e. adding / editing only
* one participant record, or is this a batch add operation
*
* ote the goal is to disentangle all the non-single stuff
* into this form and discontinue this param.
*
* @var bool
*/
public $_single = FALSE;

}
2 changes: 1 addition & 1 deletion CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public static function initSet(&$form, $entityTable = 'civicrm_event', $validOnl
switch ($entityTable) {
case 'civicrm_event':
$entity = 'participant';
if (CRM_Utils_System::getClassName($form) == 'CRM_Event_Form_Participant') {
if (in_array(CRM_Utils_System::getClassName($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register'])) {
$entityId = $form->_id;
}
else {
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/CRM/Event/Form/Task/RegisterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Test CRM_Event_Form_Registration functions.
*
* @package CiviCRM
* @group headless
*/
class CRM_Event_Form_Task_RegisterTest extends CiviUnitTestCase {

/**
* Initial test of form class.
*
* @throws \CRM_Core_Exception
*/
public function testGet() {
/* @var CRM_Event_Form_Task_Register $form */
$form = $this->getFormObject('CRM_Event_Form_Task_Register');
$this->assertEquals(FALSE, $form->_single);
}

}

0 comments on commit 86517dd

Please sign in to comment.