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; }
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; } }
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; }