本文整理汇总了PHP中CRM_Event_BAO_Participant::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Event_BAO_Participant::create方法的具体用法?PHP CRM_Event_BAO_Participant::create怎么用?PHP CRM_Event_BAO_Participant::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Event_BAO_Participant
的用法示例。
在下文中一共展示了CRM_Event_BAO_Participant::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_participant_create
/**
* Create an Event Participant
*
* This API is used for creating a participants in an event.
* Required parameters : event_id AND contact_id for new creation
* : participant as name/value with participantid for edit
* @param array $params an associative array of name/value property values of civicrm_participant
*
* @return array participant id if participant is created/edited otherwise is_error = 1
* @access public
*/
function civicrm_participant_create(&$params)
{
_civicrm_initialize();
if (!is_array($params)) {
$error = civicrm_create_error('Parameters is not an array');
return $error;
}
if (!isset($params['event_id']) || !isset($params['contact_id'])) {
$error = civicrm_create_error('Required parameter missing');
return $error;
}
if (!isset($params['status_id'])) {
$params['status_id'] = 1;
}
if (!isset($params['register_date'])) {
$params['register_date'] = date('YmdHis');
}
require_once 'CRM/Event/BAO/Participant.php';
$participant = CRM_Event_BAO_Participant::create($params);
if (is_a($participant, 'CRM_Core_Error')) {
return civicrm_create_error("Participant is not created");
} else {
return civicrm_create_success($participant->id);
}
}
示例2: create
/**
* @param array $params
*
* @return CRM_Event_Cart_BAO_MerParticipant
* @throws Exception
*/
public static function create(&$params)
{
$participantParams = array('id' => CRM_Utils_Array::value('id', $params), 'role_id' => self::get_attendee_role_id(), 'status_id' => self::get_pending_in_cart_status_id(), 'contact_id' => $params['contact_id'], 'event_id' => $params['event_id'], 'cart_id' => $params['cart_id']);
$participant = CRM_Event_BAO_Participant::create($participantParams);
if (is_a($participant, 'CRM_Core_Error')) {
CRM_Core_Error::fatal(ts('There was an error creating a cart participant'));
}
$mer_participant = new CRM_Event_Cart_BAO_MerParticipant($participant);
return $mer_participant;
}
示例3: postProcess
/**
* Process the form after the input has been submitted and validated.
*
*
* @return void
*/
public function postProcess()
{
$params = $this->exportValues();
$value = array();
foreach ($this->_participantIds as $participantId) {
$value['id'] = $participantId;
// Cancelled status id = 4
$value['status_id'] = 4;
CRM_Event_BAO_Participant::create($value);
}
}
示例4: civicrm_api3_participant_create
/**
* Create an Event Participant.
*
* @param array $params
* An associative array of name/value property values of civicrm_participant.
*
* @return array
* API result array
*/
function civicrm_api3_participant_create($params)
{
// Check that event id is not an template - should be done @ BAO layer.
if (!empty($params['event_id'])) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered.'));
}
}
$values = $participant = array();
_civicrm_api3_custom_format_params($params, $values, 'Participant');
$params = array_merge($values, $params);
$participantBAO = CRM_Event_BAO_Participant::create($params);
if (empty($params['price_set_id']) && empty($params['id']) && !empty($params['fee_level'])) {
_civicrm_api3_participant_createlineitem($params, $participantBAO);
}
_civicrm_api3_object_to_array($participantBAO, $participant[$participantBAO->id]);
return civicrm_api3_create_success($participant, $params, 'Participant', 'create', $participantBAO);
}
示例5: civicrm_api3_participant_create
/**
* Create an Event Participant
*
* This API is used for creating a participants in an event.
* Required parameters : event_id AND contact_id for new creation
* : participant as name/value with participantid for edit
*
* @param array $params an associative array of name/value property values of civicrm_participant
*
* @return array apiresult
* {@getfields participant_create}
* @access public
*/
function civicrm_api3_participant_create($params)
{
//check that event id is not an template
// note that check duplicate check was removed as it wasn't actually being called.
//check contact exists removed as belongs @ wrapper layer
if (CRM_Utils_Array::value('event_id', $params)) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered'));
}
}
$value = array();
_civicrm_api3_custom_format_params($params, $values, 'Participant');
$params = array_merge($values, $params);
require_once 'CRM/Event/BAO/Participant.php';
$participantBAO = CRM_Event_BAO_Participant::create($params);
if (empty($params['price_set_id']) && empty($params['id']) && CRM_Utils_Array::value('fee_level', $params)) {
_civicrm_api3_participant_createlineitem($params, $participantBAO);
}
_civicrm_api3_object_to_array($participantBAO, $participant[$participantBAO->id]);
return civicrm_api3_create_success($participant, $params, 'participant', 'create', $participantBAO);
}
示例6: addParticipant
/**
* Process the participant.
*
* @param CRM_Core_Form $form
* @param int $contactID
*
* @return \CRM_Event_BAO_Participant
*/
public static function addParticipant(&$form, $contactID)
{
if (empty($form->_params)) {
return NULL;
}
$params = $form->_params;
$transaction = new CRM_Core_Transaction();
$groupName = 'participant_role';
$query = "\nSELECT v.label as label ,v.value as value\nFROM civicrm_option_value v,\n civicrm_option_group g\nWHERE v.option_group_id = g.id\n AND g.name = %1\n AND v.is_active = 1\n AND g.is_active = 1\n";
$p = array(1 => array($groupName, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $p);
if ($dao->fetch()) {
$roleID = $dao->value;
}
// handle register date CRM-4320
$registerDate = NULL;
if (!empty($form->_allowConfirmation) && $form->_participantId) {
$registerDate = $params['participant_register_date'];
} elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) {
$registerDate = CRM_Utils_Date::format($params['participant_register_date']);
}
$participantFields = CRM_Event_DAO_Participant::fields();
$participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params), 'contact_id' => $contactID, 'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'], 'status_id' => CRM_Utils_Array::value('participant_status', $params, 1), 'role_id' => CRM_Utils_Array::value('participant_role_id', $params, $roleID), 'register_date' => $registerDate ? $registerDate : date('YmdHis'), 'source' => CRM_Utils_String::ellipsify(isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), $participantFields['participant_source']['maxlength']), 'fee_level' => CRM_Utils_Array::value('amount_level', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params), 'discount_id' => CRM_Utils_Array::value('discount_id', $params), 'fee_currency' => CRM_Utils_Array::value('currencyID', $params), 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
$participantParams['is_test'] = 1;
} else {
$participantParams['is_test'] = 0;
}
if (!empty($form->_params['note'])) {
$participantParams['note'] = $form->_params['note'];
} elseif (!empty($form->_params['participant_note'])) {
$participantParams['note'] = $form->_params['participant_note'];
}
// reuse id if one already exists for this one (can happen
// with back button being hit etc)
if (!$participantParams['id'] && !empty($params['contributionID'])) {
$pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['contributionID'], 'participant_id', 'contribution_id');
$participantParams['id'] = $pID;
}
$participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
if (!$participantParams['discount_id']) {
$participantParams['discount_id'] = "null";
}
$participant = CRM_Event_BAO_Participant::create($participantParams);
$transaction->commit();
return $participant;
}
示例7: testCreate
/**
* Create() method (create and updation of participant)
*/
public function testCreate()
{
$params = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $this->_eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $this->_eventId);
$participant = CRM_Event_BAO_Participant::create($params);
//Checking for Contact id in the participant table.
$pid = $this->assertDBNotNull('CRM_Event_DAO_Participant', $this->_contactId, 'id', 'contact_id', 'Check DB for Participant of the contact');
//Checking for Activity added in the table for relative participant.
$this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId, 'source_record_id', 'source_contact_id', $participant->id, 'Check DB for activity added for the participant');
$params = array_merge($params, array('id' => $participant->id, 'role_id' => 2, 'status_id' => 3, 'note' => 'Test Event in edit mode is running successfully ....'));
$participant = CRM_Event_BAO_Participant::create($params);
//Checking Edited Value of role_id in the database.
$this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id, 'role_id', 'id', 2, 'Check DB for updated role id of the participant');
//Checking Edited Value of status_id in the database.
$this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id, 'status_id', 'id', 3, 'Check DB for updated status id of the participant');
//Checking for Activity added in the table for relative participant.
$this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId, 'source_record_id', 'source_contact_id', $participant->id, 'Check DB for activity added for the participant');
//Checking for Note added in the table for relative participant.
$session = CRM_Core_Session::singleton();
$id = $session->get('userID');
if (!$id) {
$id = $this->_contactId;
}
//Deleting the Participant created by create function in this function
$deleteParticipant = CRM_Event_BAO_Participant::deleteParticipant($participant->id);
$this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId, 'id', 'contact_id', 'Check DB for deleted participant. Should be NULL.');
Contact::delete($this->_contactId);
Event::delete($this->_eventId);
}
示例8: postProcess
//.........这里部分代码省略.........
$eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
// set source if not set
if (empty($params['source'])) {
$this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
} else {
$this->_params['participant_source'] = $params['source'];
}
$this->_params['description'] = $this->_params['participant_source'];
$this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
$now = date('YmdHis');
$fields = array();
// set email for primary location.
$fields['email-Primary'] = 1;
$params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
$params['register_date'] = $now;
// now set the values for the billing location.
foreach ($this->_fields as $name => $dontCare) {
$fields[$name] = 1;
}
// also add location name to the array
$params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
$params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
$fields["address_name-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
$nameFields = array('first_name', 'middle_name', 'last_name');
foreach ($nameFields as $name) {
$fields[$name] = 1;
if (array_key_exists("billing_{$name}", $params)) {
$params[$name] = $params["billing_{$name}"];
$params['preserveDBName'] = TRUE;
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
}
if (!empty($this->_params['participant_role_id'])) {
$customFieldsRole = array();
foreach ($this->_params['participant_role_id'] as $roleKey) {
$customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole);
}
$customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
$customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $this->_eventTypeId, $this->_eventTypeCustomDataTypeID);
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE));
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Participant');
}
//do cleanup line items if participant edit the Event Fee.
if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
}
if ($this->_mode) {
// add all the additional payment params we need
$this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
$this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
$this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
$this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $params['fee_amount'];
$this->_params['amount_level'] = $params['amount_level'];
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
// at this point we've created a contact and stored its address etc
// all the payment processors expect the name and address to be in the
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
示例9: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
public function postProcess()
{
$params = $this->exportValues();
if (isset($params['field'])) {
foreach ($params['field'] as $key => $value) {
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, $key, 'Participant');
$value['id'] = $key;
if (CRM_Utils_Array::value('participant_register_date', $value)) {
$value['register_date'] = CRM_Utils_Date::processDate($value['participant_register_date'], $value['participant_register_date_time']);
}
if (CRM_Utils_Array::value('participant_role', $value)) {
$participantRoles = CRM_Event_PseudoConstant::participantRole();
if (is_array($value['participant_role'])) {
$value['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value['participant_role']));
} else {
$value['role_id'] = $value['participant_role'];
}
}
//need to send mail when status change
$statusChange = FALSE;
if (CRM_Utils_Array::value('participant_status', $value)) {
$value['status_id'] = $value['participant_status'];
$fromStatusId = CRM_Utils_Array::value($key, $this->_fromStatusIds);
if (!$fromStatusId) {
$fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id');
}
if ($fromStatusId != $value['status_id']) {
$statusChange = TRUE;
}
}
if (CRM_Utils_Array::value('participant_source', $value)) {
$value['source'] = $value['participant_source'];
}
unset($value['participant_register_date']);
unset($value['participant_status']);
unset($value['participant_source']);
CRM_Event_BAO_Participant::create($value);
//need to trigger mails when we change status
if ($statusChange) {
CRM_Event_BAO_Participant::transitionParticipants(array($key), $value['status_id'], $fromStatusId);
//update related contribution status, CRM-4395
self::updatePendingOnlineContribution($key, $value['status_id']);
}
}
CRM_Core_Session::setStatus(ts('The updates have been saved.'));
} else {
CRM_Core_Session::setStatus(ts('No updates have been saved.'));
}
}
示例10: cancelParticipant
/**
* Cancel this participant and finish, send cancellation email. At this point no
* auto-cancellation of payment is handled, so payment needs to be manually cancelled
*
* return @void
*/
public function cancelParticipant($params)
{
//set participant record status to Cancelled, refund payment if possible
// send email to participant and admin, and log Activity
$value = array();
$value['id'] = $this->_participant_id;
$cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
$value['status_id'] = $cancelledId;
CRM_Event_BAO_Participant::create($value);
$domainValues = array();
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$participantRoles = array();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
$participantDetails = array();
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$participantDetails[$dao->id] = array('id' => $dao->id, 'role' => $participantRoles[$dao->role_id], 'is_test' => $dao->is_test, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'fee_amount' => $dao->fee_amount, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id);
}
$eventDetails = array();
$eventParams = array('id' => $this->_event_id);
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
//get default participant role.
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
//get the location info
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
//get contact details
$contactIds[$this->_contact_id] = $this->_contact_id;
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
foreach ($currentContactDetails as $contactId => $contactValues) {
$contactDetails[$this->_contact_id] = $contactValues;
}
//send a 'cancelled' email to user, and cc the event's cc_confirm email
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_participant_id, $participantDetails[$this->_participant_id], $eventDetails[$this->_event_id], $contactDetails[$this->_contact_id], $domainValues, "Cancelled", "");
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
CRM_Utils_System::redirect($url);
}
示例11: import
/**
* Handle the values in import mode.
*
* @param int $onDuplicate
* The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* @return bool
* the result of this processing
*/
public function import($onDuplicate, &$values)
{
// first make sure this is a valid line
$response = $this->summary($values);
if ($response != CRM_Import_Parser::VALID) {
return $response;
}
$params =& $this->getActiveFieldParams();
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
$formatted = array('version' => 3);
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
// don't add to recent items, CRM-4399
$formatted['skipRecentView'] = TRUE;
foreach ($params as $key => $val) {
if ($val) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
if ($customFields[$customFieldID]['data_type'] == 'Date') {
CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
unset($params[$key]);
} elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
$params[$key] = CRM_Utils_String::strtoboolstr($val);
}
}
if ($key == 'participant_register_date') {
CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'participant_register_date');
$formatted['participant_register_date'] = CRM_Utils_Date::processDate($params['participant_register_date']);
}
}
}
if (!(!empty($params['participant_role_id']) || !empty($params['participant_role']))) {
if (!empty($params['event_id'])) {
$params['participant_role_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'default_role_id');
} else {
$eventTitle = $params['event_title'];
$qParams = array();
$dao = new CRM_Core_DAO();
$params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
}
}
//date-Format part ends
static $indieFields = NULL;
if ($indieFields == NULL) {
$indieFields = CRM_Event_BAO_Participant::import();
}
$formatValues = array();
foreach ($params as $key => $field) {
if ($field == NULL || $field === '') {
continue;
}
$formatValues[$key] = $field;
}
$formatError = _civicrm_api3_deprecated_participant_formatted_param($formatValues, $formatted, TRUE);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
return CRM_Import_Parser::ERROR;
}
if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
array_unshift($values, ts('Invalid value for Event ID'));
return CRM_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Participant');
} else {
if ($formatValues['participant_id']) {
$dao = new CRM_Event_BAO_Participant();
$dao->id = $formatValues['participant_id'];
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatValues['participant_id'], 'Participant');
if ($dao->find(TRUE)) {
$ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
$participantValues = array();
//@todo calling api functions directly is not supported
$newParticipant = _civicrm_api3_deprecated_participant_check_params($formatted, $participantValues, FALSE);
if ($newParticipant['error_message']) {
array_unshift($values, $newParticipant['error_message']);
return CRM_Import_Parser::ERROR;
}
$newParticipant = CRM_Event_BAO_Participant::create($formatted, $ids);
if (!empty($formatted['fee_level'])) {
$otherParams = array('fee_label' => $formatted['fee_level'], 'event_id' => $newParticipant->event_id);
CRM_Price_BAO_LineItem::syncLineItems($newParticipant->id, 'civicrm_participant', $newParticipant->fee_amount, $otherParams);
}
$this->_newParticipant[] = $newParticipant->id;
return CRM_Import_Parser::VALID;
} else {
array_unshift($values, 'Matching Participant record not found for Participant ID ' . $formatValues['participant_id'] . '. Row was skipped.');
return CRM_Import_Parser::ERROR;
}
}
//.........这里部分代码省略.........
示例12: postProcess
//.........这里部分代码省略.........
//modify params according to parameter used in create
//participant method (addParticipant)
$params['participant_status_id'] = $params['status_id'];
$params['participant_role_id'] = $params['role_id'];
$params['participant_register_date'] = $params['register_date'];
$params['participant_source'] = $params['source'];
require_once 'CRM/Core/BAO/PaymentProcessor.php';
$this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
require_once "CRM/Contact/BAO/Contact.php";
$now = date('YmdHis');
$fields = array();
// set email for primary location.
$fields["email-Primary"] = 1;
$params["email-Primary"] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
$params['register_date'] = $now;
// now set the values for the billing location.
foreach ($this->_fields as $name => $dontCare) {
$fields[$name] = 1;
}
// also add location name to the array
$params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
$params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
$fields["address_name-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
$nameFields = array('first_name', 'middle_name', 'last_name');
foreach ($nameFields as $name) {
$fields[$name] = 1;
if (array_key_exists("billing_{$name}", $params)) {
$params[$name] = $params["billing_{$name}"];
$params['preserveDBName'] = true;
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, null, null, $ctype);
}
// build custom data getFields array
$customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('role_id', $params), $this->_roleCustomDataTypeID);
$customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', false, false, null, null, true));
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_participantId, 'Participant');
if ($this->_mode) {
// add all the additioanl payment params we need
$this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
$this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
$this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
$this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $params['fee_amount'];
$this->_params['amount_level'] = $params['amount_level'];
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['payment_action'] = 'Sale';
$this->_params['invoiceID'] = md5(uniqid(rand(), true));
// at this point we've created a contact and stored its address etc
// all the payment processors expect the name and address to be in the
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
$paymentParams['email'] = $this->_contributorEmail;
}
require_once 'CRM/Core/Payment/Form.php';
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
$payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
$result =& $payment->doDirectPayment($paymentParams);
if (is_a($result, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
示例13: import
/**
* handle the values in import mode
*
* @param int $onDuplicate the code for what action to take on duplicates
* @param array $values the array of values belonging to this line
*
* @return boolean the result of this processing
* @access public
*/
function import($onDuplicate, &$values)
{
// first make sure this is a valid line
$response = $this->summary($values);
if ($response != CRM_Event_Import_Parser::VALID) {
return $response;
}
$params =& $this->getActiveFieldParams();
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
$formatted = array();
$customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
// don't add to recent items, CRM-4399
$formatted['skipRecentView'] = true;
foreach ($params as $key => $val) {
if ($val) {
if ($key == 'participant_register_date') {
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
if (!CRM_Utils_Rule::date($params[$key])) {
CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage);
}
} else {
CRM_Import_Parser_Contact::addToErrorMsg('Register Date', $errorMessage);
}
}
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
if ($customFields[$customFieldID]['data_type'] == 'Date') {
CRM_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
unset($params[$key]);
} else {
if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
$params[$key] = CRM_Utils_String::strtoboolstr($val);
}
}
}
}
}
if (!($params['participant_role_id'] || $params['participant_role'])) {
if ($params['event_id']) {
$params['participant_role_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $params['event_id'], 'default_role_id');
} else {
$eventTitle = $params['event_title'];
$qParams = array();
$dao = new CRM_Core_DAO();
$params['participant_role_id'] = $dao->singleValueQuery("SELECT default_role_id FROM civicrm_event WHERE title = '{$eventTitle}' ", $qParams);
}
}
//date-Format part ends
static $indieFields = null;
if ($indieFields == null) {
require_once 'CRM/Event/BAO/Participant.php';
$indieFields =& CRM_Event_BAO_Participant::import();
}
$formatValues = array();
foreach ($params as $key => $field) {
if ($field == null || $field === '') {
continue;
}
$formatValues[$key] = $field;
}
$formatError = _civicrm_participant_formatted_param($formatValues, $formatted, true);
require_once "api/v2/Participant.php";
if ($formatError) {
array_unshift($values, $formatError['error_message']);
return CRM_Event_Import_Parser::ERROR;
}
if (!CRM_Utils_Rule::integer($formatted['event_id'])) {
array_unshift($values, ts('Invalid value for Event ID'));
return CRM_Event_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Event_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Participant');
} else {
if ($formatValues['participant_id']) {
require_once 'CRM/Event/BAO/Participant.php';
$dao = new CRM_Event_BAO_Participant();
$dao->id = $formatValues['participant_id'];
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, $formatValues['participant_id'], 'Participant');
if ($dao->find(true)) {
$ids = array('participant' => $formatValues['participant_id'], 'userId' => $session->get('userID'));
$newParticipant = civicrm_participant_check_params($formatted, false);
if ($newParticipant['error_message']) {
array_unshift($values, $newParticipant['error_message']);
return CRM_Event_Import_Parser::ERROR;
}
$newParticipant =& CRM_Event_BAO_Participant::create($formatted, $ids);
$this->_newParticipant[] = $newParticipant->id;
return CRM_Event_Import_Parser::VALID;
} else {
array_unshift($values, "Matching Participant record not found for Participant ID " . $formatValues['participant_id'] . ". Row was skipped.");
return CRM_Event_Import_Parser::ERROR;
//.........这里部分代码省略.........
示例14: postProcess
/**
* Process transfer - first add the new participant to the event, then cancel
* source participant - send confirmation email to transferee
*/
public function postProcess()
{
//For transfer, process form to allow selection of transferree
$params = $this->controller->exportValues($this->_name);
//cancel 'from' participant row
$query = "select contact_id from civicrm_email where email = '" . $params['email'] . "'";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$contact_id = $dao->contact_id;
}
$from_participant = $params = array();
$query = "select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = " . $this->_from_participant_id;
$dao = CRM_Core_DAO::executeQuery($query);
$value_to = array();
while ($dao->fetch()) {
$value_to['role_id'] = $dao->role_id;
$value_to['source'] = $dao->source;
$value_to['fee_level'] = $dao->fee_level;
$value_to['is_test'] = $dao->is_test;
$value_to['is_pay_later'] = $dao->is_pay_later;
$value_to['fee_amount'] = $dao->fee_amount;
}
$value_to['contact_id'] = $contact_id;
$value_to['event_id'] = $this->_event_id;
$value_to['status_id'] = 1;
$value_to['register_date'] = date("Y-m-d");
//first create the new participant row -don't set registered_by yet or email won't be sent
$participant = CRM_Event_BAO_Participant::create($value_to);
//send a confirmation email to the new participant
$this->participantTransfer($participant);
//now update registered_by_id
$query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})";
$params = array(1 => array($this->_from_participant_id, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
//copy line items to new participant
$line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id);
foreach ($line_items as $item) {
$item['entity_id'] = $participant->id;
$item['id'] = NULL;
$item['entity_table'] = "civicrm_participant";
$new_item = CRM_Price_BAO_LineItem::create($item);
}
//now cancel the from participant record, leaving the original line-item(s)
$value_from = array();
$value_from['id'] = $this->_from_participant_id;
$tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
$value_from['status_id'] = $tansferId;
$value_from['transferred_to_contact_id'] = $contact_id;
$contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id);
$display_name = current($contact_details);
$this->assign('to_participant', $display_name);
CRM_Event_BAO_Participant::create($value_from);
$this->sendCancellation();
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $displayName));
$statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $email));
CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
CRM_Utils_System::redirect($url);
}
示例15: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
$params = $this->exportValues();
$dates = array('participant_register_date');
if (isset($params['field'])) {
foreach ($params['field'] as $key => $value) {
foreach ($dates as $d) {
if (!CRM_Utils_System::isNull($value[$d])) {
$value[$d]['H'] = '00';
$value[$d]['i'] = '00';
$value[$d]['s'] = '00';
$value[$d] = CRM_Utils_Date::format($value[$d]);
}
}
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, $key, 'Participant');
$value['id'] = $key;
if ($value['participant_register_date']) {
$value['register_date'] = $value['participant_register_date'];
}
if ($value['participant_role_id']) {
$value['role_id'] = $value['participant_role_id'];
}
//need to send mail when status change
$statusChange = false;
if ($value['participant_status_id']) {
$value['status_id'] = $value['participant_status_id'];
$fromStatusId = CRM_Utils_Array::value($key, $this->_fromStatusIds);
if (!$fromStatusId) {
$fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id');
}
if ($fromStatusId != $value['status_id']) {
$statusChange = true;
}
}
if ($value['participant_source']) {
$value['source'] = $value['participant_source'];
}
unset($value['participant_register_date']);
unset($value['participant_status_id']);
unset($value['participant_source']);
CRM_Event_BAO_Participant::create($value);
//need to trigger mails when we change status
if ($statusChange) {
CRM_Event_BAO_Participant::transitionParticipants(array($key), $value['status_id'], $fromStatusId);
//update related contribution status, CRM-4395
self::updatePendingOnlineContribution($key, $value['status_id']);
}
}
CRM_Core_Session::setStatus(ts('The updates have been saved.'));
} else {
CRM_Core_Session::setStatus(ts('No updates have been saved.'));
}
}