/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Event/BAO/Participant.php'; $values = $ids = array(); $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true); $params = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($params, $values, $ids); if (empty($values)) { require_once 'CRM/Core/Error.php'; CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).')); } CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]); if (CRM_Utils_Array::value('fee_level', $values[$participantID])) { CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']); } if ($values[$participantID]['is_test']) { $values[$participantID]['status'] .= ' (test) '; } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant'); $values[$participantID]['note'] = array_values($noteValue); require_once 'CRM/Price/BAO/LineItem.php'; // Get Line Items $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID); if (!CRM_Utils_System::isNull($lineItem)) { $values[$participantID]['lineItem'][] = $lineItem; } $values[$participantID]['totalAmount'] = $values[$participantID]['fee_amount']; // get the option value for custom data type $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); $roleGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $values[$participantID]['role_id'], $roleCustomDataTypeID); $eventGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $values[$participantID]['event_id'], $eventNameCustomDataTypeID); $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id'); $eventTypeGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $eventTypeID, $eventTypeCustomDataTypeID); $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID)); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $this->assign($values[$participantID]); // add viewed participant to recent items list require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title'); $displayName = CRM_Contact_BAO_Contact::displayName($contactID); $this->assign('displayName', $displayName); $title = $displayName . ' (' . $participantRoles[$values[$participantID]['role_id']] . ' - ' . $eventTitle . ')'; // add Participant to Recent Items CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], null); }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $values = $ids = array(); $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $params = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($params, $values, $ids); if (empty($values)) { CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).')); } CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]); if (!empty($values[$participantID]['fee_level'])) { CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']); } $this->assign('contactId', $contactID); $this->assign('participantId', $participantID); $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $participantID, 'id', 'participant_id'); $this->assign('hasPayment', $paymentId); if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'registered_by_id')) { $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $parentParticipantId, 'id', 'participant_id'); $this->assign('parentHasPayment', $parentHasPayment); } $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id'); $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id'); $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id'); if ($status == 'Transferred') { $transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id'); $pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id'); $transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId)); $this->assign('pid', $pid); $this->assign('transferId', $transferId); $this->assign('transferName', $transferName); } $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); if ($values[$participantID]['is_test']) { $values[$participantID]['status'] .= ' (test) '; } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant'); $values[$participantID]['note'] = array_values($noteValue); // Get Line Items $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID); if (!CRM_Utils_System::isNull($lineItem)) { $values[$participantID]['lineItem'][] = $lineItem; } $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]); // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) if (!empty($values[$participantID]['participant_registered_by_id'])) { $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $values[$participantID]['participant_registered_by_id'], 'contact_id', 'id'); $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']); } // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) { $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID); } // get the option value for custom data type $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']); $groupTree = array(); $finalTree = array(); foreach ($allRoleIDs as $k => $v) { $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID); $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $values[$participantID]['event_id'], $eventNameCustomDataTypeID); $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id'); $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID); $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID)); foreach ($groupTree as $treeId => $trees) { $finalTree[$treeId] = $trees; } } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title'); //CRM-7150, show event name on participant view even if the event is disabled if (empty($values[$participantID]['event'])) { $values[$participantID]['event'] = $eventTitle; } //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values[$participantID]['campaign'] = $campaigns[$campaignId]; } $this->assign($values[$participantID]); // add viewed participant to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::check('edit event participants')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } if (CRM_Core_Permission::check('delete in CiviEvent')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } $participantRoles = CRM_Event_PseudoConstant::participantRole(); $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']); $participantCount = array(); $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $totalTaxAmount = 0; foreach ($lineItem as $k => $v) { if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) { $participantCount[] = $lineItem[$k]['participant_count']; } $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount; } if ($invoicing) { $this->assign('totalTaxAmount', $totalTaxAmount); } if ($participantCount) { $this->assign('pricesetFieldsCount', $participantCount); } $this->assign('displayName', $displayName); // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName); $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]); $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')'; $sep = CRM_Core_DAO::VALUE_SEPARATOR; $viewRoles = array(); foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values[$participantID]['role_id'] = implode(', ', $viewRoles); $this->assign('role', $values[$participantID]['role_id']); // add Participant to Recent Items CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], NULL, $recentOther); }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::setDefaultValues($this); } $defaults = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_id) { $ids = array(); $params = array('id' => $this->_id); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $sep = CRM_Core_DAO::VALUE_SEPARATOR; if ($defaults[$this->_id]['role_id']) { $roleIDs = explode($sep, $defaults[$this->_id]['role_id']); } $this->_contactId = $defaults[$this->_id]['contact_id']; $this->_statusId = $defaults[$this->_id]['participant_status_id']; //set defaults for note $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant'); $defaults[$this->_id]['note'] = array_pop($noteDetails); // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id)); } // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) if (!empty($defaults[$this->_id]['participant_registered_by_id'])) { $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id'); $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']); $this->assign('registered_by_contact_id', $registered_by_contact_id); $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id)); } } if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) { $inactiveNeeded = TRUE; $viewMode = TRUE; } else { $viewMode = FALSE; $inactiveNeeded = FALSE; } //setting default register date if ($this->_action == CRM_Core_Action::ADD) { $statuses = array_flip($this->_participantStatuses); $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses); if (!empty($defaults[$this->_id]['event_id'])) { $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'financial_type_id'); if ($contributionTypeId) { $defaults[$this->_id]['financial_type_id'] = $contributionTypeId; } } if ($this->_mode) { $fields["email-{$this->_bltID}"] = 1; $fields['email-Primary'] = 1; if ($this->_contactId) { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults); } if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults['email-Primary'])) { $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary']; } } $submittedRole = $this->getElementValue('role_id'); if (!empty($submittedRole[0])) { $roleID = $submittedRole[0]; } $submittedEvent = $this->getElementValue('event_id'); if (!empty($submittedEvent[0])) { $eventID = $submittedEvent[0]; } } else { $defaults[$this->_id]['record_contribution'] = 0; if ($defaults[$this->_id]['participant_is_pay_later']) { $this->assign('participant_is_pay_later', TRUE); } $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']); $eventID = $defaults[$this->_id]['event_id']; $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id'); if ($this->_discountId) { $this->set('discountId', $this->_discountId); } } list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime'); //assign event and role id, this is needed for Custom data building $sep = CRM_Core_DAO::VALUE_SEPARATOR; if (!empty($defaults[$this->_id]['participant_role_id'])) { $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']); } if (isset($_POST['event_id'])) { $eventID = $_POST['event_id']; } 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('CRM_Event_DAO_Event', $this->_eID, 'default_role_id'); if (empty($roleIDs)) { $roleIDs = (array) ($defaults[$this->_id]['participant_role_id'] = $roleID); } $defaults[$this->_id]['event_id'] = $eventID; } if (!empty($eventID)) { $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); } //these should take precedence so we state them last $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String'); if ($urlRoleIDS) { $roleIDs = explode(',', $urlRoleIDS); } if (isset($roleIDs)) { $defaults[$this->_id]['role_id'] = implode(',', $roleIDs); } if (isset($eventID)) { $this->assign('eventID', $eventID); $this->set('eventId', $eventID); } if (isset($this->_eventTypeId)) { $this->assign('eventTypeID', $this->_eventTypeId); } $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id])); return $defaults[$this->_id]; }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * * @param CRM_Core_Form $form * * @return void */ public static function setDefaultValues(&$form) { $defaults = array(); if ($form->_eventId) { //get receipt text and financial type $returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date'); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); if (!empty($details[$form->_eventId]['financial_type_id'])) { $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id']; } } if ($form->_pId) { $ids = array(); $params = array('id' => $form->_pId); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); if ($form->_action == CRM_Core_Action::UPDATE) { $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { $value = current($value); $discounts[$key] = $value['name']; } } if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) { $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]); } $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId])); } $defaults[$form->_pId]['send_receipt'] = 0; } else { $defaults[$form->_pId]['send_receipt'] = strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time() ? 1 : 0; if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) { //set receipt text $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text']; } list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults(); } //CRM-11601 we should keep the record contribution //true by default while adding participant if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) { $defaults[$form->_pId]['record_contribution'] = 1; } //CRM-13420 if (empty($defaults['payment_instrument_id'])) { $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } if ($form->_mode) { $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) { $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry; } if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) { $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince; } $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId); $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults); // // hack to simplify credit card entry for testing // $defaults[$form->_pId]['credit_card_type'] = 'Visa'; // $defaults[$form->_pId]['credit_card_number'] = '4807731747657838'; // $defaults[$form->_pId]['cvv2'] = '000'; // $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' ); } // if user has selected discount use that to set default if (isset($form->_discountId)) { $defaults[$form->_pId]['discount_id'] = $form->_discountId; //hack to set defaults for already selected discount value if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; if ($form->_originalDiscountId) { $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; } } $discountId = $form->_discountId; } else { $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); } else { $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId); } if ($form->_action == CRM_Core_Action::ADD && $form->_eventId && $discountId) { // this case is for add mode, where we show discount automatically $defaults[$form->_pId]['discount_id'] = $discountId; } if ($priceSetId) { // get price set default values, CRM-4090 if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) { $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId); if (!empty($priceSetValues)) { $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues); } } if ($form->_action == CRM_Core_Action::ADD && !empty($form->_priceSet['fields'])) { 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'])) { continue; } if ($val['html_type'] == 'CheckBox') { $defaults[$form->_pId]["price_{$key}"][$keys] = 1; } else { $defaults[$form->_pId]["price_{$key}"] = $keys; } } } } } $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); if ($form->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$form->_pId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $form->assign('fee_level', $fee_level); $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); } } //CRM-4453 if (!empty($defaults[$form->_pId]['participant_fee_currency'])) { $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']); } // CRM-4395 if ($contriId = $form->get('onlinePendingContributionId')) { $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->id = $contriId; $contribution->find(TRUE); foreach (array('financial_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) { if ($f == 'receive_date') { list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f}); } else { $defaults[$form->_pId][$f] = $contribution->{$f}; } } } return $defaults[$form->_pId]; }
/** * Function to record additional payment for partial and refund contributions. * * @param int $contributionId * is the invoice contribution id (got created after processing participant payment). * @param array $trxnsData * to take user provided input of transaction details. * @param string $paymentType * 'owed' for purpose of recording partial payments, 'refund' for purpose of recording refund payments. * @param int $participantId * * @return null|object */ public static function recordAdditionalPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL) { $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); $getInfoOf['id'] = $contributionId; $defaults = array(); $contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray); if ($paymentType == 'owed') { // build params for recording financial trxn entry $params['contribution'] = $contributionDAO; $params = array_merge($defaults, $params); $params['skipLineItem'] = TRUE; $params['partial_payment_total'] = $contributionDAO->total_amount; $params['partial_amount_pay'] = $trxnsData['total_amount']; $trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis'); $trxnsData['net_amount'] = !empty($trxnsData['net_amount']) ? $trxnsData['net_amount'] : $trxnsData['total_amount']; // record the entry $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId); $trxnId = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId, $contributionDAO->financial_type_id); if (!empty($trxnId)) { $trxnId = $trxnId['trxn_id']; } elseif (!empty($contributionDAO->payment_instrument_id)) { $trxnId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contributionDAO->payment_instrument_id); } else { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); $queryParams = array(1 => array($relationTypeId, 'Integer')); $trxnId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams); } // update statuses // criteria for updates contribution total_amount == financial_trxns of partial_payments $sql = "SELECT SUM(ft.total_amount) as sum_of_payments, SUM(ft.net_amount) as net_amount_total\nFROM civicrm_financial_trxn ft\nLEFT JOIN civicrm_entity_financial_trxn eft\n ON (ft.id = eft.financial_trxn_id)\nWHERE eft.entity_table = 'civicrm_contribution'\n AND eft.entity_id = {$contributionId}\n AND ft.to_financial_account_id != {$toFinancialAccount}\n AND ft.status_id = {$statusId}\n"; $query = CRM_Core_DAO::executeQuery($sql); $query->fetch(); $sumOfPayments = $query->sum_of_payments; // update statuses if ($contributionDAO->total_amount == $sumOfPayments) { // update contribution status and // clean cancel info (if any) if prev. contribution was updated in case of 'Refunded' => 'Completed' $contributionDAO->contribution_status_id = $statusId; $contributionDAO->cancel_date = 'null'; $contributionDAO->cancel_reason = NULL; $netAmount = !empty($trxnsData['net_amount']) ? NULL : $trxnsData['total_amount']; $contributionDAO->net_amount = $query->net_amount_total + $netAmount; $contributionDAO->fee_amount = $contributionDAO->total_amount - $contributionDAO->net_amount; $contributionDAO->save(); //Change status of financial record too $financialTrxn->status_id = $statusId; $financialTrxn->save(); // note : not using the self::add method, // the reason because it performs 'status change' related code execution for financial records // which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates // are coded below i.e. just updating financial_item status to 'Paid' if ($participantId) { // update participant status $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); foreach ($ids as $val) { $participantUpdate['id'] = $val; $participantUpdate['status_id'] = array_search('Registered', $participantStatuses); CRM_Event_BAO_Participant::add($participantUpdate); } } // update financial item statuses $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $paidStatus = array_search('Paid', $financialItemStatus); $baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId); $sqlFinancialItemUpdate = "\nUPDATE civicrm_financial_item fi\n LEFT JOIN civicrm_entity_financial_trxn eft\n ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET status_id = {$paidStatus}\nWHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})\n"; CRM_Core_DAO::executeQuery($sqlFinancialItemUpdate); } } elseif ($paymentType == 'refund') { // build params for recording financial trxn entry $params['contribution'] = $contributionDAO; $params = array_merge($defaults, $params); $params['skipLineItem'] = TRUE; $trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis'); $trxnsData['total_amount'] = -$trxnsData['total_amount']; $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $trxnsData['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId); $trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name'); // record the entry $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); // note : not using the self::add method, // the reason because it performs 'status change' related code execution for financial records // which in 'Pending Refund' => 'Completed' is not useful, instead specific financial record updates // are coded below i.e. just updating financial_item status to 'Paid' $contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId); // add financial item entry $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $getLine['entity_id'] = $contributionDAO->id; $getLine['entity_table'] = 'civicrm_contribution'; $lineItemId = CRM_Price_BAO_LineItem::retrieve($getLine, CRM_Core_DAO::$_nullArray); if (!empty($lineItemId->id)) { $addFinancialEntry = array('transaction_date' => $financialTrxn->trxn_date, 'contact_id' => $contributionDAO->contact_id, 'amount' => $financialTrxn->total_amount, 'status_id' => array_search('Paid', $financialItemStatus), 'entity_id' => $lineItemId->id, 'entity_table' => 'civicrm_line_item'); $trxnIds['id'] = $financialTrxn->id; CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds); } if ($participantId) { // update participant status $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); foreach ($ids as $val) { $participantUpdate['id'] = $val; $participantUpdate['status_id'] = array_search('Registered', $participantStatuses); CRM_Event_BAO_Participant::add($participantUpdate); } } } // activity creation if (!empty($financialTrxn)) { if ($participantId) { $inputParams['id'] = $participantId; $values = array(); $ids = array(); $component = 'event'; $entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids); $entityObj = $entityObj[$participantId]; } $activityType = $paymentType == 'refund' ? 'Refund' : 'Payment'; self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId); } return $financialTrxn; }
/** * Set variables up before form is built based on participant ID from URL * * @return void */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $this->_userContext = $session->readUserContext(); $participant = $values = array(); $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); $params = array('id' => $this->_participant_id); $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); $this->_part_values = $values[$this->_participant_id]; $this->set('values', $this->_part_values); //fetch Event by event_id, verify that this event can still be xferred/cancelled $this->_event_id = $this->_part_values['event_id']; $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true"); $this->_contact_id = $this->_part_values['participant_contact_id']; $this->assign('action', $this->_action); if ($this->_participant_id) { $this->assign('participantId', $this->_participant_id); } $event = array(); $daoName = 'title'; $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); $daoName = 'start_date'; $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contact_id); $this->_contact_name = $displayName; $this->_contact_email = $email; $details = array(); $details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id'); $this->assign('contributionId', $contributionId); $query = "\n SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id\n FROM civicrm_participant cp\n LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id\n LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}\n WHERE cp.id = {$this->_participant_id}"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $details['status'] = $dao->status; $details['role'] = $dao->role; $details['fee_level'] = $dao->fee_level; $details['fee_amount'] = $dao->fee_amount; $details['register_date'] = $dao->register_date; } //verify participant status is still Registered if ($details['status'] != "Registered") { $status = "You are no longer registered for " . $this->_event_title; CRM_Core_Session::setStatus($status, ts('Event status error.'), 'alert'); CRM_Utils_System::redirect($url); } $query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $time_limit = $dao->time; $start_date = $dao->start; } $start_time = new Datetime($start_date); $timenow = new Datetime(); if (!empty($start_time) && $start_time < $timenow) { $status = ts("The event has been started, cannot transfer or cancel this event"); $session->setStatus($status, ts('Oops.'), 'alert'); CRM_Utils_System::redirect($url); } if (!empty($time_limit) && $time_limit > 0) { $interval = $timenow->diff($start_time); $days = $interval->format('%d'); $hours = $interval->format('%h'); if ($hours <= $time_limit && $days < 1) { $status = ts("Less than %1 hours to start time, cannot transfer or cancel this event", array(1 => $time_limit)); $session->setStatus($status, ts('Oops.'), 'alert'); CRM_Utils_System::redirect($url); } } $this->assign('details', $details); $this->selfsvcupdateUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_participant_id}&id=0"); $this->selfsvcupdateText = ts('Update'); $this->selfsvcupdateButtonText = ts('Update'); // Based on those ids retrieve event and verify it is eligible // for self update (event.start_date > today, event can be 'self_updated' // retrieve contact name and email, and let user verify his/her identity }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ public function setDefaultValues() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::setDefaultValues($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_participantId) { $ids = array(); $params = array('id' => $this->_participantId); require_once "CRM/Event/BAO/Participant.php"; CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $this->_contactID = $defaults[$this->_participantId]['contact_id']; $this->_statusId = $defaults[$this->_participantId]['participant_status_id']; //set defaults for note $noteDetails = CRM_Core_BAO_Note::getNote($this->_participantId, 'civicrm_participant'); $defaults[$this->_participantId]['note'] = array_pop($noteDetails); } if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } //setting default register date if ($this->_action == CRM_Core_Action::ADD) { if (CRM_Utils_Array::value('event_id', $defaults[$this->_participantId])) { $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_participantId]['event_id'], 'contribution_type_id'); if ($contributionTypeId) { $defaults[$this->_participantId]['contribution_type_id'] = $contributionTypeId; } } if ($this->_mode) { $fields["email-{$this->_bltID}"] = 1; $fields["email-Primary"] = 1; require_once "CRM/Core/BAO/UFGroup.php"; if ($this->_contactID) { require_once "CRM/Core/BAO/UFGroup.php"; CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults); } if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) { $defaults[$this->_participantId]["email-{$this->_bltID}"] = $defaults["email-Primary"]; } } $submittedRole = $this->getElementValue('role_id'); if ($submittedRole[0]) { $roleID = $submittedRole[0]; } $submittedEvent = $this->getElementValue('event_id'); if ($submittedEvent[0]) { $eventID = $submittedEvent[0]; } } else { $defaults[$this->_participantId]['record_contribution'] = 0; $recordContribution = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $defaults[$this->_participantId]['id'], 'contribution_id', 'participant_id'); //contribution record exists for this participation if ($recordContribution) { foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $field) { $defaults[$this->_participantId][$field] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recordContribution, $field); } } if ($defaults[$this->_participantId]['participant_is_pay_later']) { $this->assign('participant_is_pay_later', true); } $this->assign('participant_status_id', $defaults[$this->_participantId]['participant_status_id']); $roleID = $defaults[$this->_participantId]['participant_role_id']; $eventID = $defaults[$this->_participantId]['event_id']; $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'discount_id'); if ($this->_discountId) { $this->set('discountId', $this->_discountId); } } list($defaults[$this->_participantId]['register_date'], $defaults[$this->_participantId]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_participantId])); //assign event and role id, this is needed for Custom data building if (isset($_POST['role_id'])) { $roleID = $_POST['role_id']; } if (isset($roleID)) { $this->assign('roleID', $roleID); } if (isset($_POST['event_id'])) { $eventID = $_POST['event_id']; } if (isset($eventID)) { $this->assign('eventID', $eventID); $this->set('eventId', $eventID); } $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_participantId])); return $defaults[$this->_participantId]; }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * @access public * * @return None */ static function setDefaultValues(&$form) { $defaults = array(); if ($form->_eventId) { //get receipt text and contribution type $returnProperities = array('confirm_email_text', 'contribution_type_id', 'campaign_id'); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); if (CRM_Utils_Array::value('contribution_type_id', $details[$form->_eventId])) { $defaults[$form->_pId]['contribution_type_id'] = $details[$form->_eventId]['contribution_type_id']; } } if ($form->_pId) { $ids = array(); $params = array('id' => $form->_pId); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); if ($form->_action == CRM_Core_Action::UPDATE) { $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { $discounts[$key] = $value['name']; } } if ($form->_discountId) { $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]); } $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId])); } $defaults[$form->_pId]['send_receipt'] = 0; } else { $defaults[$form->_pId]['send_receipt'] = 1; if ($form->_eventId && CRM_Utils_Array::value('confirm_email_text', $details[$form->_eventId])) { //set receipt text $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text']; } list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults(); } if ($form->_mode) { $fields = array(); foreach ($form->_fields as $name => $dontCare) { $fields[$name] = 1; } $names = array('first_name', 'middle_name', 'last_name', "street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}", "state_province_id-{$form->_bltID}"); foreach ($names as $name) { $fields[$name] = 1; } $fields["state_province-{$form->_bltID}"] = 1; $fields["country-{$form->_bltID}"] = 1; $fields["email-{$form->_bltID}"] = 1; $fields['email-Primary'] = 1; if ($form->_contactId) { CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactId, $fields, $form->_defaults); } // use primary email address if billing email address is empty if (empty($form->_defaults["email-{$form->_bltID}"]) && !empty($form->_defaults['email-Primary'])) { $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults['email-Primary']; } foreach ($names as $name) { if (!empty($form->_defaults[$name])) { $defaults[$form->_pId]['billing_' . $name] = $form->_defaults[$name]; } } $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (!CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $defaults[$form->_pId])) { $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry; } // // hack to simplify credit card entry for testing // $defaults[$form->_pId]['credit_card_type'] = 'Visa'; // $defaults[$form->_pId]['credit_card_number'] = '4807731747657838'; // $defaults[$form->_pId]['cvv2'] = '000'; // $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' ); } if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) { // get price set default values, CRM-4090 if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) { $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId); if (!empty($priceSetValues)) { $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues); } } if ($form->_action == CRM_Core_Action::ADD && CRM_Utils_Array::value('fields', $form->_priceSet)) { 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' && CRM_Utils_Array::value('is_full', $values)) { continue; } if ($val['html_type'] == 'CheckBox') { $defaults[$form->_pId]["price_{$key}"][$keys] = 1; } else { $defaults[$form->_pId]["price_{$key}"] = $keys; } } } } } $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); if ($form->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$form->_pId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $form->assign('fee_level', $fee_level); $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); } } else { $optionGroupId = NULL; // if user has selected discount use that to set default if (isset($form->_discountId)) { $defaults[$form->_pId]['discount_id'] = $form->_discountId; //hack to set defaults for already selected discount value if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; if ($form->_originalDiscountId) { $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $form->_originalDiscountId, 'option_group_id'); $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; } } } if ($form->_action == CRM_Core_Action::ADD) { // this case is for add mode, where we show discount automatically if (!isset($form->_discountId)) { $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } else { $discountId = $form->_discountId; } if ($form->_eventId && $discountId) { $defaultDiscountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_discount_fee_id'); if ($defaultDiscountId) { $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $defaultDiscountId, 'weight'); } $defaults[$form->_pId]['discount_id'] = $discountId; $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE)); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'); } else { if ($form->_eventId) { $defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_fee_id'); } } } if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) { if (!empty($form->_feeBlock)) { $feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]); $feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]); foreach ($form->_feeBlock as $amountId => $amountInfo) { if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } // if amount is not set do fuzzy matching if (!isset($defaults[$form->_pId]['amount'])) { // if only level use that if ($amountInfo['label'] == $feeLevel) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } elseif (strpos($feeLevel, $amountInfo['label']) !== FALSE) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } elseif ($amountInfo['value'] == $feeAmount) { // if amount matches use that $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } } } } } $form->assign('amountId', CRM_Utils_Array::value('amount', $defaults[$form->_pId])); } //CRM-4453 if (CRM_Utils_Array::value('participant_fee_currency', $defaults[$form->_pId])) { $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']); } // CRM-4395 if ($contriId = $form->get('onlinePendingContributionId')) { $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->id = $contriId; $contribution->find(TRUE); foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) { if ($f == 'receive_date') { list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f}); } else { $defaults[$form->_pId][$f] = $contribution->{$f}; } } } return $defaults[$form->_pId]; }
public function postProcess() { $params = $this->controller->exportValues($this->_name); $feeBlock = $this->_values['fee']; $lineItems = $this->_values['line_items']; CRM_Event_BAO_Participant::changeFeeSelections($params, $this->_participantId, $this->_contributionId, $feeBlock, $lineItems, $this->_paidAmount, $params['priceSetId']); $this->contributionAmt = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'total_amount'); // email sending if (CRM_Utils_Array::value('send_receipt', $params)) { $fetchParticipantVals = array('id' => $this->_participantId); CRM_Event_BAO_Participant::getValues($fetchParticipantVals, $participantDetails, CRM_Core_DAO::$_nullArray); $participantParams = array_merge($params, $participantDetails[$this->_participantId]); $mailSent = $this->emailReceipt($participantParams); } // update participant CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'status_id', $params['status_id']); if (!empty($params['note'])) { $noteParams = array('entity_table' => 'civicrm_participant', 'note' => $params['note'], 'entity_id' => $this->_participantId, 'contact_id' => $this->_contactId, 'modified_date' => date('Ymd')); CRM_Core_BAO_Note::add($noteParams); } CRM_Core_Session::setStatus(ts("The fee selection has been changed for this participant"), ts('Saved'), 'success'); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/payment/add', "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}")); } }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ public function setDefaultValues() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::setDefaultValues($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_id) { $ids = array(); $params = array('id' => $this->_id); require_once "CRM/Event/BAO/Participant.php"; CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $sep = CRM_Core_DAO::VALUE_SEPARATOR; if ($defaults[$this->_id]['role_id']) { foreach (explode($sep, $defaults[$this->_id]['role_id']) as $k => $v) { $defaults[$this->_id]["role_id[{$v}]"] = 1; } unset($defaults[$this->_id]['role_id']); } $this->_contactId = $defaults[$this->_id]['contact_id']; $this->_statusId = $defaults[$this->_id]['participant_status_id']; //set defaults for note $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant'); $defaults[$this->_id]['note'] = array_pop($noteDetails); // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id)); } // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) if (CRM_Utils_Array::value('participant_registered_by_id', $defaults[$this->_id])) { $registered_by_contact_id = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id'); $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']); $this->assign('registered_by_contact_id', $registered_by_contact_id); require_once 'CRM/Contact/BAO/Contact.php'; $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id)); } } if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) { $inactiveNeeded = true; $viewMode = true; } else { $viewMode = false; $inactiveNeeded = false; } //setting default register date if ($this->_action == CRM_Core_Action::ADD) { $statuses = array_flip($this->_participantStatuses); $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses); if (CRM_Utils_Array::value('event_id', $defaults[$this->_id])) { $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'contribution_type_id'); if ($contributionTypeId) { $defaults[$this->_id]['contribution_type_id'] = $contributionTypeId; } } if ($this->_mode) { $fields["email-{$this->_bltID}"] = 1; $fields["email-Primary"] = 1; if ($this->_contactId) { require_once "CRM/Core/BAO/UFGroup.php"; CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults); } if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) { $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults["email-Primary"]; } } $submittedRole = $this->getElementValue('role_id'); if (CRM_Utils_Array::value(0, $submittedRole)) { $roleID = $submittedRole[0]; } $submittedEvent = $this->getElementValue('event_id'); if ($submittedEvent[0]) { $eventID = $submittedEvent[0]; } } else { $defaults[$this->_id]['record_contribution'] = 0; if ($defaults[$this->_id]['participant_is_pay_later']) { $this->assign('participant_is_pay_later', true); } $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']); $roleID = $defaults[$this->_id]['participant_role_id']; $eventID = $defaults[$this->_id]['event_id']; $this->_eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventID, 'event_type_id', 'id'); $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id'); if ($this->_discountId) { $this->set('discountId', $this->_discountId); } } list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime'); //assign event and role id, this is needed for Custom data building $sep = CRM_Core_DAO::VALUE_SEPARATOR; if (CRM_Utils_Array::value('participant_role_id', $defaults[$this->_id])) { $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']); } if (isset($roleIDs)) { $this->assign('roleID', $roleIDs); } if (isset($_POST['event_id'])) { $eventID = $_POST['event_id']; if ($eventID) { $this->_eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventID, 'event_type_id', 'id'); } } if (isset($eventID)) { $this->assign('eventID', $eventID); $this->set('eventId', $eventID); } if (isset($this->_eventTypeId)) { $this->assign('eventTypeID', $this->_eventTypeId); } $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id])); return $defaults[$this->_id]; }
/** * This function sets the default values for the form in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ static function setDefaultValues(&$form) { $defaults = array(); if ($form->_eventId) { //get receipt text and contribution type $returnProperities = array('confirm_email_text', 'contribution_type_id'); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); $defaults[$form->_pId]['contribution_type_id'] = $details[$form->_eventId]['contribution_type_id']; } if ($form->_pId) { $ids = array(); $params = array('id' => $form->_pId); require_once "CRM/Event/BAO/Participant.php"; CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); if ($form->_action == CRM_Core_Action::UPDATE) { $discounts = array(); if (!empty($form->_values['discount'])) { foreach ($form->_values['discount'] as $key => $value) { $discounts[$key] = $value['name']; } } if ($form->_discountId) { $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]); } $form->assign('fee_amount', $defaults[$form->_pId]['fee_amount']); $form->assign('fee_level', $defaults[$form->_pId]['fee_level']); } $defaults[$form->_pId]['send_receipt'] = 0; } else { $defaults[$form->_pId]['send_receipt'] = 1; if ($form->_eventId) { //set receipt text $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text']; } list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults(); } if ($form->_mode) { $fields = array(); foreach ($form->_fields as $name => $dontCare) { $fields[$name] = 1; } $names = array("first_name", "middle_name", "last_name", "street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}", "state_province_id-{$form->_bltID}"); foreach ($names as $name) { $fields[$name] = 1; } $fields["state_province-{$form->_bltID}"] = 1; $fields["country-{$form->_bltID}"] = 1; $fields["email-{$form->_bltID}"] = 1; $fields["email-Primary"] = 1; require_once "CRM/Core/BAO/UFGroup.php"; if ($form->_contactID) { CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactID, $fields, $form->_defaults); } // use primary email address if billing email address is empty if (empty($form->_defaults["email-{$form->_bltID}"]) && !empty($form->_defaults["email-Primary"])) { $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults["email-Primary"]; } foreach ($names as $name) { if (!empty($form->_defaults[$name])) { $defaults[$form->_pId]["billing_" . $name] = $form->_defaults[$name]; } } } require_once 'CRM/Price/BAO/Set.php'; if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) { // get price set default values, CRM-4090 if (in_array(get_class($form), array('CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) { $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId); if (!empty($priceSetValues)) { $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues); } } if ($form->_action == CRM_Core_Action::ADD) { foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { if ($val['html_type'] == 'CheckBox') { $defaults[$form->_pId]["price_{$key}"][$keys] = 1; } else { $defaults[$form->_pId]["price_{$key}"] = $keys; } } } } } $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); if ($form->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$form->_pId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $form->assign("fee_level", $fee_level); $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId])); } } else { $optionGroupId = null; // if user has selected discount use that to set default if (isset($form->_discountId)) { $defaults[$form->_pId]['discount_id'] = $form->_discountId; //hack to set defaults for already selected discount value if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) { $form->_originalDiscountId = $defaults[$form->_pId]['discount_id']; if ($form->_originalDiscountId) { $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $form->_originalDiscountId, 'option_group_id'); $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId; } } } if ($form->_action == CRM_Core_Action::ADD) { // this case is for add mode, where we show discount automatically if (!isset($form->_discountId)) { require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); } else { $discountId = $form->_discountId; } if ($form->_eventId && $discountId) { $defaultDiscountId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_discount_fee_id'); if ($defaultDiscountId) { $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $defaultDiscountId, 'weight'); } $defaults[$form->_pId]['discount_id'] = $discountId; $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, true)); $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $discountId, 'option_group_id'); } else { if ($form->_eventId) { $defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_fee_id'); } } } if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) { if (!empty($form->_feeBlock)) { $feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]); $feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]); foreach ($form->_feeBlock as $amountId => $amountInfo) { if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } // if amount is not set do fuzzy matching if (!isset($defaults[$form->_pId]['amount'])) { // if only level use that if ($amountInfo['label'] == $feeLevel) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } else { if (strpos($feeLevel, $amountInfo['label']) !== false) { $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } else { if ($amountInfo['value'] == $feeAmount) { // if amount matches use that $defaults[$form->_pId]['amount'] = $amountInfo['amount_id']; } } } } } } if (!isset($defaults[$form->_pId]['amount'])) { // keeping the old code too if (!$optionGroupId) { $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionGroup", 'civicrm_event.amount.' . $defaults[$form->_pId]['event_id'], 'id', 'name'); } $optionParams = array('option_group_id' => $optionGroupId, 'label' => CRM_Utils_Array::value('fee_level', $defaults[$form->_pId])); CRM_Core_BAO_CustomOption::retrieve($optionParams, $params); $defaults[$form->_pId]['amount'] = $params['id']; } } $form->assign("amountId", $defaults[$form->_pId]['amount']); } //CRM-4453 $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']); // CRM-4395 if ($contriId = $form->get('onlinePendingContributionId')) { require_once 'CRM/Contribute/DAO/Contribution.php'; $contribution =& new CRM_Contribute_DAO_Contribution(); $contribution->id = $contriId; $contribution->find(true); foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $f) { $defaults[$form->_pId][$f] = $contribution->{$f}; } } return $defaults[$form->_pId]; }
/** * Get source values for transfer based on participant id in URL. Line items will * be transferred to this participant - at this point no transaction changes processed * * return @void */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $this->_userContext = $session->readUserContext(); $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); $params = array('id' => $this->_from_participant_id); $participant = $values = array(); $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); $this->_part_values = $values[$this->_from_participant_id]; $this->set('values', $this->_part_values); $this->_event_id = $this->_part_values['event_id']; $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); $this->_from_contact_id = $this->_part_values['participant_contact_id']; $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_from_contact_id, $this->_userChecksum); if (!$validUser && !CRM_Core_Permission::check('edit all events')) { CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url); } $this->assign('action', $this->_action); if ($this->_from_participant_id) { $this->assign('participantId', $this->_from_participant_id); } $event = array(); $daoName = 'title'; $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); $daoName = 'start_date'; $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); $this->_contact_name = $displayName; $this->_contact_email = $email; $details = array(); $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); $query = "\n SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, civicrm_event.start_date\n FROM civicrm_participant cp\n LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id\n LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}\n LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id\n WHERE cp.id = {$this->_from_participant_id}"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $details['status'] = $dao->status; $details['role'] = $dao->role; $details['fee_level'] = $dao->fee_level; $details['fee_amount'] = $dao->fee_amount; $details['register_date'] = $dao->register_date; $details['event_start_date'] = $dao->start_date; } $this->assign('details', $details); //This participant row will be cancelled. Get line item(s) to cancel $this->selfsvctransferUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_from_participant_id}&id=0"); $this->selfsvctransferText = ts('Update'); $this->selfsvctransferButtonText = ts('Update'); }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false); //CRM-4320 $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); //check if participant allow to walk registration wizard. $this->_allowConfirmation = $this->get('allowConfirmation'); // check for Approval $this->_requireApproval = $this->get('requireApproval'); // check for waitlisting. $this->_allowWaitlist = $this->get('allowWaitlist'); //get the additional participant ids. $this->_additionalParticipantIds = $this->get('additionalParticipantIds'); $config =& CRM_Core_Config::singleton(); if (!$this->_values) { // create redirect URL to send folks back to event info page is registration not available $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", false, null, false, true); // this is the first time we are hitting this, so check for permissions here if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId)) { CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl); } // get all the values from the dao object $this->_values = array(); $this->_fields = array(); // get the participant values, CRM-4320 $this->_allowConfirmation = false; if ($this->_participantId) { require_once 'CRM/Event/BAO/Event.php'; $ids = $participantValues = array(); $participantParams = array('id' => $this->_participantId); require_once 'CRM/Event/BAO/Participant.php'; CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); $this->_values['participant'] = $participantValues[$this->_participantId]; //allow pending status class walk registration wizard. require_once 'CRM/Core/PseudoConstant.php'; if (array_key_exists($participantValues[$this->_participantId]['status_id'], CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'"))) { $this->_allowConfirmation = true; $this->set('allowConfirmation', true); } } //retrieve event information require_once 'CRM/Event/BAO/Event.php'; $params = array('id' => $this->_eventId); CRM_Event_BAO_Event::retrieve($params, $this->_values['event']); require_once 'CRM/Event/BAO/Participant.php'; //check for additional participants. if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) { $this->_additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); $this->set('additionalParticipantIds', $this->_additionalParticipantIds); } $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->_allowWaitlist = false; if ($eventFull && !$this->_allowConfirmation) { //lets redirecting to info only when to waiting list. $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']); if (!$this->_allowWaitlist) { CRM_Utils_System::redirect($infoUrl); } } $this->set('allowWaitlist', $this->_allowWaitlist); //check for require requires approval. $this->_requireApproval = false; if (CRM_Utils_Array::value('requires_approval', $this->_values['event']) && !$this->_allowConfirmation) { $this->_requireApproval = true; } $this->set('requireApproval', $this->_requireApproval); // also get the accounting code if (CRM_Utils_Array::value('contribution_type_id', $this->_values['event'])) { $this->_values['event']['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $this->_values['event']['contribution_type_id'], 'accounting_code'); } if (isset($this->_values['event']['default_role_id'])) { require_once 'CRM/Core/OptionGroup.php'; $participant_role = CRM_Core_OptionGroup::values('participant_role'); $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"]; } // is the event active (enabled)? if (!$this->_values['event']['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).')); } // is online registration is enabled? if (!$this->_values['event']['is_online_registration']) { CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $infoUrl); } // is this an event template ? if (CRM_Utils_Array::value('is_template', $this->_values['event'])) { CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $infoUrl); } $now = date('YmdHis'); $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])); if ($startDate && $startDate >= $now) { CRM_Core_Error::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])))), $infoUrl); } $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])); if ($endDate && $endDate < $now) { CRM_Core_Error::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])))), $infoUrl); } // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']); //retrieve custom information $eventID = $this->_eventId; $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'is_pay_later'); //check for variour combination for paylater, payment //process with paid event. if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values['event']))) { $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values['event']); if (!$ppID) { CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl); } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); // make sure we have a valid payment class, else abort if ($this->_values['event']['is_monetary']) { if (!$this->_paymentProcessor) { CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.')); } // ensure that processor has a valid config $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this); $error = $payment->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } } $this->_paymentProcessor['processorName'] = $payment->_processorName; $this->set('paymentProcessor', $this->_paymentProcessor); } // get price info $price = self::initPriceSet($this, $eventID); if ($price == false) { if (!isset($this->_values['fee'])) { $this->_values['fee'] = array(); } require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventID}", $this->_values['fee'], true); //fix for non-upgraded price sets.CRM-4256. if ($isMonetary && empty($this->_values['fee'])) { CRM_Core_Error::fatal(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.', array(1 => CRM_Utils_System::url('civicrm/event/manage', 'reset=1&action=update&subPage=Fee&id=' . $this->_eventId)))); } } // get the profile ids require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId); list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // set profiles for additional participants if ($this->_values['event']['is_multiple_registrations']) { require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent_Additional', 'entity_id' => $this->_eventId); list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact // set same profile for additional contacts. if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) { $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id']; } if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) { $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id']; } // now check for no profile condition, in that case is_active = 0 if (isset($preActive) && !$preActive) { unset($this->_values['additional_custom_pre_id']); } if (isset($postActive) && !$postActive) { unset($this->_values['additional_custom_post_id']); } } $params = array('id' => $this->_eventId); // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $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); if ($this->_values['event']['is_monetary'] && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); } $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, true); $this->set('values', $this->_values); $this->set('fields', $this->_fields); } $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); // setting CMS page title CRM_Utils_System::setTitle($this->_values['event']['title']); $this->assign('title', $this->_values['event']['title']); $this->assign('paidEvent', $this->_values['event']['is_monetary']); // we do not want to display recently viewed items on Registration pages $this->assign('displayRecent', false); // Registration page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', true); // assign all event properties so wizard templates can display event info. $this->assign('event', $this->_values['event']); $this->assign('location', $this->_values['location']); $this->assign('bltID', $this->_bltID); $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); $this->assign('isShowLocation', $isShowLocation); }
/** * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method */ public function testfixEventLevel() { $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); $paramsSet['is_active'] = FALSE; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'option_name' => array('1' => 10), 'option_weight' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1); $ids = array(); $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield'); $eventId = $this->_eventId; $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55'); $participant = CRM_Event_BAO_Participant::add($participantParams); //Checking for participant added in the table. $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant'); $values = array(); $ids = array(); $params = array('id' => $participant->id); CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNotEquals(count($values), 0, 'Checking for empty array.'); CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]); if ($values[$participant->id]['fee_level']) { CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']); } $deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id); $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.'); $deletePriceset = CRM_Price_BAO_PriceSet::deleteSet($priceset->id); $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.'); Participant::delete($participant->id); Contact::delete($this->_contactId); Event::delete($eventId); }
/** * Process the form submission. */ public function postProcess() { $now = date('YmdHis'); $this->_params = $this->get('params'); if (!empty($this->_params[0]['contact_id'])) { // unclear when this would be set & whether it could be checked in getContactID. // perhaps it relates to when cid is in the url //@todo someone who knows add comments on the various contactIDs in this form $contactID = $this->_params[0]['contact_id']; } else { $contactID = $this->getContactID(); } // if a discount has been applied, lets now deduct it from the amount // and fix the fee level if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) { foreach ($this->_params as $k => $v) { if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && !empty($this->_params[$k]['discountAmount'])) { $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount']; $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]); } } $this->set('params', $this->_params); } // CRM-4320, lets build array of cancelled additional participant ids // those are drop or skip by primary at the time of confirmation. // get all in and then unset those we want to process. $cancelledIds = $this->_additionalParticipantIds; $params = $this->_params; if ($this->_values['event']['is_monetary']) { $this->set('finalAmount', $this->_amount); } $participantCount = array(); //unset the skip participant from params. //build the $participantCount array. //maintain record for all participants. foreach ($params as $participantNum => $record) { if ($record == 'skip') { unset($params[$participantNum]); $participantCount[$participantNum] = 'skip'; } elseif ($participantNum) { $participantCount[$participantNum] = 'participant'; } //lets get additional participant id to cancel. if ($this->_allowConfirmation && is_array($cancelledIds)) { $additonalId = CRM_Utils_Array::value('participant_id', $record); if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) { unset($cancelledIds[$key]); } } } $payment = $registerByID = $primaryCurrencyID = $contribution = NULL; $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.'); $this->participantIDS = array(); $fields = array(); foreach ($params as $key => $value) { CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this); //unset the billing parameters if it is pay later mode //to avoid creation of billing location // @todo - the reasoning for this is unclear - elsewhere we check what fields are provided by // the form & if billing fields exist we create the address, relying on the form to collect // only information we intend to store. if ($this->_allowWaitlist || $this->_requireApproval || !empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater || empty($value['is_primary'])) { $billingFields = array("email-{$this->_bltID}", 'billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}", "address_name-{$this->_bltID}"); foreach ($billingFields as $field) { unset($value[$field]); } if (!empty($value['is_pay_later'])) { $this->_values['params']['is_pay_later'] = TRUE; } } //Unset ContactID for additional participants and set RegisterBy Id. if (empty($value['is_primary'])) { $contactID = CRM_Utils_Array::value('contact_id', $value); $registerByID = $this->get('registerByID'); if ($registerByID) { $value['registered_by_id'] = $registerByID; } } else { $value['amount'] = $this->_totalAmount; } $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this); // lets store the contactID in the session // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend if (!$this->getContactID() && !empty($value['is_primary'])) { $session = CRM_Core_Session::singleton(); $session->set('transaction.userID', $contactID); } $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title']; $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']); $pending = FALSE; if ($this->_allowWaitlist || $this->_requireApproval) { //get the participant statuses. $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); if ($this->_allowWaitlist) { $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses); } else { $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses); } //there might be case user seleted pay later and //now becomes part of run time waiting list. $value['is_pay_later'] = FALSE; } // required only if paid event if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) { if (is_array($this->_paymentProcessor)) { $payment = $this->_paymentProcessor['object']; } if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); $value = array_merge($value, $preApprovalParams); } $result = NULL; if (!empty($value['is_pay_later']) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') { if ($value['amount'] != 0) { $pending = TRUE; //get the participant statuses. $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'"); $status = !empty($value['is_pay_later']) ? 'Pending from pay later' : 'Pending from incomplete transaction'; $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses); } } elseif (!empty($value['is_primary'])) { CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE); // payment email param can be empty for _bltID mapping // thus provide mapping for it with a different email value if (empty($value['email'])) { $value['email'] = CRM_Utils_Array::valueByRegexKey('/^email-/', $value); } if (is_object($payment)) { try { $result = $payment->doPayment($value); $value = array_merge($value, $result); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { CRM_Core_Session::singleton()->setStatus($e->getMessage()); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); } } else { CRM_Core_Error::fatal($paymentObjError); } } $value['receive_date'] = $now; if ($this->_allowConfirmation) { $value['participant_register_date'] = $this->_values['participant']['register_date']; } $createContrib = $value['amount'] != 0 ? TRUE : FALSE; // force to create zero amount contribution, CRM-5095 if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) { $createContrib = TRUE; } if ($createContrib && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) { // if paid event add a contribution record //if primary participant contributing additional amount //append (multiple participants) to its fee level. CRM-4196. $isAdditionalAmount = FALSE; if (count($params) > 1) { $isAdditionalAmount = TRUE; } //passing contribution id is already registered. $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount); $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->financial_type_id; $value['receive_date'] = $contribution->receive_date; $value['trxn_id'] = $contribution->trxn_id; $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->financial_type_id; } $value['contactID'] = $contactID; $value['eventID'] = $this->_eventId; $value['item_name'] = $value['description']; } if (!empty($value['contributionID'])) { $this->_values['contributionId'] = $value['contributionID']; } //CRM-4453. if (!empty($value['is_primary'])) { $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value); } if (empty($value['currencyID'])) { $value['currencyID'] = $primaryCurrencyID; } // CRM-11182 - Confirmation page might not be monetary if ($this->_values['event']['is_monetary']) { if (!$pending && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) { // transactionID & receive date required while building email template $this->assign('trxn_id', $value['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value)); } } $value['fee_amount'] = CRM_Utils_Array::value('amount', $value); $this->set('value', $value); // handle register date CRM-4320 if ($this->_allowConfirmation) { $registerDate = CRM_Utils_Array::value('participant_register_date', $params); } elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) { $registerDate = CRM_Utils_Date::format($params['participant_register_date']); } else { $registerDate = date('YmdHis'); } $this->assign('register_date', $registerDate); $this->confirmPostProcess($contactID, $contribution, $payment); } //handle if no additional participant. if (!$registerByID) { $registerByID = $this->get('registerByID'); } $this->set('participantIDs', $this->_participantIDS); // create line items, CRM-5313 if ($this->_priceSetId && !empty($this->_lineItem)) { // take all processed participant ids. $allParticipantIds = $this->_participantIDS; // when participant re-walk wizard. if ($this->_allowConfirmation && !empty($this->_additionalParticipantIds)) { $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds); } $entityTable = 'civicrm_participant'; $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $totalTaxAmount = 0; $dataArray = array(); foreach ($this->_lineItem as $key => $value) { if ($value == 'skip') { continue; } if ($entityId = CRM_Utils_Array::value($key, $allParticipantIds)) { // do cleanup line items if participant re-walking wizard. if ($this->_allowConfirmation) { CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable); } $lineItem[$this->_priceSetId] = $value; CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable); } if ($invoicing) { foreach ($value as $line) { if (isset($line['tax_amount']) && isset($line['tax_rate'])) { $totalTaxAmount = $line['tax_amount'] + $totalTaxAmount; if (isset($dataArray[$line['tax_rate']])) { $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line); } else { $dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line); } } } } } if ($invoicing) { $this->assign('dataArray', $dataArray); $this->assign('totalTaxAmount', $totalTaxAmount); } } //update status and send mail to cancelled additional participants, CRM-4320 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); } $isTest = FALSE; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = TRUE; } // for Transfer checkout. // The concept of contributeMode is deprecated. if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && empty($params[0]['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) { $primaryParticipant = $this->get('primaryParticipant'); if (empty($primaryParticipant['participantID'])) { $primaryParticipant['participantID'] = $registerByID; } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } // do a transfer only if a monetary payment greater than 0 if ($this->_values['event']['is_monetary'] && $primaryParticipant) { if ($payment && is_object($payment)) { //CRM 14512 provide line items of all participants to payment gateway $primaryContactId = $this->get('primaryContactId'); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE); //need to copy, since we are unsetting on the way. $copyParticipantCountLines = $participantCount; //lets carry all participant params w/ values. foreach ($additionalIDs as $participantID => $contactId) { $participantNum = NULL; $participantNum = $participantID; if ($participantID == $registerByID) { // This is the is primary participant. $participantNum = 0; } else { if ($participantNum = array_search('participant', $copyParticipantCountLines)) { //if no participant found break. if ($participantNum === NULL) { break; } //unset current particpant so we don't check them again unset($copyParticipantCountLines[$participantNum]); } } // get values of line items if ($this->_amount) { $amount = array(); $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']); $amount[$participantNum]['amount'] = $params[$participantNum]['amount']; $params[$participantNum]['amounts'] = $amount; } if (!empty($this->_lineItem)) { $lineItems = $this->_lineItem; $lineItem = array(); if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) { $lineItem[] = $lineItemValue; } $params[$participantNum]['lineItem'] = $lineItem; } //only add additional particpants and not the primary particpant as we already have that //added to $primaryParticipant so that this change doesn't break or require changes to //existing gateway implementations $primaryParticipant['participants_info'][$participantID] = $params[$participantNum]; } //get event custom field information $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']); $primaryParticipant['eventCustomFields'] = $groupTree; // call postprocess hook before leaving $this->postProcessHook(); // this does not return $payment->doPayment($primaryParticipant, 'event'); } else { CRM_Core_Error::fatal($paymentObjError); } } } else { //otherwise send mail Confirmation/Receipt $primaryContactId = $this->get('primaryContactId'); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE); //lets send mails to all with meaningful text, CRM-4320. $this->assign('isOnWaitlist', $this->_allowWaitlist); $this->assign('isRequireApproval', $this->_requireApproval); //need to copy, since we are unsetting on the way. $copyParticipantCount = $participantCount; //lets carry all paticipant params w/ values. foreach ($additionalIDs as $participantID => $contactId) { $participantNum = NULL; if ($participantID == $registerByID) { $participantNum = 0; } else { if ($participantNum = array_search('participant', $copyParticipantCount)) { unset($copyParticipantCount[$participantNum]); } } if ($participantNum === NULL) { break; } //carry the participant submitted values. $this->_values['params'][$participantID] = $params[$participantNum]; } foreach ($additionalIDs as $participantID => $contactId) { $participantNum = 0; if ($participantID == $registerByID) { //set as Primary Participant $this->assign('isPrimary', 1); //build an array of custom profile and assigning it to template. $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } $this->_values['params']['additionalParticipant'] = FALSE; } else { //take the Additional participant number. if ($participantNum = array_search('participant', $participantCount)) { unset($participantCount[$participantNum]); } // Change $this->_values['participant'] to include additional participant values $ids = $participantValues = array(); $participantParams = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); $this->_values['participant'] = $participantValues[$participantID]; $this->assign('isPrimary', 0); $this->assign('customProfile', NULL); //Additional Participant should get only it's payment information if (!empty($this->_amount)) { $amount = array(); $params = $this->get('params'); $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']); $amount[$participantNum]['amount'] = $params[$participantNum]['amount']; $this->assign('amounts', $amount); } if ($this->_lineItem) { $lineItems = $this->_lineItem; $lineItem = array(); if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) { $lineItem[] = $lineItemValue; } if ($invoicing) { $individual = $this->get('individual'); $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt']; $this->assign('dataArray', $dataArray); $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']); $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']); $this->assign('individual', array($individual[$participantNum])); } $this->assign('lineItem', $lineItem); } $this->_values['params']['additionalParticipant'] = TRUE; $this->assign('isAdditionalParticipant', $this->_values['params']['additionalParticipant']); } //pass these variables since these are run time calculated. $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist; $this->_values['params']['isRequireApproval'] = $this->_requireApproval; //send mail to primary as well as additional participants. $this->assign('contactID', $contactId); $this->assign('participantID', $participantID); CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); } } }
/** * Set the first participant ID if not set. * * CRM-10032. * * @param int $participantID */ public function processFirstParticipant($participantID) { $this->_participantId = $participantID; $this->set('participantId', $this->_participantId); $ids = $participantValues = array(); $participantParams = array('id' => $this->_participantId); CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); $this->_values['participant'] = $participantValues[$this->_participantId]; $this->set('values', $this->_values); // also set the allow confirmation stuff if (array_key_exists($this->_values['participant']['status_id'], CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'"))) { $this->_allowConfirmation = TRUE; $this->set('allowConfirmation', TRUE); } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Event/BAO/Participant.php'; require_once 'CRM/Core/DAO.php'; $values = $ids = array(); $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true); $params = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($params, $values, $ids); if (empty($values)) { require_once 'CRM/Core/Error.php'; CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).')); } CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]); if (CRM_Utils_Array::value('fee_level', $values[$participantID])) { CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']); } if ($values[$participantID]['is_test']) { $values[$participantID]['status'] .= ' (test) '; } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant'); $values[$participantID]['note'] = array_values($noteValue); require_once 'CRM/Price/BAO/LineItem.php'; // Get Line Items $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID); if (!CRM_Utils_System::isNull($lineItem)) { $values[$participantID]['lineItem'][] = $lineItem; } $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]); // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) if (CRM_Utils_Array::value('participant_registered_by_id', $values[$participantID])) { $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $values[$participantID]['participant_registered_by_id'], 'contact_id', 'id'); require_once 'CRM/Contact/BAO/Contact.php'; $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']); } // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) { $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID); } // get the option value for custom data type $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']); $groupTree = array(); $finalTree = array(); foreach ($allRoleIDs as $k => $v) { $roleGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $v, $roleCustomDataTypeID); $eventGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $values[$participantID]['event_id'], $eventNameCustomDataTypeID); $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id'); $eventTypeGroupTree =& CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, null, $eventTypeID, $eventTypeCustomDataTypeID); $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree); $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID)); foreach ($groupTree as $treeId => $trees) { $finalTree[$treeId] = $trees; } } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title'); //CRM-7150, show event name on participant view even if the event is disabled if (!CRM_Utils_Array::value('event', $values[$participantID])) { $values[$participantID]['event'] = $eventTitle; } $this->assign($values[$participantID]); // add viewed participant to recent items list require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::check('edit event participants')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } if (CRM_Core_Permission::check('delete in CiviEvent')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"); } $participantRoles = CRM_Event_PseudoConstant::participantRole(); $displayName = CRM_Contact_BAO_Contact::displayName($contactID); $participantCount = array(); foreach ($lineItem as $k => $v) { if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) { $participantCount[] = $lineItem['participant_count']; } } if ($participantCount) { $this->assign('pricesetFieldsCount', $participantCount); } $this->assign('displayName', $displayName); $title = $displayName . ' (' . $participantRoles[$values[$participantID]['role_id']] . ' - ' . $eventTitle . ')'; require_once 'CRM/Core/DAO.php'; $sep = CRM_Core_DAO::VALUE_SEPARATOR; $viewRoles = array(); foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values[$participantID]['role_id'] = implode(', ', $viewRoles); $this->assign('role', $values[$participantID]['role_id']); // add Participant to Recent Items CRM_Utils_Recent::add($title, $url, $values[$participantID]['id'], 'Participant', $values[$participantID]['contact_id'], null, $recentOther); }