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