<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
* This class generates form components for processing a participation
* in an event
*/
-class CRM_Event_Form_Participant extends CRM_Contact_Form_Task {
+class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment {
public $useLivePageJS = TRUE;
/**
- * the values for the contribution db object
+ * The values for the contribution db object
*
* @var array
- * @protected
*/
public $_values;
/**
- * the values for the quickconfig for priceset
+ * The values for the quickconfig for priceset
*
* @var boolean
- * @protected
*/
public $_quickConfig = NULL;
* Price Set ID, if the new price set method is used
*
* @var int
- * @protected
*/
public $_priceSetId;
* Array of fields for the price set
*
* @var array
- * @protected
*/
public $_priceSet;
/**
- * the id of the participation that we are proceessing
+ * The id of the participation that we are proceessing
*
* @var int
- * @protected
*/
public $_id;
/**
- * the id of the note
+ * The id of the note
*
* @var int
- * @protected
*/
protected $_noteId = NULL;
/**
- * the id of the contact associated with this participation
+ * The id of the contact associated with this participation
*
* @var int
- * @protected
*/
public $_contactId;
/**
- * array of event values
+ * Array of event values
*
* @var array
- * @protected
*/
protected $_event;
protected $_eventTypeId = NULL;
/**
- * participant status Id
+ * Participant status Id
*/
protected $_statusId = NULL;
/**
- * cache all the participant statuses
+ * Cache all the participant statuses
*/
protected $_participantStatuses;
/**
- * participant mode
+ * Participant mode
*/
public $_mode = NULL;
/**
- * event ID preselect
+ * Event ID preselect
*/
public $_eID = NULL;
- /*
- *Line Item for Price Set
- */
-
+ /**
+ * Line Item for Price Set
+ */
public $_lineItem = NULL;
- /*
- *Contribution mode for event registration for offline mode
- */
+ /*
+ * Contribution mode for event registration for offline mode
+ */
public $_contributeMode = 'direct';
public $_online;
/**
- * store id of role custom data type ( option value )
+ * Store id of role custom data type ( option value )
*/
protected $_roleCustomDataTypeID;
/**
- * store id of event Name custom data type ( option value)
+ * Store id of event Name custom data type ( option value)
*/
protected $_eventNameCustomDataTypeID;
/**
- * selected discount id
+ * Selected discount id
*/
public $_originalDiscountId = NULL;
/**
- * event id
+ * Event id
*/
public $_eventId = NULL;
/**
- * id of payment, if any
+ * Id of payment, if any
*/
public $_paymentId = NULL;
public $_onlinePendingContributionId = NULL;
/**
- * Function to set variables up before form is built
+ * Set variables up before form is built
*
* @return void
- * @access public
*/
public function preProcess() {
$this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET);
if ($this->_mode) {
$this->assign('participantMode', $this->_mode);
-
- $this->_paymentProcessor = array('billing_mode' => 1);
-
- $validProcessors = array();
- $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
-
- foreach ($processors as $ppID => $label) {
- $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
- if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
- continue;
- }
- elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
- continue;
- }
- else {
- $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
- $error = $paymentObject->checkConfig();
- if (empty($error)) {
- $validProcessors[$ppID] = $label;
- }
- $paymentObject = NULL;
- }
- }
- if (empty($validProcessors)) {
- CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
- }
- else {
- $this->_processors = $validProcessors;
- }
- // also check for billing information
- // get the billing location type
- $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
- // CRM-8108 remove ts around Billing location type
- //$this->_bltID = array_search( ts('Billing'), $locationTypes );
- $this->_bltID = array_search('Billing', $locationTypes);
- if (!$this->_bltID) {
- CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
- }
- $this->set('bltID', $this->_bltID);
- $this->assign('bltID', $this->_bltID);
-
- $this->_fields = array();
-
- CRM_Core_Payment_Form::setCreditCardFields($this);
-
- // this required to show billing block
- $this->assign_by_ref('paymentProcessor', $paymentProcessor);
+ $this->assignPaymentRelatedVariables();
}
if ($this->_showFeeBlock) {
$this->_single = TRUE;
$this->assign('urlPath', 'civicrm/contact/view/participant');
if (!$this->_id && !$this->_contactId) {
- $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
+ $breadCrumbs = array(array(
+ 'title' => ts('CiviEvent Dashboard'),
'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'),
));
// check for edit permission
if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
- CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
+ CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
if ($this->_action & CRM_Core_Action::DELETE) {
* This function sets the default values for the form in edit/view mode
* the default values are retrieved from the database
*
- * @access public
*
* @return void
*/
$eventID = $_POST['event_id'];
}
- if($this->_eID) {
+ if ($this->_eID) {
$eventID = $this->_eID;
//@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
$roleID = CRM_Core_DAO::getFieldValue(
$this->_eID,
'default_role_id'
);
- if(empty($roleIDs)) {
+ if (empty($roleIDs)) {
$roleIDs = (array) $defaults[$this->_id]['participant_role_id'] = $roleID;
}
$defaults[$this->_id]['event_id'] = $eventID;
}
//these should take precedence so we state them last
$urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String');
- if($urlRoleIDS) {
+ if ($urlRoleIDS) {
$roleIDs = explode(',', $urlRoleIDS);
}
if (isset($roleIDs)) {
}
/**
- * Function to build the form
+ * Build the form object
*
* @return void
- * @access public
*/
public function buildQuickForm() {
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
TRUE
)) - 1;
if ($additionalParticipant) {
- $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
+ $deleteParticipants = array(
+ 1 => ts('Delete this participant record along with associated participant record(s).'),
2 => ts('Delete only this participant record.'),
);
$this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
return;
}
-
if ($this->_single && $this->_context == 'standalone') {
$this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
}
'select' => array('minimumInputLength' => 0),
'api' => array(
'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
- )
+ ),
);
if ($this->_mode) {
$notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
$this->assign('notificationStatusIds', $notificationStatusIds);
- $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
- $this->addSelect('status_id', $checkCancelledJs + array('option_url' => 'civicrm/admin/participant_status'), TRUE);
+ $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
- $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
- 'enable_cart'
- );
- $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
- $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
- $this->assign('enableCart', $enableCart);
- $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
- $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
+ // Only show refund status when editing
+ if ($this->_action & CRM_Core_Action::ADD) {
+ $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
+ if ($pendingRefundStatusId) {
+ unset($statusOptions[$pendingRefundStatusId]);
+ }
+ }
+
+ $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
$this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
$path = CRM_Utils_System::currentPath();
$excludeForPaths = array(
'civicrm/contact/search',
- 'civicrm/group/search'
+ 'civicrm/group/search',
);
if (!in_array($path, $excludeForPaths)) {
$buttons[] = array(
/**
* Add local and global form rules
*
- * @access protected
*
* @return void
*/
- function addRules() {
+ public function addRules() {
$this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
}
/**
- * global validation rules for the form
+ * Global validation rules for the form
*
- * @param $values
+ * @param array $values
+ * Posted values of the form.
* @param $files
* @param $self
*
- * @internal param array $fields posted values of the form
- *
* @return array list of errors to be posted back to the form
* @static
- * @access public
*/
- static function formRule($values, $files, $self) {
+ public static function formRule($values, $files, $self) {
// If $values['_qf_Participant_next'] is Delete or
// $values['event_id'] is empty, then return
// instead of proceeding further.
}
// For single additions - show validation error if the contact has already been registered
// for this event with the same role.
- if($self->_single && ($self->_action & CRM_Core_Action::ADD)) {
+ if ($self->_single && ($self->_action & CRM_Core_Action::ADD)) {
$contactId = $self->_contactId;
$eventId = CRM_Utils_Array::value('event_id', $values);
- if(!empty($contactId) && !empty($eventId)) {
+ if (!empty($contactId) && !empty($eventId)) {
$dupeCheck = new CRM_Event_BAO_Participant;
$dupeCheck->contact_id = $contactId;
$dupeCheck->event_id = $eventId;
$dupeCheck->find(TRUE);
- if(!empty($dupeCheck->id)) {
+ if (!empty($dupeCheck->id)) {
$errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
}
}
}
/**
- * Function to process the form
+ * Process the form submission
*
- * @access public
*/
public function postProcess() {
// get the submitted form values.
// removed automatically and the user receives one notification.
if ($this->_action & CRM_Core_Action::ADD) {
$event_id = $this->_eventId;
- if(empty($event_id) && !empty($params['event_id'])) {
+ if (empty($event_id) && !empty($params['event_id'])) {
$event_id = $params['event_id'];
}
- if(!$this->_single && !empty($event_id)) {
+ if (!$this->_single && !empty($event_id)) {
$duplicateContacts = 0;
- while(list($k,$dupeCheckContactId) = each($this->_contactIds)) {
+ while (list($k, $dupeCheckContactId) = each($this->_contactIds)) {
// Eliminate contacts that have already been assigned to this event.
$dupeCheck = new CRM_Event_BAO_Participant;
$dupeCheck->contact_id = $dupeCheckContactId;
$dupeCheck->event_id = $event_id;
$dupeCheck->find(TRUE);
- if(!empty($dupeCheck->id)) {
+ if (!empty($dupeCheck->id)) {
$duplicateContacts++;
unset($this->_contactIds[$k]);
}
}
- if($duplicateContacts > 0) {
+ if ($duplicateContacts > 0) {
$msg = ts(
"%1 contacts have already been assigned to this event. They were not added a second time.",
array(1 => $duplicateContacts)
);
CRM_Core_Session::setStatus($msg);
}
- if(count($this->_contactIds) == 0) {
+ if (count($this->_contactIds) == 0) {
CRM_Core_Session::setStatus(ts("No participants were added."));
return;
}
}
}
-
$participantStatus = CRM_Event_PseudoConstant::participantStatus();
// set the contact, when contact is selected
if (!empty($params['contact_id'])) {
if ($this->_quickConfig && !empty($params['total_amount']) &&
$params['status_id'] != array_search('Partially paid', $participantStatus)) {
$params['fee_amount'] = $params['total_amount'];
- } else {
+ }
+ else {
//fix for CRM-3086
$params['fee_amount'] = $params['amount'];
}
if (isset($participantCount)) {
$this->assign('pricesetFieldsCount', $participantCount);
}
- $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig? FALSE : $lineItem);
+ $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig ? FALSE : $lineItem);
}
else {
$this->assign('amount_level', $params['amount_level']);
$contributionParams['total_amount'] = CRM_Utils_Array::value('total_amount', $params);
}
-
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
// also add location name to the array
$params["address_name-{$this->_bltID}"] =
- CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
+ CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
CRM_Utils_Array::value('billing_middle_name', $params) . ' ' .
CRM_Utils_Array::value('billing_last_name', $params);
}
//do cleanup line items if participant edit the Event Fee.
- if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
+ if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
}
$payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
+ // CRM-15622: fix for incorrect contribution.fee_amount
+ $paymentParams['fee_amount'] = NULL;
$result = $payment->doDirectPayment($paymentParams);
if (is_a($result, 'CRM_Core_Error')) {
}
//CRM-15372 patch to fix fee amount replacing amount
- $this->_params['fee_amount'] = $this->_params['amount'];
+ $this->_params['fee_amount'] = $this->_params['amount'];
$participants[] = CRM_Event_Form_Registration::addParticipant($this, $contactID);
$contributionParams['non_deductible_amount'] = 'null';
$contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
- $recordContribution = array( 'contact_id', 'financial_type_id',
+ $recordContribution = array('contact_id', 'financial_type_id',
'payment_instrument_id', 'trxn_id',
'contribution_status_id', 'receive_date',
'check_number', 'campaign_id',
$feeLevel = $this->_params['amount_priceset_level_radio'];
}
else {
- $feeLevel[] = $this->_params['fee_level'] ;
+ $feeLevel[] = $this->_params['fee_level'];
}
CRM_Event_BAO_Participant::createDiscountTrxn($this->_eventId, $contributionParams, $feeLevel);
}
if (isset($contributionParams['partial_payment_total'])) {
// balance amount
$balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
- $this->assign('balanceAmount', $balanceAmount );
+ $this->assign('balanceAmount', $balanceAmount);
}
$this->assign('isPrimary', 1);
$this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
if ($this->_isPaidEvent) {
// fix amount for each of participants ( for bulk mode )
$eventAmount = array();
- $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings');
+ $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$totalTaxAmount = 0;
'valueName' => 'event_offline_receipt',
'contactId' => $contactID,
'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues),
- 'PDFFilename' => ts('confirmation').'.pdf',
+ 'PDFFilename' => ts('confirmation') . '.pdf',
);
// try to send emails only if email id is present
}
//send email with pdf invoice
- $template = CRM_Core_Smarty::singleton( );
+ $template = CRM_Core_Smarty::singleton();
$taxAmt = $template->get_template_vars('dataArray');
$contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
$this->_id, 'contribution_id', 'participant_id'
$prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
- $sendTemplateParams['isEmailPdf'] = True;
+ $sendTemplateParams['isEmailPdf'] = TRUE;
$sendTemplateParams['contributionId'] = $contributionId;
}
list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);