* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\API\EntityLookupTrait;
+
/**
* Back office participant form.
*/
class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment {
+ use EntityLookupTrait;
+
/**
* Participant ID - use getParticipantID.
*
$this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
$this->assign('context', $this->_context);
- if ($this->_contactID) {
- $this->setPageTitle(ts('Event Registration for %1', [1 => $this->userDisplayName]));
+ if ($this->getContactID()) {
+ $this->setPageTitle(ts('Event Registration for %1', [1 => $this->getContactValue('display_name')]));
}
else {
$this->setPageTitle(ts('Event Registration'));
return $defaults[$this->_id];
}
+ /**
+ * Get a value for the contact being acted on in the form.
+ *
+ * This can be called from any point in the form flow and if
+ * the contact can not yet be determined it will return NULL.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function getContactValue($fieldName) {
+ if ($this->isDefined('Contact')) {
+ return $this->lookup('Contact', $fieldName);
+ }
+ if ($this->getContactID()) {
+ $this->define('Contact', 'Contact', ['id' => $this->getContactID()]);
+ return $this->lookup('Contact', $fieldName);
+ }
+ return NULL;
+ }
+
/**
* Build the form object.
*
$userName = CRM_Core_Session::singleton()->getLoggedInContactDisplayName();
if ($this->_contactId) {
- [$this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
+ [, $this->_contributorEmail, $this->_toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
}
//modify params according to parameter used in create
protected function getStatusMsg(array $params, int $numberSent, int $numberNotSent, string $updateStatusMsg): string {
$statusMsg = '';
if (($this->_action & CRM_Core_Action::UPDATE)) {
- $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contributorDisplayName]);
+ $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->getContactValue('display_name')]);
if (!empty($params['send_receipt']) && $numberSent) {
- $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', [1 => $this->_contributorEmail]);
+ $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', [1 => $this->getContactValue('email_primary.email')]);
}
if ($updateStatusMsg) {
}
}
elseif ($this->_action & CRM_Core_Action::ADD) {
- $statusMsg = ts('Event registration for %1 has been added.', [1 => $this->_contributorDisplayName]);
+ $statusMsg = ts('Event registration for %1 has been added.', [1 => $this->getContactValue('display_name')]);
if (!empty($params['send_receipt']) && $numberSent) {
- $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $this->_contributorEmail]);
+ $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $this->getContactValue('email_primary.email')]);
}
}
return $statusMsg;
$form->add('textarea', 'receipt_text', ts('Confirmation Message'));
// Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
- if ($form->_context != 'standalone') {
- if ($form->_contactId) {
- [$form->_contributorDisplayName, $form->_contributorEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
+ if ($form->_context !== 'standalone') {
+ if ($form->getContactID()) {
+ [, $form->_contributorEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
$form->assign('email', $form->_contributorEmail);
}
else {
foreach ($this->_contactIds as $num => $contactID) {
// Retrieve the name and email of the contact - this will be the TO for receipt email
- [$this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($contactID);
+ [, $this->_contributorEmail, $this->_toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($contactID);
$waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
$waitingStatus = $waitStatus[$params['status_id']] ?? NULL;
// and the do-not-email option is not checked for that contact
if ($this->_contributorEmail and !$this->_toDoNotEmail) {
$sendTemplateParams['from'] = $params['from_email_address'];
- $sendTemplateParams['toName'] = $this->_contributorDisplayName;
+ $sendTemplateParams['toName'] = $this->getContactValue('display_name');
$sendTemplateParams['toEmail'] = $this->_contributorEmail;
$sendTemplateParams['cc'] = $this->_fromEmails['cc'] ?? NULL;
$sendTemplateParams['bcc'] = $this->_fromEmails['bcc'] ?? NULL;
return (bool) ($_GET['eventId'] ?? NULL);
}
+ /**
+ * Get the contact ID in use.
+ *
+ * Ideally override this as appropriate to the form.
+ *
+ * @noinspection PhpUnhandledExceptionInspection
+ * @noinspection PhpDocSignatureIsNotCompleteInspection
+ */
+ public function getContactID():?int {
+ if ($this->_contactID === NULL) {
+ if ($this->getSubmittedValue('contact_id')) {
+ $contactID = $this->getSubmittedValue('contact_id');
+ }
+ else {
+ $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
+ }
+ if (!$contactID && $this->getParticipantID()) {
+ $contactID = $this->getParticipantValue('contact_id');
+ }
+ $this->_contactID = $contactID ? (int) $contactID : NULL;
+ }
+ return $this->_contactID;
+ }
+
}