Exemplo n.º 1
0
 /**
  * @param CRM_Core_Form $form
  * @param int $id
  * @param string $entityTable
  * @param bool $validOnly
  * @param int $priceSetId
  *
  * @return bool|false|int|null
  */
 public static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL)
 {
     if (!$priceSetId) {
         $priceSetId = self::getFor($entityTable, $id);
     }
     //check if priceset is is_config
     if (is_numeric($priceSetId)) {
         if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config') && $form->getVar('_name') != 'Participant') {
             $form->assign('quickConfig', 1);
         }
     }
     // get price info
     if ($priceSetId) {
         if ($form->_action & CRM_Core_Action::UPDATE) {
             $entityId = $entity = NULL;
             switch ($entityTable) {
                 case 'civicrm_event':
                     $entity = 'participant';
                     if (CRM_Utils_System::getClassName($form) == 'CRM_Event_Form_Participant') {
                         $entityId = $form->_id;
                     } else {
                         $entityId = $form->_participantId;
                     }
                     break;
                 case 'civicrm_contribution_page':
                 case 'civicrm_contribution':
                     $entity = 'contribution';
                     $entityId = $form->_id;
                     break;
             }
             if ($entityId && $entity) {
                 $form->_values['line_items'] = CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::getLineItems($entityId, $entity);
             }
             $required = FALSE;
         } else {
             $required = TRUE;
         }
         $form->_priceSetId = $priceSetId;
         $priceSet = self::getSetDetail($priceSetId, $required, $validOnly);
         $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
         $form->_values['fee'] = CRM_Utils_Array::value('fields', $form->_priceSet);
         //get the price set fields participant count.
         if ($entityTable == 'civicrm_event') {
             //get option count info.
             $form->_priceSet['optionsCountTotal'] = self::getPricesetCount($priceSetId);
             if ($form->_priceSet['optionsCountTotal']) {
                 $optionsCountDeails = array();
                 if (!empty($form->_priceSet['fields'])) {
                     foreach ($form->_priceSet['fields'] as $field) {
                         foreach ($field['options'] as $option) {
                             $count = CRM_Utils_Array::value('count', $option, 0);
                             $optionsCountDeails['fields'][$field['id']]['options'][$option['id']] = $count;
                         }
                     }
                 }
                 $form->_priceSet['optionsCountDetails'] = $optionsCountDeails;
             }
             //get option max value info.
             $optionsMaxValueTotal = 0;
             $optionsMaxValueDetails = array();
             if (!empty($form->_priceSet['fields'])) {
                 foreach ($form->_priceSet['fields'] as $field) {
                     foreach ($field['options'] as $option) {
                         $maxVal = CRM_Utils_Array::value('max_value', $option, 0);
                         $optionsMaxValueDetails['fields'][$field['id']]['options'][$option['id']] = $maxVal;
                         $optionsMaxValueTotal += $maxVal;
                     }
                 }
             }
             $form->_priceSet['optionsMaxValueTotal'] = $optionsMaxValueTotal;
             if ($optionsMaxValueTotal) {
                 $form->_priceSet['optionsMaxValueDetails'] = $optionsMaxValueDetails;
             }
         }
         $form->set('priceSetId', $form->_priceSetId);
         $form->set('priceSet', $form->_priceSet);
         return $priceSetId;
     }
     return FALSE;
 }