/** * 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 civicrm_event_create(&$params) { _civicrm_initialize(); if (!is_array($params)) { return civicrm_create_error('Params is not an array'); } if (!isset($params['title']) || !isset($params['event_type_id']) || !isset($params['start_date'])) { return civicrm_create_error('Missing require fields ( title, event type id,start date)'); } $error = _civicrm_check_required_fields($params, 'CRM_Event_DAO_Event'); if ($error['is_error']) { return civicrm_create_error($error['error_message']); } // Do we really want $params[id], even if we have // $params[event_id]? if yes then please uncomment the below line //$ids['event' ] = $params['id']; $ids['eventTypeId'] = $params['event_type_id']; $ids['startDate'] = $params['start_date']; $ids['event_id'] = CRM_Utils_Array::value('event_id', $params); require_once 'CRM/Event/BAO/Event.php'; $eventBAO = CRM_Event_BAO_Event::create($params, $ids); if (is_a($eventBAO, 'CRM_Core_Error')) { return civicrm_create_error("Event is not created"); } else { $event = array(); _civicrm_object_to_array($eventBAO, $event); $values = array(); $values['event_id'] = $event['id']; $values['is_error'] = 0; } return $values; }
/** * Helper function to create * an Event * * @return $event id of created Event */ static function create($contactId) { require_once "CRM/Event/BAO/Event.php"; $params = array('title' => 'Test Event', 'event_type_id' => 1, 'default_role_id' => 1, 'participant_listing_id' => 1, 'summary' => 'Created for Test Coverage BAO', 'description' => 'Test Coverage BAO', 'is_public' => 1, 'start_date' => '20080526200000', 'end_date' => '20080530200000', 'is_active' => 1, 'contact_id' => $contactId); $event = CRM_Event_BAO_Event::create($params); return $event->id; }
/** * Create a Event * * This API is used for creating a Event * * @param array $params (reference ) input parameters * Allowed @params array keys are: * {@schema Event/Event.xml} * * @return array of newly created event property values. * @access public */ function civicrm_event_create(&$params) { _civicrm_initialize(true); try { civicrm_api_check_permission(__FUNCTION__, $params, true); civicrm_verify_mandatory($params, 'CRM_Event_DAO_Event', array('start_date', 'event_type_id', 'title')); // Do we really want $params[id], even if we have // $params[event_id]? if yes then please uncomment the below line //$ids['event' ] = $params['id']; $ids['eventTypeId'] = (int) $params['event_type_id']; $ids['startDate'] = $params['start_date']; $ids['event_id'] = CRM_Utils_Array::value('event_id', $params); require_once 'CRM/Event/BAO/Event.php'; $eventBAO = CRM_Event_BAO_Event::create($params, $ids); if (is_a($eventBAO, 'CRM_Core_Error')) { return civicrm_create_error("Event is not created"); } else { $event = array(); _civicrm_object_to_array($eventBAO, $event); $values = array(); $values['event_id'] = $event['id']; $values['is_error'] = 0; } return $values; } catch (Exception $e) { return civicrm_create_error($e->getMessage()); } }
/** * Create a Event * * This API is used for creating a Event * * @param array $params input parameters * Allowed @params array keys are: * {@getfields event_create} * * @return array API result Array. * @access public */ function civicrm_api3_event_create($params) { _civicrm_api3_event_create_legacy_support_42($params); //format custom fields so they can be added $value = array(); _civicrm_api3_custom_format_params($params, $values, 'Event'); $params = array_merge($values, $params); require_once 'CRM/Event/BAO/Event.php'; $eventBAO = CRM_Event_BAO_Event::create($params); $event = array(); _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]); return civicrm_api3_create_success($event, $params); }
/** * Create a Event * * This API is used for creating a Event * * @param array $params input parameters * Allowed @params array keys are: * {@getfields event_create} * * @return array API result Array. * @access public */ function civicrm_api3_event_create($params) { civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id')); // Clone event from template if (!empty($params['template_id']) && empty($params['id'])) { $copy = CRM_Event_BAO_Event::copy($params['template_id']); $params['id'] = $copy->id; unset($params['template_id']); if (empty($params['is_template'])) { $params['is_template'] = 0; } } _civicrm_api3_event_create_legacy_support_42($params); //format custom fields so they can be added $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Event'); $params = array_merge($values, $params); $eventBAO = CRM_Event_BAO_Event::create($params); $event = array(); _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]); return civicrm_api3_create_success($event, $params); }
/** * Process the form submission. */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), TRUE); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); $params['id'] = $this->_id; $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Event'); //merge params with defaults from templates if (!empty($params['template_id'])) { $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (!empty($params['template_id'])) { CRM_Event_BAO_Event::copy($params['template_id'], $event, TRUE); } $this->set('id', $event->id); $this->postProcessHook(); if ($this->_action & CRM_Core_Action::ADD) { $url = 'civicrm/event/manage/location'; $urlParams = "action=update&reset=1&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { $url = 'civicrm/event/manage'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())), ts('Saved'), 'success'); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } parent::endPostProcess(); }
/** * Add participant with contribution * * @return array */ protected function addParticipantWithContribution() { // creating price set, price field require_once 'CiviTest/Event.php'; $this->_contactId = Contact::createIndividual(); $this->_eventId = Event::create($this->_contactId); $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4); $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); $paramsSet['is_active'] = TRUE; $paramsSet['financial_type_id'] = 4; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); $priceSetId = $priceset->id; //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name')); $priceField = CRM_Price_BAO_PriceField::create($paramsField); $eventParams = array('id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1); CRM_Event_BAO_Event::create($eventParams); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId); $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); $participantParams = array('financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', 'contact_id' => $this->_contactId); $participant = CRM_Event_BAO_Participant::add($participantParams); $contributionParams = array('total_amount' => 150, 'currency' => 'USD', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'contribution_status_id' => 1, 'partial_payment_total' => 300.0, 'partial_amount_pay' => 150, 'contribution_mode' => 'participant', 'participant_id' => $participant->id); foreach ($priceFields['values'] as $key => $priceField) { $lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']); } $contributionParams['line_item'] = $lineItems; $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams); $paymentParticipant = array('participant_id' => $participant->id, 'contribution_id' => $contributions->id); $ids = array(); CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids); return array($lineItems, $contributions); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false); $params['id'] = $this->_id; //new event, so lets set the created_id if ($this->_action & CRM_Core_Action::ADD) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); require_once 'CRM/Event/BAO/Event.php'; // copy all not explicitely set $params keys from the template (if it should be sourced) if (CRM_Utils_Array::value('template_id', $params)) { $defaults = array(); $templateParams = array('id' => $params['template_id']); CRM_Event_BAO_Event::retrieve($templateParams, $defaults); unset($defaults['id']); unset($defaults['default_fee_id']); unset($defaults['default_discount_fee_id']); foreach ($defaults as $key => $value) { if (!isset($params[$key])) { $params[$key] = $value; } } } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy event fees $ogParams = array('name' => "civicrm_event.amount.{$event->id}"); $defaults = array(); require_once 'CRM/Core/BAO/OptionGroup.php'; if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) { // Copy the Main Event Fees CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id); // Copy the Discount option Group and Values require_once 'CRM/Core/BAO/Discount.php'; $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event"); foreach ($optionGroupIds as $id) { $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label'); CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix); } } // copy price sets if any require_once 'CRM/Price/BAO/Set.php'; $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Core/BAO/UFJoin.php'; if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Friend/BAO/Friend.php'; if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") { $urlParam = "action=update&reset=1&id={$event->id}"; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam)); } parent::endPostProcess(); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), TRUE); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); $params['id'] = $this->_id; $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); //merge params with defaults from templates if (CRM_Utils_Array::value('template_id', $params)) { $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy price sets if any $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config'); if ($isQuickConfig) { $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId); $priceSetId = $copyPriceSet->id; } CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; if (isset($tafParams['id'])) { unset($tafParams['id']); } CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } //copy pcp settings CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id), array('replace' => array('target_entity_id' => $event->id))); //copy event schedule remainder CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $params['template_id']), array('entity_value' => $event->id)); } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $url = 'civicrm/event/manage/location'; $urlParams = "action=update&reset=1&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { $url = 'civicrm/event/manage'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } parent::endPostProcess(); }