本文整理汇总了PHP中CRM_Core_BAO_CustomValueTable::store方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomValueTable::store方法的具体用法?PHP CRM_Core_BAO_CustomValueTable::store怎么用?PHP CRM_Core_BAO_CustomValueTable::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomValueTable
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomValueTable::store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_pcpteams_create
/**
* File for the CiviCRM APIv3 group functions
*
* @package CiviCRM_APIv3
* @subpackage API_pcpteams
* @copyright CiviCRM LLC (c) 2004-2014
*/
function civicrm_api3_pcpteams_create($params)
{
// since we are allowing html input from the user
// we also need to purify it, so lets clean it up
// $params['pcp_title'] = $pcp['title'];
// $params['pcp_contact_id'] = $pcp['contact_id'];
$htmlFields = array('intro_text', 'page_text', 'title');
foreach ($htmlFields as $field) {
if (!empty($params[$field])) {
$params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
}
}
$entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
$pcpBlock->entity_table = $entity_table;
$pcpBlock->entity_id = $params['page_id'];
$pcpBlock->find(TRUE);
$params['pcp_block_id'] = $pcpBlock->id;
$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
// 1 -> waiting review
// 2 -> active / approved (default for now)
$params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2);
// active by default for now
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
$pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE);
//Custom Set
$customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE);
$isCustomValueSet = FALSE;
foreach ($customFields as $fieldID => $fieldValue) {
list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) {
$isCustomValueSet = TRUE;
//FIXME: to find out the custom value exists, set -1 as default now
$params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"];
}
}
if ($isCustomValueSet) {
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP');
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id);
}
//end custom set
$values = array();
@_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]);
return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create');
}
示例2: create
/**
* takes an associative array and creates a campaign object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return object CRM_Campaign_DAO_Campaign object
* @access public
* @static
*/
static function create(&$params)
{
if (empty($params)) {
return;
}
if (!CRM_Utils_Array::value('id', $params)) {
if (!CRM_Utils_Array::value('created_id', $params)) {
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
}
if (!CRM_Utils_Array::value('created_date', $params)) {
$params['created_date'] = date('YmdHis');
}
if (!CRM_Utils_Array::value('name', $params)) {
$params['name'] = CRM_Utils_String::titleToVar($params['title'], 64);
}
}
$campaign = new CRM_Campaign_DAO_Campaign();
$campaign->copyValues($params);
$campaign->save();
/* Create the campaign group record */
$groupTableName = CRM_Contact_BAO_Group::getTableName();
if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) {
foreach ($params['groups']['include'] as $entityId) {
$dao = new CRM_Campaign_DAO_CampaignGroup();
$dao->campaign_id = $campaign->id;
$dao->entity_table = $groupTableName;
$dao->entity_id = $entityId;
$dao->group_type = 'Include';
$dao->save();
$dao->free();
}
}
//store custom data
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id);
}
return $campaign;
}
示例3: add
/**
* This is the function that check/add if the relationship created is valid
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param integer $contactId this is contact id for adding relationship
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contact_BAO_Relationship
* @access public
* @static
*/
static function add(&$params, &$ids, $contactId)
{
if (CRM_Utils_Array::value('relationship', $ids)) {
CRM_Utils_Hook::pre('edit', 'Relationship', $ids['relationship'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Relationship', NULL, $params);
}
$relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);
// expolode the string with _ to get the relationship type id and to know which contact has to be inserted in
// contact_id_a and which one in contact_id_b
list($type, $first, $second) = explode('_', $relationshipTypes);
${'contact_' . $first} = CRM_Utils_Array::value('contact', $ids);
${'contact_' . $second} = $contactId;
//check if the relationship type is Head of Household then update the household's primary contact with this contact.
if ($type == 6) {
CRM_Contact_BAO_Household::updatePrimaryContact($contact_b, $contact_a);
}
$relationship = new CRM_Contact_BAO_Relationship();
$relationship->contact_id_b = $contact_b;
$relationship->contact_id_a = $contact_a;
$relationship->relationship_type_id = $type;
$relationship->is_active = CRM_Utils_Array::value('is_active', $params) ? 1 : 0;
$relationship->is_permission_a_b = CRM_Utils_Array::value('is_permission_a_b', $params, 0);
$relationship->is_permission_b_a = CRM_Utils_Array::value('is_permission_b_a', $params, 0);
$relationship->description = CRM_Utils_Array::value('description', $params);
$relationship->start_date = CRM_Utils_Date::format(CRM_Utils_Array::value('start_date', $params));
$relationship->case_id = CRM_Utils_Array::value('case_id', $params);
if (!$relationship->start_date) {
$relationship->start_date = 'NULL';
}
$relationship->end_date = CRM_Utils_Date::format(CRM_Utils_Array::value('end_date', $params));
if (!$relationship->end_date) {
$relationship->end_date = 'NULL';
}
$relationship->id = CRM_Utils_Array::value('relationship', $ids);
$relationship->save();
// add custom field values
if (CRM_Utils_Array::value('custom', $params)) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_relationship', $relationship->id);
}
$relationship->free();
if (CRM_Utils_Array::value('relationship', $ids)) {
CRM_Utils_Hook::post('edit', 'Relationship', $relationship->id, $relationship);
} else {
CRM_Utils_Hook::post('create', 'Relationship', $relationship->id, $relationship);
}
return $relationship;
}
示例4: CRM_Core_Transaction
/**
* takes an associative array and creates a case object
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @internal param array $ids the array that holds all the db ids
*
* @return object CRM_Case_BAO_Case object
* @access public
* @static
*/
static function &create(&$params)
{
$transaction = new CRM_Core_Transaction();
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Case', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Case', NULL, $params);
}
$case = self::add($params);
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_case', $case->id);
}
if (is_a($case, 'CRM_Core_Error')) {
$transaction->rollback();
return $case;
}
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'Case', $case->id, $case);
} else {
CRM_Utils_Hook::post('create', 'Case', $case->id, $case);
}
$transaction->commit();
//we are not creating log for case
//since case log can be tracked using log for activity.
return $case;
}
示例5: create
/**
* Takes an associative array and creates a participant object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Event_BAO_Participant
*/
public static function create(&$params)
{
$transaction = new CRM_Core_Transaction();
$status = NULL;
if (!empty($params['id'])) {
$status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id');
}
$participant = self::add($params);
if (is_a($participant, 'CRM_Core_Error')) {
$transaction->rollback();
return $participant;
}
if (!CRM_Utils_Array::value('id', $params) || isset($params['status_id']) && $params['status_id'] != $status) {
CRM_Activity_BAO_Activity::addActivity($participant);
}
//CRM-5403
//for update mode
if (self::isPrimaryParticipant($participant->id) && $status) {
self::updateParticipantStatus($participant->id, $status, $participant->status_id);
}
$session = CRM_Core_Session::singleton();
$id = $session->get('userID');
if (!$id) {
$id = CRM_Utils_Array::value('contact_id', $params);
}
// add custom field values
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id);
}
//process note, CRM-7634
$noteId = NULL;
if (!empty($params['id'])) {
$note = CRM_Core_BAO_Note::getNote($params['id'], 'civicrm_participant');
$noteId = key($note);
}
$noteValue = NULL;
$hasNoteField = FALSE;
foreach (array('note', 'participant_note') as $noteFld) {
if (array_key_exists($noteFld, $params)) {
$noteValue = $params[$noteFld];
$hasNoteField = TRUE;
break;
}
}
if ($noteId || $noteValue) {
if ($noteValue) {
$noteParams = array('entity_table' => 'civicrm_participant', 'note' => $noteValue, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd'));
$noteIDs = array();
if ($noteId) {
$noteIDs['id'] = $noteId;
}
CRM_Core_BAO_Note::add($noteParams, $noteIDs);
} elseif ($noteId && $hasNoteField) {
CRM_Core_BAO_Note::del($noteId, FALSE);
}
}
// Log the information on successful add/edit of Participant data.
$logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Log::add($logParams);
$params['participant_id'] = $participant->id;
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (empty($params['skipRecentView'])) {
$url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
$recentOther = array();
if (CRM_Core_Permission::check('edit event participants')) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
$participantRoles = CRM_Event_PseudoConstant::participantRole();
if ($participant->role_id) {
$role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id);
foreach ($role as &$roleValue) {
if (isset($roleValue)) {
$roleValue = $participantRoles[$roleValue];
}
}
$roles = implode(', ', $role);
}
$roleString = empty($roles) ? '' : $roles;
$eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title');
$title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roleString . ' - ' . $eventTitle . ')';
// add the recently created Participant
CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, NULL, $recentOther);
}
return $participant;
}
示例6: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
$params = $this->exportValues();
$dates = array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date');
if (isset($params['field'])) {
foreach ($params['field'] as $key => $value) {
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, $key, 'Contribution');
$ids['contribution'] = $key;
foreach ($dates as $val) {
$value[$val] = CRM_Utils_Date::processDate($value[$val]);
}
if ($value['contribution_type']) {
$value['contribution_type_id'] = $value['contribution_type'];
}
if ($value['payment_instrument']) {
$value['payment_instrument_id'] = $value['payment_instrument'];
}
if ($value['contribution_source']) {
$value['source'] = $value['contribution_source'];
}
unset($value['contribution_type']);
unset($value['contribution_source']);
$contribution = CRM_Contribute_BAO_Contribution::add($value, $ids);
// add custom field values
if (CRM_Utils_Array::value('custom', $value) && is_array($value['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_contribution', $contribution->id);
}
}
CRM_Core_Session::setStatus("Your updates have been saved.");
} else {
CRM_Core_Session::setStatus("No updates have been saved.");
}
}
示例7: add
/**
* Takes an associative array and creates a contribution object.
*
* the function extract all the params it needs to initialize the create a
* contribution object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Contribute_BAO_Contribution
* @todo move hook calls / extended logic to create - requires changing calls to call create not add
*/
public static function add(&$params)
{
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'ContributionRecur', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'ContributionRecur', NULL, $params);
}
// make sure we're not creating a new recurring contribution with the same transaction ID
// or invoice ID as an existing recurring contribution
$duplicates = array();
if (self::checkDuplicate($params, $duplicates)) {
$error = CRM_Core_Error::singleton();
$d = implode(', ', $duplicates);
$error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching recurring contribution(s): {$d}");
return $error;
}
$recurring = new CRM_Contribute_BAO_ContributionRecur();
$recurring->copyValues($params);
$recurring->id = CRM_Utils_Array::value('id', $params);
// set currency for CRM-1496
if (empty($params['id']) && !isset($recurring->currency)) {
$config = CRM_Core_Config::singleton();
$recurring->currency = $config->defaultCurrency;
}
$result = $recurring->save();
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'ContributionRecur', $recurring->id, $recurring);
} else {
CRM_Utils_Hook::post('create', 'ContributionRecur', $recurring->id, $recurring);
}
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution_recur', $recurring->id);
}
return $result;
}
示例8: create
/**
* Takes an associative array and creates a contribution object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $ids
* The array that holds all the db ids.
*
* @return CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = array())
{
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (!empty($params['note'])) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams);
}
// make entry in batch entity batch table
if (!empty($params['batch_id'])) {
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
}
// Handle soft credit and / or link to personal campaign page
$softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id);
$pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE);
if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
$softParams = array();
$softParams['id'] = $pcpId ? $pcpId : NULL;
$softParams['contribution_id'] = $contribution->id;
$softParams['pcp_id'] = $pcp['pcp_made_through_id'];
$softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp['pcp_made_through_id'], 'contact_id');
$softParams['currency'] = $contribution->currency;
$softParams['amount'] = $contribution->total_amount;
$softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
$softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
$softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
$softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
$contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($softParams);
//Send notification to owner for PCP
if ($contributionSoft->pcp_id && empty($pcpId)) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
}
} elseif (array_key_exists('pcp', $params) && $pcpId) {
$deleteParams = array('id' => $pcpId);
CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
}
if (isset($params['soft_credit'])) {
$softParams = $params['soft_credit'];
foreach ($softParams as $softParam) {
if (!empty($softIDs)) {
$key = key($softIDs);
$softParam['id'] = $softIDs[$key];
unset($softIDs[$key]);
}
$softParam['contribution_id'] = $contribution->id;
$softParam['currency'] = $contribution->currency;
//case during Contribution Import when we assign soft contribution amount as contribution's total_amount by default
if (empty($softParam['amount'])) {
$softParam['amount'] = $contribution->total_amount;
}
CRM_Contribute_BAO_ContributionSoft::add($softParam);
}
if (!empty($softIDs)) {
foreach ($softIDs as $softID) {
if (!in_array($softID, $params['soft_credit_ids'])) {
$deleteParams = array('id' => $softID);
CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
}
}
}
}
//.........这里部分代码省略.........
示例9: foreach
//.........这里部分代码省略.........
}
$transaction = new CRM_Core_Transaction();
$contact = self::add($params);
if (!$contact) {
// Not dying here is stupid, since we get into wierd situation and into a bug that
// is impossible to figure out for the user or for us
// CRM-7925
CRM_Core_Error::fatal();
}
$params['contact_id'] = $contact->id;
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) {
// Enabling multisite causes the contact to be added to the domain group.
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (!empty($domainGroupID)) {
if (!empty($params['group']) && is_array($params['group'])) {
$params['group'][$domainGroupID] = 1;
} else {
$params['group'] = array($domainGroupID => 1);
}
}
}
if (array_key_exists('group', $params)) {
$contactIds = array($params['contact_id']);
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
} elseif ($flag == -1) {
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
}
}
}
// Add location Block data.
$blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
foreach ($blocks as $name => $value) {
$contact->{$name} = $value;
}
//add website
CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete);
//get userID from session
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
// add notes
if (!empty($params['note'])) {
if (is_array($params['note'])) {
foreach ($params['note'] as $note) {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => CRM_Utils_Array::value('subject', $note), 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
} else {
$contactId = $contact->id;
if (isset($note['contact_id'])) {
$contactId = $note['contact_id'];
}
//if logged in user, overwrite contactId
if ($userID) {
$contactId = $userID;
}
$noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note'], 'subject' => CRM_Utils_Array::value('subject', $params), 'contact_id' => $contactId);
CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
}
}
// update the UF user_unique_id if that has changed
CRM_Core_BAO_UFMatch::updateUFName($contact->id);
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contact', $contact->id);
}
// make a civicrm_subscription_history entry only on contact create (CRM-777)
if (empty($params['contact_id'])) {
$subscriptionParams = array('contact_id' => $contact->id, 'status' => 'Added', 'method' => 'Admin');
CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams);
}
$transaction->commit();
// CRM-6367: fetch the right label for contact type’s display
$contact->contact_type_display = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $contact->contact_type, 'label', 'name');
if (!$config->doNotResetCache) {
// Note: doNotResetCache flag is currently set by import contact process and merging,
// since resetting and
// rebuilding cache could be expensive (for many contacts). We might come out with better
// approach in future.
CRM_Contact_BAO_Contact_Utils::clearContactCaches($contact->id);
}
if ($invokeHooks) {
if ($isEdit) {
CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact);
} else {
CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact);
}
}
// process greetings CRM-4575, cache greetings
self::processGreetings($contact);
return $contact;
}
示例10: ts
/**
* takes an associative array and creates a membership object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
* @param boolean $callFromAPI Is this function called from API?
*
* @return object CRM_Member_BAO_Membership object
* @access public
* @static
*/
static function &create(&$params, &$ids, $skipRedirect = false, $activityType = 'Membership Signup')
{
// always cal status if is_override/skipStatusCal is not true.
// giving respect to is_override during import. CRM-4012
// To skip status cal we should use 'skipStatusCal'.
// eg pay later membership, membership update cron CRM-3984
if (!CRM_Utils_Array::value('is_override', $params) && !CRM_Utils_Array::value('skipStatusCal', $params)) {
require_once 'CRM/Utils/Date.php';
$startDate = $endDate = $joinDate = null;
if (isset($params['start_date'])) {
$startDate = CRM_Utils_Date::customFormat($params['start_date'], '%Y%m%d');
}
if (isset($params['end_date'])) {
$endDate = CRM_Utils_Date::customFormat($params['end_date'], '%Y%m%d');
}
if (isset($params['join_date'])) {
$joinDate = CRM_Utils_Date::customFormat($params['join_date'], '%Y%m%d');
}
require_once 'CRM/Member/BAO/MembershipStatus.php';
//fix for CRM-3570, during import exclude the statuses those having is_admin = 1
$excludeIsAdmin = CRM_Utils_Array::value('exclude_is_admin', $params, false);
//CRM-3724 always skip is_admin if is_override != true.
if (!$excludeIsAdmin && !CRM_Utils_Array::value('is_override', $params)) {
$excludeIsAdmin = true;
}
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', $excludeIsAdmin);
if (empty($calcStatus)) {
if (!$skipRedirect) {
// Redirect the form in case of error
CRM_Core_Session::setStatus(ts('The membership cannot be saved.') . '<br/>' . ts('No valid membership status for given dates.'));
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$params['contact_id']}&selectedChild=member"));
}
// Return the error message to the api
$error = array();
$error['is_error'] = ts('The membership cannot be saved. No valid membership status for given dates');
return $error;
}
$params['status_id'] = $calcStatus['id'];
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$membership =& self::add($params, $ids);
if (is_a($membership, 'CRM_Core_Error')) {
$transaction->rollback();
return $membership;
}
// add custom field values
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_membership', $membership->id);
}
$params['membership_id'] = $membership->id;
if (isset($ids['membership'])) {
$ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $ids['membership'], 'contribution_id', 'membership_id');
}
//record contribution for this membership
if (CRM_Utils_Array::value('contribution_status_id', $params)) {
$contributionParams = array();
$config = CRM_Core_Config::singleton();
$contributionParams['currency'] = $config->defaultCurrency;
$contributionParams['receipt_date'] = CRM_Utils_Array::value('receipt_date', $params) ? $params['receipt_date'] : 'null';
$contributionParams['source'] = CRM_Utils_Array::value('contribution_source', $params);
$contributionParams['non_deductible_amount'] = 'null';
$recordContribution = array('contact_id', 'total_amount', 'receive_date', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test', 'contribution_status_id', 'check_number');
foreach ($recordContribution as $f) {
$contributionParams[$f] = CRM_Utils_Array::value($f, $params);
}
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribution =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
//insert payment record for this membership
if (!CRM_Utils_Array::value('contribution', $ids) || CRM_Utils_Array::value('is_recur', $params)) {
require_once 'CRM/Member/DAO/MembershipPayment.php';
$mpDAO = new CRM_Member_DAO_MembershipPayment();
$mpDAO->membership_id = $membership->id;
$mpDAO->contribution_id = $contribution->id;
if (CRM_Utils_Array::value('is_recur', $params)) {
$mpDAO->find();
}
CRM_Utils_Hook::pre('create', 'MembershipPayment', null, $mpDAO);
$mpDAO->save();
CRM_Utils_Hook::post('create', 'MembershipPayment', $mpDAO->id, $mpDAO);
}
}
// add activity record only during create mode and renew mode
// also add activity if status changed CRM-3984 and CRM-2521
if (!CRM_Utils_Array::value('membership', $ids) || $activityType == 'Membership Renewal' || CRM_Utils_Array::value('createActivity', $params)) {
if (CRM_Utils_Array::value('membership', $ids)) {
CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_Membership', 'id', $membership->id, $data, array('contact_id', 'membership_type_id', 'source'));
$membership->contact_id = $data[$membership->id]['contact_id'];
//.........这里部分代码省略.........
示例11: create
/**
* Takes an associative array and creates a Survey object.
*
* the function extract all the params it needs to initialize the create a
* survey object.
*
*
* @param array $params
*
* @return CRM_Survey_DAO_Survey
*/
public static function create(&$params)
{
if (empty($params)) {
return FALSE;
}
if (!empty($params['is_default'])) {
$query = "UPDATE civicrm_survey SET is_default = 0";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
if (!CRM_Utils_Array::value('id', $params)) {
if (!CRM_Utils_Array::value('created_id', $params)) {
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
}
if (!CRM_Utils_Array::value('created_date', $params)) {
$params['created_date'] = date('YmdHis');
}
}
$dao = new CRM_Campaign_DAO_Survey();
$dao->copyValues($params);
$dao->save();
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_survey', $dao->id);
}
return $dao;
}
示例12: implode
/**
* Create a new group.
*
* @param array $params
*
* @return CRM_Contact_BAO_Group|NULL
* The new group BAO (if created)
*/
public static function &create(&$params)
{
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Group', NULL, $params);
}
// form the name only if missing: CRM-627
$nameParam = CRM_Utils_Array::value('name', $params, NULL);
if (!$nameParam && empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}
// convert params if array type
if (isset($params['group_type'])) {
if (is_array($params['group_type'])) {
$params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
}
} else {
$params['group_type'] = '';
}
$session = CRM_Core_Session::singleton();
$cid = $session->get('userID');
// this action is add
if ($cid && empty($params['id'])) {
$params['created_id'] = $cid;
}
// this action is update
if ($cid && !empty($params['id'])) {
$params['modified_id'] = $cid;
}
$group = new CRM_Contact_BAO_Group();
$group->copyValues($params);
//@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but
// needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn
// use metadata to translate the array to the appropriate DB type or altering the param in the api layer,
// or at least altering the param in same section as 'group_type' rather than repeating here. However, further down
// we need the $params one to be in it's original form & we are not sure what test coverage we have on that
if (isset($group->parents) && is_array($group->parents)) {
$group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR;
}
if (empty($params['id']) && !$nameParam) {
$group->name .= "_tmp";
}
$group->save();
if (!$group->id) {
return NULL;
}
if (empty($params['id']) && !$nameParam) {
$group->name = substr($group->name, 0, -4) . "_{$group->id}";
}
$group->buildClause();
$group->save();
// add custom field values
if (!empty($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
}
// make the group, child of domain/site group by default.
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('no_parent', $params) !== 1) {
if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) {
// if no parent present and the group doesn't already have any parents,
// make sure site group goes as parent
$params['parents'] = array($domainGroupID => 1);
} elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) {
$params['parents'] = array($params['parents'] => 1);
}
if (!empty($params['parents'])) {
foreach ($params['parents'] as $parentId => $dnc) {
if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
}
}
}
// clear any descendant groups cache if exists
$finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
// this is always required, since we don't know when a
// parent group is removed
CRM_Contact_BAO_GroupNestingCache::update();
// update group contact cache for all parent groups
$parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
foreach ($parentIds as $parentId) {
CRM_Contact_BAO_GroupContactCache::add($parentId);
}
}
if (!empty($params['organization_id'])) {
$groupOrg = array();
$groupOrg = $params;
$groupOrg['group_id'] = $group->id;
CRM_Contact_BAO_GroupOrganization::add($groupOrg);
}
CRM_Contact_BAO_GroupContactCache::add($group->id);
if (!empty($params['id'])) {
//.........这里部分代码省略.........
示例13: create
/**
* Takes an associative array and creates a contribution object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $ids
* The array that holds all the db ids.
*
* @return CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = array())
{
$dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
foreach ($dateFields as $df) {
if (isset($params[$df])) {
$params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
}
}
//if contribution is created with cancelled or refunded status, add credit note id
if (!empty($params['contribution_status_id'])) {
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if ($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) {
if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") {
$params['creditnote_id'] = self::createCreditNoteId();
}
}
}
$transaction = new CRM_Core_Transaction();
$contribution = self::add($params, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$transaction->rollback();
return $contribution;
}
$params['contribution_id'] = $contribution->id;
if (!empty($params['custom']) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
}
$session = CRM_Core_Session::singleton();
if (!empty($params['note'])) {
$noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd'));
if (!$noteParams['contact_id']) {
$noteParams['contact_id'] = $params['contact_id'];
}
CRM_Core_BAO_Note::add($noteParams);
}
// make entry in batch entity batch table
if (!empty($params['batch_id'])) {
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
}
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
// check if activity record exist for this contribution, if
// not add activity
$activity = new CRM_Activity_DAO_Activity();
$activity->source_record_id = $contribution->id;
$activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name');
if (!$activity->find(TRUE)) {
if (empty($contribution->contact_id)) {
$contribution->find(TRUE);
}
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
} else {
// CRM-13237 : if activity record found, update it with campaign id of contribution
CRM_Core_DAO::setFieldValue('CRM_Activity_BAO_Activity', $activity->id, 'campaign_id', $contribution->campaign_id);
}
// do not add to recent items for import, CRM-4399
if (empty($params['skipRecentView'])) {
$url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
// in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
$titleFields = array('contact_id', 'total_amount', 'currency', 'financial_type_id');
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if (!isset($contribution->{$titleField})) {
$retrieveRequired = 1;
break;
}
}
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->financial_type_id] . ')';
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home");
}
//.........这里部分代码省略.........
示例14: postProcess
/**
* This function is called after the user submits the form.
*
* @access public
*
* @return none
*/
public function postProcess()
{
global $user;
$isAdmin = in_array('civihr_admin', $user->roles) ? true : false;
$session = CRM_Core_Session::singleton();
$submitValues = $this->_submitValues;
if (!empty($submitValues['contacts_id'])) {
$this->_targetContactID = $submitValues['contacts_id'];
}
$absentDateDurations = array();
$activityStatus = CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus('name');
$activityStatusId['status_id'] = CRM_Utils_Array::key('Completed', $activityStatus);
if (!empty($submitValues['date_values'])) {
foreach (explode('|', $submitValues['date_values']) as $key => $dateString) {
if ($dateString) {
$values = explode('(', $dateString);
$date = CRM_Utils_Date::processDate($values[0]);
$valuesDate = explode(':', $dateString);
$absentDateDurations[$date]['duration'] = (int) $valuesDate[1];
if (isset($valuesDate[2]) && $valuesDate[2] == 1 && $this->_showhide == 1 && array_key_exists('_qf_AbsenceRequest_done_save', $submitValues) || isset($valuesDate[2]) && $valuesDate[2] == 0 && $this->_showhide == 0 && array_key_exists('_qf_AbsenceRequest_done_save', $submitValues)) {
$absentDateDurations[$date]['approval'] = CRM_Utils_Array::key('Scheduled', $activityStatus);
} elseif (isset($valuesDate[2]) && $valuesDate[2] == 0 && $this->_showhide == 1) {
$absentDateDurations[$date]['approval'] = CRM_Utils_Array::key('Rejected', $activityStatus);
} elseif (array_key_exists('_qf_AbsenceRequest_done_saveandapprove', $submitValues) || array_key_exists('_qf_AbsenceRequest_done_approve', $submitValues)) {
$absentDateDurations[$date]['approval'] = CRM_Utils_Array::key('Completed', $activityStatus);
}
}
}
}
// set email template values
$taDays = explode('|', $submitValues['tot_app_days']);
$totDays = $taDays[0];
if (!empty($taDays[1])) {
$appDays = $taDays[1];
}
$msgTempResult = civicrm_api3('MessageTemplate', 'get', array('msg_title' => "Absence Email"));
$targetContactResult = civicrm_api3('contact', 'get', array('id' => $this->_targetContactID));
$mailprm[$this->_targetContactID]['display_name'] = $targetContactResult['values'][$this->_targetContactID]['display_name'];
$mailprm[$this->_targetContactID]['email'] = $targetContactResult['values'][$this->_targetContactID]['email'];
$tplParams = array('messageTemplateID' => $msgTempResult['values'][$msgTempResult['id']]['id'], 'empName' => $mailprm[$this->_targetContactID]['display_name'], 'absenceType' => $this->_absenceType, 'absentDateDurations' => $absentDateDurations, 'startDate' => $submitValues['start_date'], 'endDate' => $submitValues['end_date'], 'empPosition' => $this->_empPosition, 'totDays' => $totDays, 'jobHoursTime' => $this->_jobHoursTime);
if (!empty($appDays)) {
$tplParams['appDays'] = $appDays;
}
$sendTemplateParams = array('messageTemplateID' => $tplParams['messageTemplateID'], 'contactId' => $this->_targetContactID, 'tplParams' => $tplParams);
if ($this->_action & CRM_Core_Action::ADD) {
$activityParam = array('sequential' => 1, 'source_contact_id' => $this->_loginUserID, 'target_contact_id' => $this->_targetContactID, 'assignee_contact_id' => $this->_managerContactID, 'activity_type_id' => $this->_activityTypeID);
if (array_key_exists('_qf_AbsenceRequest_done_saveandapprove', $submitValues) || $isAdmin) {
$activityParam['status_id'] = CRM_Utils_Array::key('Completed', $activityStatus);
} else {
//we want to keep the activity status in Scheduled for new absence if save button is clicked
$activityParam['status_id'] = CRM_Utils_Array::key('Scheduled', $activityStatus);
}
$result = civicrm_api3('Activity', 'create', $activityParam);
//save the custom data
if (!empty($submitValues['hidden_custom'])) {
$customFields = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeID), CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE));
$customValues = CRM_Core_BAO_CustomField::postProcess($submitValues, $customFields, $result['id'], 'Activity');
CRM_Core_BAO_CustomValueTable::store($customValues, 'civicrm_activity', $result['id']);
}
if (!empty($customValues)) {
$customGroup = array();
foreach ($customValues as $fieldID => $values) {
foreach ($values as $fieldValue) {
$customValue = array('data' => $fieldValue['value']);
$customFields[$fieldID]['id'] = $fieldID;
$formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
$customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
}
}
$sendTemplateParams['tplParams']['customGroup'] = $customGroup;
}
$activityLeavesParam = array('sequential' => 1, 'source_record_id' => $result['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', 'Absence', 'name'));
foreach ($absentDateDurations as $date => $duration) {
$activityLeavesParam['activity_date_time'] = $date;
$activityLeavesParam['duration'] = $duration['duration'];
$activityLeavesParam['status_id'] = $duration['approval'];
civicrm_api3('Activity', 'create', $activityLeavesParam);
}
if (array_key_exists('_qf_AbsenceRequest_done_save', $submitValues)) {
$sendTemplateParams['from'] = $mailprm[$this->_targetContactID]['email'];
CRM_Core_Session::setStatus(ts('Absence(s) have been applied.'), ts('Saved'), 'success');
} elseif (array_key_exists('_qf_AbsenceRequest_done_saveandapprove', $submitValues) || $isAdmin) {
if (!empty($this->_managerContactID)) {
$emailID = civicrm_api3('contact', 'get', array('id' => $this->_loginUserID));
$sendTemplateParams['from'] = $emailID['values'][$emailID['id']]['email'];
}
$sendTemplateParams['tplParams']['approval'] = TRUE;
CRM_Core_Session::setStatus(ts('Absence(s) have been applied and approved.'), ts('Saved'), 'success');
}
$managerContactResult = array();
if (!empty($this->_managerContactID)) {
foreach ($this->_managerContactID as $key => $val) {
$managerContactResult = civicrm_api3('contact', 'get', array('id' => $val));
//.........这里部分代码省略.........
示例15: CRM_Core_Transaction
/**
* takes an associative array and creates a participant object
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Event_BAO_Participant object
* @access public
* @static
*/
static function &create(&$params)
{
require_once 'CRM/Utils/Date.php';
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$status = null;
if (CRM_Utils_Array::value('id', $params)) {
$status = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id');
}
$participant =& self::add($params);
if (is_a($participant, 'CRM_Core_Error')) {
$transaction->rollback();
return $participant;
}
if (!CRM_Utils_Array::value('id', $params) || $params['status_id'] != $status) {
require_once 'CRM/Activity/BAO/Activity.php';
CRM_Activity_BAO_Activity::addActivity($participant);
}
//CRM-5403
//for update mode
if (self::isPrimaryParticipant($participant->id) && $status) {
self::updateParticipantStatus($participant->id, $status, $participant->status_id);
}
$session =& CRM_Core_Session::singleton();
$id = $session->get('userID');
if (!$id) {
$id = $params['contact_id'];
}
// add custom field values
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_participant', $participant->id);
}
if (CRM_Utils_Array::value('note', $params) || CRM_Utils_Array::value('participant_note', $params)) {
if (CRM_Utils_Array::value('note', $params)) {
$note = CRM_Utils_Array::value('note', $params);
} else {
$note = CRM_Utils_Array::value('participant_note', $params);
}
$noteDetails = CRM_Core_BAO_Note::getNote($participant->id, 'civicrm_participant');
$noteIDs = array();
if (!empty($noteDetails)) {
$noteIDs['id'] = array_pop(array_flip($noteDetails));
}
if ($note) {
require_once 'CRM/Core/BAO/Note.php';
$noteParams = array('entity_table' => 'civicrm_participant', 'note' => $note, 'entity_id' => $participant->id, 'contact_id' => $id, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Note::add($noteParams, $noteIDs);
}
}
// Log the information on successful add/edit of Participant data.
require_once 'CRM/Core/BAO/Log.php';
$logParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'data' => CRM_Event_PseudoConstant::participantStatus($participant->status_id), 'modified_id' => $id, 'modified_date' => date('Ymd'));
CRM_Core_BAO_Log::add($logParams);
$params['participant_id'] = $participant->id;
$transaction->commit();
// do not add to recent items for import, CRM-4399
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
require_once 'CRM/Utils/Recent.php';
require_once 'CRM/Event/PseudoConstant.php';
require_once 'CRM/Contact/BAO/Contact.php';
$url = CRM_Utils_System::url('civicrm/contact/view/participant', "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
$recentOther = array();
if (CRM_Core_Permission::check('edit event participants')) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant', "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home");
}
$participantRoles = CRM_Event_PseudoConstant::participantRole();
if ($participant->role_id) {
$role = explode(CRM_Core_DAO::VALUE_SEPARATOR, $participant->role_id);
foreach ($role as $roleKey => $roleValue) {
if (isset($roles)) {
$roles .= ", " . $participantRoles[$roleValue];
} else {
$roles = $participantRoles[$roleValue];
}
}
}
$eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'title');
$title = CRM_Contact_BAO_Contact::displayName($participant->contact_id) . ' (' . $roles . ' - ' . $eventTitle . ')';
// add the recently created Participant
CRM_Utils_Recent::add($title, $url, $participant->id, 'Participant', $participant->contact_id, null, $recentOther);
}
return $participant;
}