/** * Build the form object. * * @return void */ public function buildQuickForm() { $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses); $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId); if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign('additionalParticipant', $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single && $this->_context == 'standalone') { $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE); } $eventFieldParams = array('entity' => 'event', 'select' => array('minimumInputLength' => 0), 'api' => array('extra' => array('campaign_id', 'default_role_id', 'event_type_id'))); if ($this->_mode) { // exclude events which are not monetary when credit card registration is used $eventFieldParams['api']['params']['is_monetary'] = 1; $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } //CRM-7362 --add campaigns. $campaignId = NULL; if ($this->_id) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id'); } if (!$campaignId) { $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($eventId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id'); } } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = NULL; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } // get the participant status names to build special status array which is used to show notification // checkbox below participant status select $participantStatusName = CRM_Event_PseudoConstant::participantStatus(); $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired'); // get the required status and then implode only ids $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses))); $this->assign('notificationStatusIds', $notificationStatusIds); $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create'); // Only show refund status when editing if ($this->_action & CRM_Core_Action::ADD) { $pendingRefundStatusId = array_search('Pending refund', $participantStatusName); if ($pendingRefundStatusId) { unset($statusOptions[$pendingRefundStatusId]); } } $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS); $path = CRM_Utils_System::currentPath(); $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search'); if (!in_array($path, $excludeForPaths)) { $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS); } $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel')); $this->addButtons($buttons); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { require_once 'CRM/Event/BAO/Event.php'; $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_participantId, null, $this->_contactID, false, true)) - 1; if ($additionalParticipant) { $this->assign("additionalParticipant", $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactID}&context=participant"; if ($this->_context == 'standalone') { require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = "reset=1&context=standalone"; $urlPath = 'civicrm/participant/add'; } if ($this->_participantId) { $urlParams .= "&action=update&id={$this->_participantId}"; } else { $urlParams .= "&action=add"; } if (CRM_Utils_Request::retrieve('past', 'Boolean', $this)) { $urlParams .= "&past=true"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false); } $this->assign("refreshURL", $url); $url .= "&past=true"; $this->assign("pastURL", $url); $events = array(); $this->assign("past", false); require_once "CRM/Event/BAO/Event.php"; if (CRM_Utils_Request::retrieve('past', 'Boolean', $this) || $this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(true); $this->assign("past", true); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true); } $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} );", 'class' => 'huge')); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_participantId) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id')) { $element->freeze(); } } $this->addDateTime('register_date', ts('Registration Date'), true); if ($this->_participantId) { $this->assign('entityID', $this->_participantId); } $this->add('select', 'role_id', ts('Participant Role'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), true, array('onchange' => "buildCustomData( 'Participant', this.value, {$this->_roleCustomDataTypeID} );")); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); } $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, null, 'label'), true, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $confirmJS = null; if ($this->_onlinePendingContributionId) { $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Set default values for the form. For edit/view mode * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { $defaults = $unsetSubmittedOptions = array(); $discountId = NULL; //fix for CRM-3088, default value for discount set. if (!empty($this->_values['discount'])) { $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event'); if ($discountId && !empty($this->_values['event']['default_discount_fee_id'])) { $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id'); $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE)); } } if ($this->_priceSetId) { foreach ($this->_feeBlock as $key => $val) { if (empty($val['options'])) { continue; } $optionsFull = CRM_Utils_Array::value('option_full_ids', $val, array()); foreach ($val['options'] as $keys => $values) { if ($values['is_default'] && !in_array($keys, $optionsFull)) { if ($val['html_type'] == 'CheckBox') { $defaults["price_{$key}"][$keys] = 1; } else { $defaults["price_{$key}"] = $keys; } } } if (!empty($optionsFull)) { $unsetSubmittedOptions[$val['id']] = $optionsFull; } } } //CRM-4320, setdefault additional participant values. if ($this->_allowConfirmation && $this->_additionalParticipantId) { //hack to get set default from eventFees.php $this->_discountId = $discountId; $this->_pId = $this->_additionalParticipantId; $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id'); $participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this); $participantDefaults = array_merge($this->_defaults, $participantDefaults); // use primary email address if billing email address is empty if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) { $participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"]; } $defaults = array_merge($defaults, $participantDefaults); } $defaults = array_merge($this->_defaults, $defaults); //reset values for all options those are full. CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this); //load default campaign from page. if (array_key_exists('participant_campaign_id', $this->_fields)) { $defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']); } return $defaults; }
public static function formatFieldsForOptionFull(&$form) { $priceSet = $form->get('priceSet'); $priceSetId = $form->get('priceSetId'); if (!$priceSetId || !is_array($priceSet) || empty($priceSet) || !CRM_Utils_Array::value('optionsMaxValueTotal', $priceSet)) { return; } $skipParticipants = $formattedPriceSetDefaults = array(); if ($form->_allowConfirmation && (isset($form->_pId) || isset($form->_additionalParticipantId))) { $participantId = isset($form->_pId) ? $form->_pId : $form->_additionalParticipantId; $pricesetDefaults = CRM_Event_Form_EventFees::setDefaultPriceSet($participantId, $form->_eventId); // modify options full to respect the selected fields // options on confirmation. $formattedPriceSetDefaults = self::formatPriceSetParams($form, $pricesetDefaultOptions); // to skip current registered participants fields option count on confirmation. $skipParticipants[] = $form->_participantId; if (!empty($form->_additionalParticipantIds)) { $skipParticipants = array_merge($skipParticipants, $form->_additionalParticipantIds); } } $className = CRM_Utils_System::getClassName($form); //get the current price event price set options count. $currentOptionsCount = self::getPriceSetOptionCount($form); $recordedOptionsCount = CRM_Event_BAO_Participant::priceSetOptionsCount($form->_eventId, $skipParticipants); foreach ($form->_feeBlock as &$field) { $optionFullIds = array(); $fieldId = $field['id']; if (!is_array($field['options'])) { continue; } foreach ($field['options'] as &$option) { $optId = $option['id']; $count = CRM_Utils_Array::value('count', $option, 0); $maxValue = CRM_Utils_Array::value('max_value', $option, 0); $dbTotalCount = CRM_Utils_Array::value($optId, $recordedOptionsCount, 0); $currentTotalCount = CRM_Utils_Array::value($optId, $currentOptionsCount, 0); // Do not consider current count for select field, // since we are not going to freeze the options. if ($field['html_type'] == 'Select') { $totalCount = $dbTotalCount; } else { $totalCount = $currentTotalCount + $dbTotalCount; } $isFull = FALSE; if ($maxValue && ($totalCount >= $maxValue || $totalCount + $count > $maxValue)) { $isFull = TRUE; $optionFullIds[$optId] = $optId; } //here option is not full, //but we don't want to allow participant to increase //seats at the time of re-walking registration. if ($count && $form->_allowConfirmation && !empty($formattedPriceSetDefaults)) { if (!CRM_Utils_Array::value("price_{$field}", $formattedPriceSetDefaults) || !CRM_Utils_Array::value($opId, $formattedPriceSetDefaults["price_{$fieldId}"])) { $optionFullIds[$optId] = $optId; $isFull = TRUE; } } $option['is_full'] = $isFull; $option['db_total_count'] = $dbTotalCount; $option['total_option_count'] = $dbTotalCount + $currentTotalCount; } //ignore option full for offline registration. if ($className == 'CRM_Event_Form_Participant') { $optionFullIds = array(); } //finally get option ids in. $field['option_full_ids'] = $optionFullIds; } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign('additionalParticipant', $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactId}&context=participant"; if ($this->_context == 'standalone') { CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = 'reset=1&context=standalone'; $urlPath = 'civicrm/participant/add'; } if ($this->_id) { $urlParams .= "&action=update&id={$this->_id}"; } else { $urlParams .= "&action=add"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, FALSE, NULL, FALSE); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', FALSE, NULL, FALSE); } $this->assign('refreshURL', $url); $this->add('hidden', 'past_event'); $events = array(); if ($this->_eID) { $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'end_date'); } $this->assign('past', 0); if ($this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE); } elseif ($this->getElementValue('past_event') || isset($eventEndDate) && CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)) { $pastval = $this->getElementValue('past_event'); $events = CRM_Event_BAO_Event::getEvents($pastval); $this->assign('past', $pastval); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } // build array(event -> eventType) mapper $query = "\nSELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM civicrm_event\nWHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0"; $dao = CRM_Core_DAO::executeQuery($query); $eventAndTypeMapping = array(); while ($dao->fetch()) { $eventAndTypeMapping[$dao->id] = $dao->event_type_id; } $eventAndTypeMapping = json_encode($eventAndTypeMapping); // building of mapping ends -- //inherit the campaign from event. $eventCampaigns = array(); $allEventIds = array_keys($events); if (!empty($allEventIds)) { CRM_Core_PseudoConstant::populate($eventCampaigns, 'CRM_Event_DAO_Event', TRUE, 'campaign_id'); } $eventCampaigns = json_encode($eventCampaigns); $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, TRUE, array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge')); // CRM-6111 // note that embedding JS within PHP files is quite awful, IMO // but we do the same for the onChange element and this form is complex // and i did not want to break it late in the 3.2 cycle $preloadJSSnippet = NULL; if (CRM_Utils_Array::value('reset', $_GET) && $this->_eID) { $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} );\nCRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\nloadCampaign( {$this->_eID}, {$eventCampaigns} );\n});\n"; } $this->assign('preloadJSSnippet', $preloadJSSnippet); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } //CRM-7362 --add campaigns. $campaignId = NULL; if ($this->_id) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id'); } if (!$campaignId) { $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($eventId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id'); } } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $roleids = CRM_Event_PseudoConstant::participantRole(); foreach ($roleids as $rolekey => $rolevalue) { $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")); } $this->addGroup($roleTypes, 'role_id', ts('Participant Role')); $this->addRule('role_id', ts('Role is required'), 'required'); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = NULL; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } // get the participant status names to build special status array which is used to show notification // checkbox below participant status select $participantStatusName = CRM_Event_PseudoConstant::participantStatus(); $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired'); // get the required status and then implode only ids $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses))); $this->assign('notificationStatusIds', $notificationStatusIds); $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, TRUE, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS); $path = CRM_Utils_System::currentPath(); $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search'); if (!in_array($path, $excludeForPaths)) { $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS); } $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel')); $this->addButtons($buttons); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
public function setDefaultValues() { $params = array('id' => $this->_participantId); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId); $priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE); if (!empty($priceSetValues)) { $defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues); } $this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); if ($this->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$this->_participantId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $this->assign('fee_level', $fee_level); $this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); } $defaults = $defaults[$this->_participantId]; return $defaults; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = array(); $discountId = null; //fix for CRM-3088, default value for discount set. if (!empty($this->_values['discount'])) { require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event'); if ($discountId && CRM_Utils_Array::value('default_discount_fee_id', $this->_values['event'])) { $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id'); $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, true)); } } if ($this->_priceSetId) { foreach ($this->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { if ($val['html_type'] == 'CheckBox') { $defaults["price_{$key}"][$keys] = 1; } else { $defaults["price_{$key}"] = $keys; } } } } } //CRM-4320, setdefault additional participant values. if ($this->_allowConfirmation && $this->_additionalParticipantId) { require_once 'CRM/Event/Form/EventFees.php'; //hack to get set default from eventFees.php $this->_discountId = $discountId; $this->_pId = $this->_additionalParticipantId; $this->_contactID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id'); $participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this); $participantDefaults = array_merge($this->_defaults, $participantDefaults); // use primary email address if billing email address is empty if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) { $participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"]; } $defaults = array_merge($defaults, $participantDefaults); } $defaults = array_merge($this->_defaults, $defaults); return $defaults; }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { require_once 'CRM/Event/BAO/Event.php'; $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, null, $this->_contactId, false, true)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', null, $deleteParticipants, null, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign("additionalParticipant", $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactId}&context=participant"; if ($this->_context == 'standalone') { require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = "reset=1&context=standalone"; $urlPath = 'civicrm/participant/add'; } if ($this->_id) { $urlParams .= "&action=update&id={$this->_id}"; } else { $urlParams .= "&action=add"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false); } $this->assign("refreshURL", $url); $this->add('hidden', 'past_event'); $events = array(); $this->assign("past", false); require_once "CRM/Event/BAO/Event.php"; if ($this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(true, false, false); } elseif ($this->getElementValue('past_event')) { $events = CRM_Event_BAO_Event::getEvents(true); $this->assign("past", true); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true); } // build array(event -> eventType) mapper $query = "\nSELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM civicrm_event\nWHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0"; $dao =& CRM_Core_DAO::executeQuery($query); $eventAndTypeMapping = array(); while ($dao->fetch()) { $eventAndTypeMapping[$dao->id] = $dao->event_type_id; } $eventAndTypeMapping = json_encode($eventAndTypeMapping); // building of mapping ends -- $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );", 'class' => 'huge')); // CRM-6111 // note that embedding JS within PHP files is quite awful, IMO // but we do the same for the onChange element and this form is complex // and i did not want to break it late in the 3.2 cycle $preloadJSSnippet = null; if (CRM_Utils_Array::value('reset', $_GET)) { $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($this->_eID) { $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} ); \nbuildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\n});\n"; } } $this->assign('preloadJSSnippet', $preloadJSSnippet); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } $this->addDateTime('register_date', ts('Registration Date'), true, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $roleids = CRM_Event_PseudoConstant::participantRole(); foreach ($roleids as $rolekey => $rolevalue) { $roleTypes[] = HTML_QuickForm::createElement('checkbox', $rolekey, null, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")); } $this->addGroup($roleTypes, 'role_id', ts('Participant Role')); $this->addRule('role_id', ts('Role is required'), 'required'); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = null; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(null, null, 'label'); $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, true, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
public function setDefaultValues() { $params = array('id' => $this->_participantId); CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId); $priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE); $priceFieldId = array_keys($this->_values['fee']); if (!empty($priceSetValues)) { $defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues); } else { foreach ($priceFieldId as $key => $value) { if (!empty($value) && ($this->_values['fee'][$value]['html_type'] == 'Radio' || $this->_values['fee'][$value]['html_type'] == 'Select') && !$this->_values['fee'][$value]['is_required']) { $fee_keys = array_keys($this->_values['fee']); $defaults[$this->_participantId]['price_' . $fee_keys[$key]] = 0; } } } $this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); if ($this->_action == CRM_Core_Action::UPDATE) { $fee_level = $defaults[$this->_participantId]['fee_level']; CRM_Event_BAO_Participant::fixEventLevel($fee_level); $this->assign('fee_level', $fee_level); $this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); } $defaults = $defaults[$this->_participantId]; return $defaults; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { // check if the user is registered and we have a contact ID $session =& CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { $options = array(); $fields = array(); require_once "CRM/Core/BAO/CustomGroup.php"; if (!empty($this->_fields)) { $removeCustomFieldTypes = array('Participant'); foreach ($this->_fields as $name => $dontCare) { if (substr($name, 0, 7) == 'custom_') { $id = substr($name, 7); if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) { continue; } } else { if (substr($name, 0, 12) == 'participant_') { //ignore component fields continue; } } $fields[$name] = 1; } } $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}"); foreach ($names as $name) { $fields[$name] = 1; } $fields["state_province-{$this->_bltID}"] = 1; $fields["country-{$this->_bltID}"] = 1; $fields["email-{$this->_bltID}"] = 1; $fields["email-Primary"] = 1; require_once 'CRM/Core/BAO/UFGroup.php'; CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults); // use primary email address if billing email address is empty if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) { $this->_defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"]; } foreach ($names as $name) { if (isset($this->_defaults[$name])) { $this->_defaults["billing_" . $name] = $this->_defaults[$name]; } } } //if event is monetary and pay later is enabled and payment //processor is not available then freeze the pay later checkbox with //default check if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !is_array($this->_paymentProcessor)) { $this->_defaults['is_pay_later'] = 1; } //set custom field defaults if (!empty($this->_fields)) { require_once "CRM/Core/BAO/CustomField.php"; foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { if (!isset($this->_defaults[$name])) { //fix for CRM-1743 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, null, CRM_Profile_Form::MODE_REGISTER); } } } } //fix for CRM-3088, default value for discount set. $discountId = null; if (!empty($this->_values['discount'])) { require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event'); if ($discountId) { if (isset($this->_values['event']['default_discount_fee_id'])) { $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id'); $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, true)); } } } // now fix all state country selectors require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); // add this event's default participant role to defaults array (for cases where participant_role field is included in form via profile) if ($this->_values['event']['default_role_id']) { $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id']; } if ($this->_priceSetId) { foreach ($this->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { if ($values['is_default']) { if ($val['html_type'] == 'CheckBox') { $this->_defaults["price_{$key}"][$keys] = 1; } else { $this->_defaults["price_{$key}"] = $keys; } } } } } //set default participant fields, CRM-4320. $hasAdditionalParticipants = false; if ($this->_allowConfirmation) { require_once 'CRM/Event/Form/EventFees.php'; $this->_contactID = $contactID; $this->_discountId = $discountId; $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, false); $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this)); $this->_defaults['is_pay_later'] = $forcePayLater; if ($this->_additionalParticipantIds) { $hasAdditionalParticipants = true; $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds); } } $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants); // //hack to simplify credit card entry for testing // $this->_defaults['credit_card_type'] = 'Visa'; // $this->_defaults['credit_card_number'] = '4807731747657838'; // $this->_defaults['cvv2'] = '000'; // $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' ); // to process Custom data that are appended to URL require_once 'CRM/Core/BAO/CustomGroup.php'; $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'"); if (!empty($getDefaults)) { $this->_defaults = array_merge($this->_defaults, $getDefaults); } return $this->_defaults; }