public function postProcess() { $params = $this->exportValues(); $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * Create a Event * * This API is used for creating a Event * * @param array $params an associative array of title/value property values of civicrm_event * * @return array of newly created event property values. * @access public */ function crm_create_event($params) { _crm_initialize(); if (!is_array($params)) { return _crm_error('Params is not an array.'); } if (!$params["title"] || !$params['event_type_id'] || !$params['start_date']) { return _crm_error('Missing require fileds ( title, event type id,start date)'); } $error = _crm_check_required_fields($params, 'CRM_Event_DAO_Event'); if (is_a($error, 'CRM_Core_Error')) { return $error; } $ids['event'] = $params['id']; $ids['eventTypeId'] = $params['event_type_id']; $ids['startDate'] = $params['start_date']; require_once 'CRM/Event/BAO/Event.php'; $eventBAO = CRM_Event_BAO_Event::add($params, $ids); $event = array(); _crm_object_to_array($eventBAO, $event); return $event; }
/** * Process the form. */ public function postProcess() { $eventTitle = ''; $params = $this->exportValues(); $this->set('discountSection', 0); if (!empty($_POST['_qf_Fee_submit'])) { $this->buildAmountLabel(); $this->set('discountSection', 2); return; } if (!empty($params['payment_processor'])) { $params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']); } else { $params['payment_processor'] = 'null'; } $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0); $params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0); if ($this->_id) { // delete all the prior label values or discounts in the custom options table // and delete a price set if one exists //@todo note that this removes the reference from existing participants - // even where there is not change - redress? // note that a more tentative form of this is invoked by passing price_set_id as an array // to event.create see CRM-14069 // @todo get all of this logic out of form layer (currently partially in BAO/api layer) if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) { CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event'); } } if ($params['is_monetary']) { if (!empty($params['price_set_id'])) { //@todo this is now being done in the event BAO if passed price_set_id as an array // per notes on that fn - looking at the api converting to an array // so calling via the api may cause this to be done in the api CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']); if (!empty($params['price_field_id'])) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0); } } else { // if there are label / values, create custom options for them $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($options)) { $params['default_fee_id'] = NULL; if (empty($params['price_set_id'])) { if (empty($params['price_field_id'])) { $setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title']; $eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245)); if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) { $setParams['name'] = $eventTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $this->_id; } else { $timeSec = explode('.', microtime(TRUE)); $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['financial_type_id'] = $params['financial_type_id']; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_PriceSet::create($setParams); $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245)); $fieldParams['price_set_id'] = $priceSet->id; } else { foreach ($params['price_field_value'] as $arrayID => $fieldValueID) { if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) { CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0'); unset($params['price_field_value'][$arrayID]); } } $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params); $fieldParams['option_id'] = $params['price_field_value']; $priceSet = new CRM_Price_BAO_PriceSet(); $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id'); if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']); } } $fieldParams['label'] = $params['fee_label']; $fieldParams['html_type'] = 'Radio'; CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id); $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; $fieldParams['financial_type_id'] = $params['financial_type_id']; foreach ($options as $value) { $fieldParams['option_weight'][$value['weight']] = $value['weight']; } $fieldParams['default_option'] = $params['default']; $priceField = CRM_Price_BAO_PriceField::create($fieldParams); } } } $discountPriceSets = !empty($this->_defaultValues['discount_price_set']) ? $this->_defaultValues['discount_price_set'] : array(); $discountFieldIDs = !empty($this->_defaultValues['discount_option_id']) ? $this->_defaultValues['discount_option_id'] : array(); if (CRM_Utils_Array::value('is_discount', $params) == 1) { // if there are discounted set of label / values, // create custom options for them $labels = CRM_Utils_Array::value('discounted_label', $params); $values = CRM_Utils_Array::value('discounted_value', $params); $default = CRM_Utils_Array::value('discounted_default', $params); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) { $discountOptions = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))) { $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($discountOptions)) { $fieldParams = array(); $params['default_discount_fee_id'] = NULL; $keyCheck = $j - 1; $setParams = array(); if (empty($discountPriceSets[$keyCheck])) { if (!$eventTitle) { $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200)); } $setParams['title'] = $params['discount_name'][$j]; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j]; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id; } else { $timeSec = explode('.', microtime(TRUE)); $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['financial_type_id'] = $params['financial_type_id']; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_PriceSet::create($setParams); $priceSetID = $priceSet->id; } else { $priceSetID = $discountPriceSets[$j - 1]; $setParams = array('title' => $params['discount_name'][$j], 'id' => $priceSetID); if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) { $setParams['financial_type_id'] = $params['financial_type_id']; } CRM_Price_BAO_PriceSet::create($setParams); unset($discountPriceSets[$j - 1]); $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id'); } $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; $fieldParams['is_required'] = 1; $fieldParams['price_set_id'] = $priceSetID; $fieldParams['html_type'] = 'Radio'; $fieldParams['financial_type_id'] = $params['financial_type_id']; foreach ($discountOptions as $value) { $fieldParams['option_label'][$value['weight']] = $value['label']; $fieldParams['option_amount'][$value['weight']] = $value['value']; $fieldParams['option_weight'][$value['weight']] = $value['weight']; if (!empty($value['is_default'])) { $fieldParams['default_option'] = $value['weight']; } if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) { $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']]; unset($discountFieldIDs[$j][$value['weight']]); } } //create discount priceset $priceField = CRM_Price_BAO_PriceField::create($fieldParams); if (!empty($discountFieldIDs[$j])) { foreach ($discountFieldIDs[$j] as $fID) { CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0'); } } $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'price_set_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]), 'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j])); CRM_Core_BAO_Discount::add($discountParams); } } } } if (!empty($discountPriceSets)) { foreach ($discountPriceSets as $setId) { CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0); } } } } else { if (!empty($params['price_field_id'])) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0); } $params['financial_type_id'] = ''; $params['is_pay_later'] = 0; $params['is_billing_required'] = 0; } //update 'is_billing_required' if (empty($params['is_pay_later'])) { $params['is_billing_required'] = FALSE; } //update events table $params['id'] = $this->_id; // skip update of financial type in price set $params['skipFinancialType'] = TRUE; CRM_Event_BAO_Event::add($params); // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = !empty($params['is_monetary']); parent::endPostProcess(); }
public function postProcess() { $params = array(); $params = $this->exportValues(); if (trim($params['parent_event_name']) === '') { # believe me... $params['parent_event_id'] = ''; } //update events table $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * EventFull() method (checking the event for full ) */ public function testEventFull() { $eventParams = array('max_participants' => 1, 'id' => $this->_eventId); CRM_Event_BAO_Event::add($eventParams); $participantId = Participant::create($this->_contactId, $this->_eventId); $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->assertEquals($eventFull, 'This event is full.', 'Checking if Event is full.'); Participant::delete($participantId); Contact::delete($this->_contactId); Event::delete($this->_eventId); }
/** * DeleteLocBlock() method * delete the location block * created with various elements. */ public function testDeleteLocBlock() { $this->_contactId = $this->individualCreate(); //create test event record. $event = $this->eventCreate(); $params['location'][1] = array('location_type_id' => 1, 'is_primary' => 1, 'address' => array('street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', 'city' => 'Newark', 'postal_code' => '01903', 'country_id' => 1228, 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973'), 'email' => array('1' => array('email' => '*****@*****.**')), 'phone' => array('1' => array('phone_type_id' => 1, 'phone' => '303443689'), '2' => array('phone_type_id' => 2, 'phone' => '9833910234')), 'im' => array('1' => array('name' => 'jane.doe', 'provider_id' => 1))); $params['entity_id'] = $event['id']; $params['entity_table'] = 'civicrm_event'; //create location block. //with various elements //like address, phone, email, im. $location = CRM_Core_BAO_Location::create($params, NULL, TRUE); $locBlockId = CRM_Utils_Array::value('id', $location); //update event record with location block id $eventParams = array('id' => $event['id'], 'loc_block_id' => $locBlockId); CRM_Event_BAO_Event::add($eventParams); //delete the location block CRM_Core_BAO_Location::deleteLocBlock($locBlockId); //Now check DB for location elements. //Now check DB for Address $this->assertDBNull('CRM_Core_DAO_Address', 'Saint Helier St', 'id', 'street_address', 'Database check, Address deleted successfully.'); //Now check DB for Email $this->assertDBNull('CRM_Core_DAO_Email', '*****@*****.**', 'id', 'email', 'Database check, Email deleted successfully.'); //Now check DB for Phone $this->assertDBNull('CRM_Core_DAO_Phone', '303443689', 'id', 'phone', 'Database check, Phone deleted successfully.'); //Now check DB for Mobile $this->assertDBNull('CRM_Core_DAO_Phone', '9833910234', 'id', 'phone', 'Database check, Mobile deleted successfully.'); //Now check DB for IM $this->assertDBNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name', 'Database check, IM deleted successfully.'); //cleanup DB by deleting the record. $this->eventDelete($event['id']); $this->contactDelete($this->_contactId); //Now check DB for Event $this->assertDBNull('CRM_Event_DAO_Event', $event['id'], 'id', 'id', 'Database check, Event deleted successfully.'); }
/** * Process the form submission. * * * @return void */ public function postProcess() { $params = $this->exportValues(); $params['id'] = $this->_id; // format params $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, FALSE); $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE); // CRM-11182 $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, FALSE); $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, FALSE); $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, FALSE); // reset is_email confirm if not online reg if (!$params['is_online_registration']) { $params['is_email_confirm'] = FALSE; } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], $params['registration_start_date_time'], TRUE); $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], $params['registration_end_date_time'], TRUE); } CRM_Event_BAO_Event::add($params); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviEvent', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); $uf = array(); $wt = 2; if (!empty($params['custom_pre_id'])) { $uf[1] = $params['custom_pre_id']; $wt = 1; } if (!empty($params['custom_post_id'])) { $uf[2] = $params['custom_post_id']; } if (!empty($params['custom_post_id_multiple'])) { $uf = array_merge($uf, $params['custom_post_id_multiple']); } $uf = array_values($uf); if (!empty($uf)) { foreach ($uf as $weight => $ufGroupId) { $ufJoinParams['weight'] = $weight + $wt; $ufJoinParams['uf_group_id'] = $ufGroupId; CRM_Core_BAO_UFJoin::create($ufJoinParams); unset($ufJoinParams['id']); } } // also update the ProfileModule tables $ufJoinParamsAdd = array('is_active' => 1, 'module' => 'CiviEvent_Additional', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParamsAdd); if (!empty($params['is_multiple_registrations'])) { $ufAdd = array(); $wtAdd = 2; if (array_key_exists('additional_custom_pre_id', $params)) { if (empty($params['additional_custom_pre_id'])) { $ufAdd[1] = $params['custom_pre_id']; $wtAdd = 1; } elseif (CRM_Utils_Array::value('additional_custom_pre_id', $params) == 'none') { } else { $ufAdd[1] = $params['additional_custom_pre_id']; $wtAdd = 1; } } if (array_key_exists('additional_custom_post_id', $params)) { if (empty($params['additional_custom_post_id'])) { $ufAdd[2] = $params['custom_post_id']; } elseif (CRM_Utils_Array::value('additional_custom_post_id', $params) == 'none') { } else { $ufAdd[2] = $params['additional_custom_post_id']; } } if (!empty($params['additional_custom_post_id_multiple'])) { $additionalPostMultiple = array(); foreach ($params['additional_custom_post_id_multiple'] as $key => $value) { if (is_null($value) && !empty($params['custom_post_id'])) { $additionalPostMultiple[$key] = $params['custom_post_id']; } elseif ($value == 'none') { continue; } elseif ($value) { $additionalPostMultiple[$key] = $value; } } $ufAdd = array_merge($ufAdd, $additionalPostMultiple); } $ufAdd = array_values($ufAdd); if (!empty($ufAdd)) { foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) { $ufJoinParamsAdd['weight'] = $weightAdd + $wtAdd; $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd; CRM_Core_BAO_UFJoin::create($ufJoinParamsAdd); unset($ufJoinParamsAdd['id']); } } } // get the profiles to evaluate what they collect $profileIds = array(CRM_Utils_Array::value('custom_pre_id', $params), CRM_Utils_Array::value('custom_post_id', $params)); $additionalProfileIds = array(CRM_Utils_Array::value('additional_custom_pre_id', $params), CRM_Utils_Array::value('additional_custom_post_id', $params)); // additional profile fields default to main if not set if (!is_numeric($additionalProfileIds[0])) { $additionalProfileIds[0] = $profileIds[0]; } if (!is_numeric($additionalProfileIds[1])) { $additionalProfileIds[1] = $profileIds[1]; } //add multiple profiles if set self::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple'); self::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple'); $cantDedupe = FALSE; $rgId = CRM_Utils_Array::value('dedupe_rule_group_id', $params, 0); switch (self::canProfilesDedupe($profileIds, $rgId)) { case 0: $dedupeTitle = 'Duplicate Matching Impossible'; $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact."); break; case 1: $dedupeTitle = 'Duplicate Contacts Possible'; $cantDedupe = ts("The selected profiles can collect enough information to match registrations with existing contacts, but not all of the relevant fields are required. Anonymous registrations may result in duplicate contacts."); } if (!empty($params['is_multiple_registrations'])) { switch (self::canProfilesDedupe($additionalProfileIds, $rgId)) { case 0: $dedupeTitle = 'Duplicate Matching Impossible'; if ($cantDedupe) { $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact."); } else { $cantDedupe = ts("The selected profiles do not contain the fields necessary to match additional participants with existing contacts. This means all additional participants will result in a new contact."); } break; case 1: if (!$cantDedupe) { $dedupeTitle = 'Duplicate Contacts Possible'; $cantDedupe = ts("The selected profiles can collect enough information to match additional participants with existing contacts, but not all of the relevant fields are required. This may result in duplicate contacts."); } } } if ($cantDedupe) { CRM_Core_Session::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0)); } // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = !empty($params['is_online_registration']); parent::endPostProcess(); }
/** * EventFull() method (checking the event for full ) */ public function testEventFull() { $eventParams = array('max_participants' => 1, 'id' => $this->_eventId); CRM_Event_BAO_Event::add($eventParams); $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.'); $this->participantDelete($participantId); $this->contactDelete($this->_contactId); $this->eventDelete($this->_eventId); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = array(); $params = $this->exportValues(); $params['id'] = $this->_id; //format params $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, false); $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, false); $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, false); $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, false); // reset is_email confirm if not online reg if (!$params['is_online_registration']) { $params['is_email_confirm'] = false; } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], $params['registration_start_date_time'], true); $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], $params['registration_end_date_time'], true); } require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::add($params); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviEvent', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); require_once 'CRM/Core/BAO/UFJoin.php'; // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); if (!empty($params['custom_pre_id'])) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['custom_pre_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } unset($ufJoinParams['id']); if (!empty($params['custom_post_id'])) { $ufJoinParams['weight'] = 2; $ufJoinParams['uf_group_id'] = $params['custom_post_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } // CRM-4377: also update the profiles for additional participants $ufJoinParams['module'] = 'CiviEvent_Additional'; $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['custom_pre_id']; if ($params['additional_custom_pre_id'] == 'none') { $ufJoinParams['is_active'] = 0; } elseif ($params['additional_custom_pre_id']) { $ufJoinParams['uf_group_id'] = $params['additional_custom_pre_id']; } CRM_Core_BAO_UFJoin::create($ufJoinParams); $ufJoinParams['weight'] = 2; $ufJoinParams['uf_group_id'] = $params['custom_post_id']; if ($params['additional_custom_post_id'] == 'none') { $ufJoinParams['is_active'] = 0; } elseif ($params['additional_custom_post_id']) { //minor fix for CRM-4377 $ufJoinParams['is_active'] = 1; $ufJoinParams['uf_group_id'] = $params['additional_custom_post_id']; } CRM_Core_BAO_UFJoin::create($ufJoinParams); parent::endPostProcess(); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->exportValues(); $delteOldBlock = false; // if 'use existing location' option is selected - if ($params['location_option'] == 2 && CRM_Utils_Array::value('loc_event_id', $params) && $params['loc_event_id'] != $this->_oldLocBlockId) { // if new selected loc is different from old loc, update the loc_block_id // so that loc update would affect the selected loc and not the old one. $delteOldBlock = true; CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', $params['loc_event_id']); } // if 'create new loc' option is selected, set the loc_block_id for this event to null // so that an update would result in creating a new loc. if ($this->_oldLocBlockId && $params['location_option'] == 1) { $delteOldBlock = true; CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id, 'loc_block_id', 'null'); } // if 'create new loc' optioin is selected OR selected new loc is different // from old one, go ahead and delete the old loc provided thats not being // used by any other event if ($this->_oldLocBlockId && $delteOldBlock) { CRM_Event_BAO_Event::deleteEventLocBlock($this->_oldLocBlockId, $this->_id); } // get ready with location block params $params['entity_table'] = 'civicrm_event'; $params['entity_id'] = $this->_id; require_once 'CRM/Core/BAO/LocationType.php'; $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); foreach (array('address', 'phone', 'email') as $block) { if (!CRM_Utils_Array::value($block, $params) || !is_array($params[$block])) { continue; } foreach ($params[$block] as $count => &$values) { if ($count == 1) { $values['is_primary'] = 1; } $values['location_type_id'] = $defaultLocationType->id ? $defaultLocationType->id : 1; } } // create/update event location require_once 'CRM/Core/BAO/Location.php'; $location = CRM_Core_BAO_Location::create($params, true, 'event'); $params['loc_block_id'] = $location['id']; // finally update event params $params['id'] = $this->_id; require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * Process the form * * @return void * @access public */ public function postProcess() { $params = array(); $params = $this->exportValues(); $this->set('discountSection', 0); if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) { $this->buildAmountLabel(); $this->set('discountSection', 1); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage', '#isDiscount')); return; } $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0); if ($this->_id) { require_once 'CRM/Price/BAO/Set.php'; // delete all the prior label values or discounts in the custom options table // and delete a price set if one exists if (!CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) { require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}"); CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}.discount.%", "LIKE"); } } if ($params['is_monetary']) { if ($params['price_set_id']) { CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']); } else { // if there are label / values, create custom options for them $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($options)) { $params['default_fee_id'] = null; CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}", $options, $params['default_fee_id']); } } if (CRM_Utils_Array::value('is_discount', $params) == 1) { // if there are discounted set of label / values, // create custom options for them $labels = CRM_Utils_Array::value('discounted_label', $params); $values = CRM_Utils_Array::value('discounted_value', $params); $default = CRM_Utils_Array::value('discounted_default', $params); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) { $discountOptions = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && CRM_Utils_Array::value($j, $values[$i])) { $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($discountOptions)) { $params['default_discount_fee_id'] = null; $discountOptionsGroupId = CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}.discount.{$params['discount_name'][$j]}", $discountOptions, $params['default_discount_fee_id'], $params['discount_name'][$j]); $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $discountOptionsGroupId, 'start_date' => CRM_Utils_Date::format($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::format($params["discount_end_date"][$j])); require_once 'CRM/Core/BAO/Discount.php'; CRM_Core_BAO_Discount::add($discountParams); } } } } } } else { $params['contribution_type_id'] = ''; } //update events table require_once 'CRM/Event/BAO/Event.php'; $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $params = array(); $params = $this->exportValues(); $params['id'] = $this->_id; //format params $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, FALSE); $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, FALSE); $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, FALSE); $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, FALSE); // reset is_email confirm if not online reg if (!$params['is_online_registration']) { $params['is_email_confirm'] = FALSE; } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], $params['registration_start_date_time'], TRUE); $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], $params['registration_end_date_time'], TRUE); } CRM_Event_BAO_Event::add($params); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviEvent', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); $uf = array(); $wt = 2; if (!empty($params['custom_pre_id'])) { $uf[1] = $params['custom_pre_id']; $wt = 1; } if (!empty($params['custom_post_id'])) { $uf[2] = $params['custom_post_id']; } if (CRM_Utils_Array::value('custom_post_id_multiple', $params)) { $uf = array_merge($uf, $params['custom_post_id_multiple']); } $uf = array_values($uf); if (!empty($uf)) { foreach ($uf as $weight => $ufGroupId) { $ufJoinParams['weight'] = $weight + $wt; $ufJoinParams['uf_group_id'] = $ufGroupId; CRM_Core_BAO_UFJoin::create($ufJoinParams); unset($ufJoinParams['id']); } } // also update the ProfileModule tables $ufJoinParamsAdd = array('is_active' => 1, 'module' => 'CiviEvent_Additional', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParamsAdd); if (CRM_Utils_Array::value('is_multiple_registrations', $params)) { $ufAdd = array(); $wtAdd = 2; if (array_key_exists('additional_custom_pre_id', $params)) { if (!CRM_Utils_Array::value('additional_custom_pre_id', $params)) { $ufAdd[1] = $params['custom_pre_id']; $wtAdd = 1; } elseif (CRM_Utils_Array::value('additional_custom_pre_id', $params) == 'none') { } else { $ufAdd[1] = $params['additional_custom_pre_id']; $wtAdd = 1; } } if (array_key_exists('additional_custom_post_id', $params)) { if (!CRM_Utils_Array::value('additional_custom_post_id', $params)) { $ufAdd[2] = $params['custom_post_id']; } elseif (CRM_Utils_Array::value('additional_custom_post_id', $params) == 'none') { } else { $ufAdd[2] = $params['additional_custom_post_id']; } } if (CRM_Utils_Array::value('additional_custom_post_id_multiple', $params)) { $additionalPostMultiple = array(); foreach ($params['additional_custom_post_id_multiple'] as $key => $value) { if (!$value && CRM_Utils_Array::value('custom_post_id', $params)) { $additionalPostMultiple[$key] = $params['custom_post_id']; } elseif ($value == 'none') { continue; } elseif ($value) { $additionalPostMultiple[$key] = $value; } } $ufAdd = array_merge($ufAdd, $additionalPostMultiple); } $ufAdd = array_values($ufAdd); if (!empty($ufAdd)) { foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) { $ufJoinParamsAdd['weight'] = $weightAdd + $wtAdd; $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd; CRM_Core_BAO_UFJoin::create($ufJoinParamsAdd); unset($ufJoinParamsAdd['id']); } } } parent::endPostProcess(); }
/** * Process the form * * @return void * @access public */ public function postProcess() { $params = array(); $eventTitle = ''; $params = $this->exportValues(); $this->set('discountSection', 0); if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) { $this->buildAmountLabel(); $this->set('discountSection', 2); return; } if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) { $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor'])); } else { $params['payment_processor'] = 'null'; } $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0); if ($this->_id) { // delete all the prior label values or discounts in the custom options table // and delete a price set if one exists if (CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) { CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event'); } } if ($params['is_monetary']) { if (CRM_Utils_Array::value('price_set_id', $params)) { CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']); if (CRM_Utils_Array::value('price_field_id', $params)) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } } else { // if there are label / values, create custom options for them $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($options)) { $params['default_fee_id'] = NULL; if (!CRM_Utils_Array::value('price_set_id', $params)) { if (!CRM_Utils_Array::value('price_field_id', $params)) { $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle, 'id', 'title')) { $setParams['name'] = $setParams['title'] = $eventTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $this->_id, 'id', 'title')) { $setParams['name'] = $setParams['title'] = $eventTitle . '_' . $this->_id; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $setParams['title'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; $fieldParams['price_set_id'] = $priceSet->id; } else { foreach ($params['price_field_value'] as $arrayID => $fieldValueID) { if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) { CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0'); unset($params['price_field_value'][$arrayID]); } } $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params); $fieldParams['option_id'] = $params['price_field_value']; $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id'); } $fieldParams['html_type'] = 'Radio'; CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id); $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; foreach ($options as $value) { $fieldParams['option_weight'][$value['weight']] = $value['weight']; } $fieldParams['default_option'] = $params['default']; $priceField = CRM_Price_BAO_Field::create($fieldParams); } } } $discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array(); $discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array(); if (CRM_Utils_Array::value('is_discount', $params) == 1) { // if there are discounted set of label / values, // create custom options for them $labels = CRM_Utils_Array::value('discounted_label', $params); $values = CRM_Utils_Array::value('discounted_value', $params); $default = CRM_Utils_Array::value('discounted_default', $params); if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) { for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) { $discountOptions = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (!empty($labels[$i]) && !empty($values[$i][$j])) { $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } if (!empty($discountOptions)) { $fieldParams = array(); $params['default_discount_fee_id'] = NULL; $keyCheck = $j - 1; if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) { if (!$eventTitle) { $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200)); } $setParams['title'] = $params['discount_name'][$j]; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j]; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetID = $priceSet->id; } else { $priceSetID = $discountPriceSets[$j - 1]; unset($discountPriceSets[$j - 1]); $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id'); } $fieldParams['name'] = $fieldParams['label'] = $params['fee_label']; $fieldParams['is_required'] = 1; $fieldParams['price_set_id'] = $priceSetID; $fieldParams['html_type'] = 'Radio'; foreach ($discountOptions as $value) { $fieldParams['option_label'][$value['weight']] = $value['label']; $fieldParams['option_amount'][$value['weight']] = $value['value']; $fieldParams['option_weight'][$value['weight']] = $value['weight']; if (CRM_Utils_Array::value('is_default', $value)) { $fieldParams['default_option'] = $value['weight']; } if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'] - 1, $discountFieldIDs[$j])) { $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight'] - 1]; unset($discountFieldIDs[$j][$value['weight'] - 1]); } } //create discount priceset $priceField = CRM_Price_BAO_Field::create($fieldParams); if (!empty($discountFieldIDs)) { foreach ($discountFieldIDs as $fID) { CRM_Price_BAO_FieldValue::setIsActive($fID, '0'); } } $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::processDate($params["discount_end_date"][$j])); CRM_Core_BAO_Discount::add($discountParams); } } } } if (!empty($discountPriceSets)) { foreach ($discountPriceSets as $setId) { CRM_Price_BAO_Set::setIsQuickConfig($setId, 0); } } } } else { if (CRM_Utils_Array::value('price_field_id', $params)) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } $params['contribution_type_id'] = ''; } //update events table $params['id'] = $this->_id; CRM_Event_BAO_Event::add($params); parent::endPostProcess(); }
/** * eventFull() method (checking the event for full ) */ function testeventFull() { require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::add($eventParams = array('max_participants' => 1, 'id' => $this->_eventId)); $participantId = Participant::create($this->_contactId, $this->_eventId); $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->assertEquals($eventFull, 'This event is full !!!', 'Checking if Event is full.'); Participant::delete($participantId); Contact::delete($this->_contactId); Event::delete($this->_eventId); }