本文整理汇总了PHP中CRM_Contact_DAO_Contact::find方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_DAO_Contact::find方法的具体用法?PHP CRM_Contact_DAO_Contact::find怎么用?PHP CRM_Contact_DAO_Contact::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_DAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_DAO_Contact::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
// reset action from the session
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$rcid = CRM_Utils_Request::retrieve('rcid', 'Positive', $this);
$rcid = $rcid ? "&id={$rcid}" : '';
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/user', "reset=1{$rcid}"));
if ($this->_contactId) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $this->_contactId;
if (!$contact->find(TRUE)) {
CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
}
$this->_contactType = $contact->contact_type;
// check for permissions
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
}
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
} else {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
}
示例2: validateData
function validateData(&$input, &$ids, &$objects, $required = true)
{
// make sure contact exists and is valid
require_once 'CRM/Contact/DAO/Contact.php';
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $ids['contact'];
if (!$contact->find(true)) {
CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']}");
echo "Failure: Could not find contact record: {$ids['contact']}<p>";
return false;
}
// make sure contribution exists and is valid
require_once 'CRM/Contribute/DAO/Contribution.php';
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $ids['contribution'];
if (!$contribution->find(true)) {
CRM_Core_Error::debug_log_message("Could not find contribution record: {$contributionID}");
echo "Failure: Could not find contribution record for {$contributionID}<p>";
return false;
}
$contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
$objects['contact'] =& $contact;
$objects['contribution'] =& $contribution;
if (!$this->loadObjects($input, $ids, $objects, $required)) {
return false;
}
return true;
}
示例3: validateData
function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL)
{
// make sure contact exists and is valid
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $ids['contact'];
if (!$contact->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']}");
echo "Failure: Could not find contact record: {$ids['contact']}<p>";
return FALSE;
}
// make sure contribution exists and is valid
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $ids['contribution'];
if (!$contribution->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contribution record: " . $contribution->id);
echo "Failure: Could not find contribution record for {$contribution->id}<p>";
return FALSE;
}
$contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
$objects['contact'] =& $contact;
$objects['contribution'] =& $contribution;
if (!$this->loadObjects($input, $ids, $objects, $required, $paymentProcessorID)) {
return FALSE;
}
return TRUE;
}
示例4: tearDownAfterClass
/**
* Both testDummy1 and testDummy2 have been created at some point (as part of the test runs),
* but all the data was rolled-back
*
* @throws \Exception
*/
public static function tearDownAfterClass()
{
if (!is_numeric(self::$contactIds['testDummy1'])) {
throw new \Exception("Uh oh! The static \$contactIds does not include testDummy1! Did the test fail to execute?");
}
if (!is_numeric(self::$contactIds['testDummy2'])) {
throw new \Exception("Uh oh! The static \$contactIds does not include testDummy2! Did the test fail to execute?");
}
$dao = new \CRM_Contact_DAO_Contact();
$dao->id = self::$contactIds['testDummy1'];
if ($dao->find()) {
throw new \Exception("Uh oh! testDummy1 still exists!");
}
$dao = new \CRM_Contact_DAO_Contact();
$dao->id = self::$contactIds['testDummy2'];
if ($dao->find()) {
throw new \Exception("Uh oh! testDummy2 still exists!");
}
}
示例5: createNavigation
/**
* Function to create navigation for CiviCRM Admin Menu
*
* @param int $contactID contact id
*
* @return string $navigation returns navigation html
* @static
*/
static function createNavigation($contactID)
{
$config = CRM_Core_Config::singleton();
// if on frontend, do not create navigation menu items, CRM-5349
if ($config->userFrameworkFrontend) {
return "<!-- {$config->lcMessages} -->";
}
$navParams = array('contact_id' => $contactID);
$navigation = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, 'navigation', NULL, NULL, $contactID);
// FIXME: hack for CRM-5027: we need to prepend the navigation string with
// (HTML-commented-out) locale info so that we rebuild menu on locale changes
if (!$navigation || substr($navigation, 0, 14) != "<!-- {$config->lcMessages} -->") {
//retrieve navigation if it's not cached.
$navigation = self::buildNavigation();
//add additional navigation items
$logoutURL = CRM_Utils_System::url('civicrm/logout', 'reset=1');
$appendSring = "<li id=\"menu-logout\" class=\"menumain\"><a href=\"{$logoutURL}\">" . ts('Logout') . "</a></li>";
// get home menu from db
$homeParams = array('name' => 'Home');
$homeNav = array();
self::retrieve($homeParams, $homeNav);
if ($homeNav) {
list($path, $q) = explode('&', $homeNav['url']);
$homeURL = CRM_Utils_System::url($path, $q);
$homeLabel = $homeNav['label'];
// CRM-6804 (we need to special-case this as we don’t ts()-tag variables)
if ($homeLabel == 'Home') {
$homeLabel = ts('Home');
}
} else {
$homeURL = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
$homeLabel = ts('Home');
}
if ($config->userSystem->is_drupal && (module_exists('toolbar') && user_access('access toolbar') || module_exists('admin_menu') && user_access('access administration menu'))) {
$prepandString = "<li class=\"menumain crm-link-home\">" . $homeLabel . "<ul id=\"civicrm-home\"><li><a href=\"{$homeURL}\">" . $homeLabel . "</a></li><li><a href=\"#\" onclick=\"cj.Menu.closeAll( );cj('#civicrm-menu').toggle( );\">" . ts('Drupal Menu') . "</a></li></ul>";
} elseif ($config->userSystem->is_wordpress) {
$prepandString = "<li class=\"menumain crm-link-home\">" . $homeLabel . "<ul id=\"civicrm-home\"><li><a href=\"{$homeURL}\">" . $homeLabel . "</a></li><li><a href=\"#\" onclick=\"cj.Menu.closeAll( );cj('#civicrm-menu').toggle( );\">" . ts('WordPress Menu') . "</a></li></ul>";
} else {
$prepandString = "<li class=\"menumain crm-link-home\"><a href=\"{$homeURL}\" title=\"" . $homeLabel . "\">" . $homeLabel . "</a>";
}
// prepend the navigation with locale info for CRM-5027
$navigation = "<!-- {$config->lcMessages} -->" . $prepandString . $navigation . $appendSring;
// before inserting check if contact id exists in db
// this is to handle wierd case when contact id is in session but not in db
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $contactID;
if ($contact->find(TRUE)) {
CRM_Core_BAO_Setting::setItem($navigation, CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, 'navigation', NULL, $contactID, $contactID);
}
}
return $navigation;
}
示例6: browse
/**
* This function is called when action is browse
*
* return null
* @access public
*/
function browse()
{
$note =& new CRM_Core_DAO_Note();
$note->entity_table = 'civicrm_contact';
$note->entity_id = $this->_contactId;
$note->orderBy('modified_date desc');
$values = array();
$links =& CRM_Contact_Page_View_Note::links();
$action = array_sum(array_keys($links)) & CRM_Core_Action::mask($this->_permission);
$note->find();
while ($note->fetch()) {
$values[$note->id] = array();
CRM_Core_DAO::storeValues($note, $values[$note->id]);
$values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $note->id, 'cid' => $this->_contactId));
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $note->contact_id;
$contact->find();
$contact->fetch();
$values[$note->id]['createdBy'] = $contact->display_name;
}
$this->assign('notes', $values);
}
示例7: addMembershipType
private function addMembershipType()
{
$organizationDAO = new CRM_Contact_DAO_Contact();
$organizationDAO->id = 5;
$organizationDAO->find(TRUE);
$contact_id = $organizationDAO->contact_id;
$membershipType = "INSERT INTO civicrm_membership_type\n (name, description, member_of_contact_id, financial_type_id, minimum_fee, duration_unit, duration_interval, period_type, fixed_period_start_day, fixed_period_rollover_day, relationship_type_id, relationship_direction, visibility, weight, is_active)\n VALUES\n ('General', 'Regular annual membership.', " . $contact_id . ", 2, 100, 'year', 1, 'rolling',null, null, 7, 'b_a', 'Public', 1, 1),\n ('Student', 'Discount membership for full-time students.', " . $contact_id . ", 2, 50, 'year', 1, 'rolling', null, null, 7, 'b_a', 'Public', 2, 1),\n ('Lifetime', 'Lifetime membership.', " . $contact_id . ", 2, 1200, 'lifetime', 1, 'rolling', null, null, 7, 'b_a', 'Admin', 3, 1);\n ";
$this->_query($membershipType);
}
示例8: preProcess
/**
* Function to build the form
*
* @return None
* @access public
*/
function preProcess()
{
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
$this->assign('cdType', FALSE);
if ($this->_cdType) {
$this->assign('cdType', TRUE);
return CRM_Custom_Form_CustomData::preProcess($this);
}
$this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
if ($this->_action & CRM_Core_Action::ADD && !$this->_currentlyViewedContactId) {
// check for add contacts permissions
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
return;
}
}
//CRM-4418
if (!CRM_Core_Permission::checkActionPermission('CiviCase', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
}
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
if (!$this->_caseId) {
$caseAttributes = array('case_type' => CRM_Case_PseudoConstant::caseType(), 'case_status' => CRM_Case_PseudoConstant::caseStatus(), 'encounter_medium' => CRM_Case_PseudoConstant::encounterMedium());
foreach ($caseAttributes as $key => $values) {
if (empty($values)) {
CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => str_replace('_', ' ', $key))));
break;
}
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$this->_activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
if (!$this->_activityTypeId) {
CRM_Core_Error::fatal(ts('The Open Case activity type is missing or disabled. Please have your site administrator check Administer > Option Lists > Activity Types for the CiviCase component.'));
}
}
//check for case permissions.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if ($this->_action & CRM_Core_Action::ADD && (!CRM_Core_Permission::check('access all cases and activities') && !CRM_Core_Permission::check('add cases'))) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, 'Case')) {
$this->assign('activityTypeFile', $this->_activityTypeFile);
}
$details = CRM_Case_PseudoConstant::caseActivityType(FALSE);
CRM_Utils_System::setTitle($details[$this->_activityTypeId]['label']);
$this->assign('activityType', $details[$this->_activityTypeId]['label']);
$this->assign('activityTypeDescription', $details[$this->_activityTypeId]['description']);
if (isset($this->_currentlyViewedContactId)) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $this->_currentlyViewedContactId;
if (!$contact->find(TRUE)) {
CRM_Core_Error::statusBounce(ts('Client contact does not exist: %1', array(1 => $this->_currentlyViewedContactId)));
}
$this->assign('clientName', $contact->display_name);
}
$session = CRM_Core_Session::singleton();
$this->_currentUserId = $session->get('userID');
//when custom data is included in this page
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );");
$activityGroupTree = $this->_groupTree;
// for case custom fields to populate with defaults
if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
CRM_Custom_Form_CustomData::preProcess($this);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// so that grouptree is not populated with case fields, since the grouptree is used
// for populating activity custom fields.
$this->_groupTree = $activityGroupTree;
}
示例9: 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;
}
}
//.........这里部分代码省略.........
示例10: buildNoteTree
/**
* Recursive function to get all descendent notes of the note with given ID.
*
* @param int $parentId
* ID of the note to start from.
* @param int $maxDepth
* Maximum number of levels to descend into the tree; if not given, will include all descendents.
* @param bool $snippet
* If TRUE, returned values will be pre-formatted for display in a table of notes.
* @param array $tree
* (Reference) Variable to store all found descendents.
* @param int $depth
* Depth of current iteration within the descendent tree (used for comparison against maxDepth).
*
* @return array
* Nested associative array beginning with direct children of given note.
*/
private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = array(), $depth = 0)
{
if ($maxDepth && $depth > $maxDepth) {
return FALSE;
}
// get direct children of given parentId note
$note = new CRM_Core_DAO_Note();
$note->entity_table = 'civicrm_note';
$note->entity_id = $parentId;
$note->orderBy('modified_date asc');
$note->find();
while ($note->fetch()) {
// foreach child, call this function, unless the child is private/hidden
if (!self::getNotePrivacyHidden($note)) {
CRM_Core_DAO::storeValues($note, $tree[$note->id]);
// get name of user that created this note
$contact = new CRM_Contact_DAO_Contact();
$createdById = $note->contact_id;
$contact->id = $createdById;
$contact->find();
$contact->fetch();
$tree[$note->id]['createdBy'] = $contact->display_name;
$tree[$note->id]['createdById'] = $createdById;
$tree[$note->id]['modified_date'] = CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
// paper icon view for attachments part
$paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id);
$tree[$note->id]['attachment'] = $paperIconAttachmentInfo ? implode('', $paperIconAttachmentInfo) : '';
if ($snippet) {
$tree[$note->id]['note'] = nl2br($tree[$note->id]['note']);
$tree[$note->id]['note'] = smarty_modifier_mb_truncate($tree[$note->id]['note'], 80, '...', TRUE);
CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
}
self::buildNoteTree($note->id, $maxDepth, $snippet, $tree[$note->id]['child'], $depth + 1);
}
}
return $tree;
}
示例11: import
//.........这里部分代码省略.........
}
$formatValues = array();
foreach ($params as $key => $field) {
if ($field == null || $field === '') {
continue;
}
$formatValues[$key] = $field;
}
$formatError = _civicrm_membership_formatted_param($formatValues, $formatted, true);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
return CRM_Member_Import_Parser::ERROR;
}
if ($onDuplicate != CRM_Member_Import_Parser::DUPLICATE_UPDATE) {
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, null, 'Membership');
} else {
//fix for CRM-2219 Update Membership
// onDuplicate == CRM_Member_Import_Parser::DUPLICATE_UPDATE
if (CRM_Utils_Array::value('is_override', $formatted) && !CRM_Utils_Array::value('status_id', $formatted)) {
array_unshift($values, "Required parameter missing: Status");
return CRM_Member_Import_Parser::ERROR;
}
if ($formatValues['membership_id']) {
require_once 'CRM/Member/BAO/Membership.php';
$dao = new CRM_Member_BAO_Membership();
$dao->id = $formatValues['membership_id'];
$dates = array('join_date', 'start_date', 'end_date');
foreach ($dates as $v) {
if (!$formatted[$v]) {
$formatted[$v] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $formatValues['membership_id'], $v);
}
}
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, CRM_Core_DAO::$_nullObject, $formatValues['membership_id'], 'Membership');
if ($dao->find(true)) {
$ids = array('membership' => $formatValues['membership_id'], 'userId' => $session->get('userID'));
$newMembership =& CRM_Member_BAO_Membership::create($formatted, $ids, true);
if (civicrm_error($newMembership)) {
array_unshift($values, $newMembership['is_error'] . " for Membership ID " . $formatValues['membership_id'] . ". Row was skipped.");
return CRM_Member_Import_Parser::ERROR;
} else {
$this->_newMemberships[] = $newMembership->id;
return CRM_Member_Import_Parser::VALID;
}
} else {
array_unshift($values, "Matching Membership record not found for Membership ID " . $formatValues['membership_id'] . ". Row was skipped.");
return CRM_Member_Import_Parser::ERROR;
}
}
}
//Format dates
$startDate = CRM_Utils_Date::customFormat($formatted['start_date'], '%Y-%m-%d');
$endDate = CRM_Utils_Date::customFormat($formatted['end_date'], '%Y-%m-%d');
$joinDate = CRM_Utils_Date::customFormat($formatted['join_date'], '%Y-%m-%d');
if ($this->_contactIdIndex < 0) {
//retrieve contact id using contact dedupe rule
$formatValues['contact_type'] = $this->_contactType;
$error = civicrm_check_contact_dedupe($formatValues);
if (civicrm_duplicate($error)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
if (count($matchedIDs) > 1) {
array_unshift($values, "Multiple matching contact records detected for this row. The membership was not imported");
return CRM_Member_Import_Parser::ERROR;
} else {
$cid = $matchedIDs[0];
$formatted['contact_id'] = $cid;
//fix for CRM-1924
示例12: createBatchEntry
/**
* Required params
*
* From import record usually:
* 'contact_id',
* 'contact_display_name',
* 'net_amount',
* 'received_date',
*
* This usually goes from the form:
* 'payment_instrument_id',
* 'contribution_type_id',
* 'campaign_id',
*
* And from the code:
* 'batch_id',
* 'weight',
*
* Optional:
* 'transaction_id'
*
* @param array $params
* @return type
*/
protected function createBatchEntry(array $params)
{
//preload what we can
// if(isset($params['VARef'])) {
// require_once 'CRM/Contact/DAO/Contact.php';
// $contact = new CRM_Contact_DAO_Contact();
// $contact->external_identifier = $params['VARef'];
// $contact->find();
// if($contact->fetch() === false) {
// throw new Exception("Can't load contact using extenal_id = '{$params['VARef']}'");
// }
//
// $params['contact_id'] = $contact->id;
// $params['contactDisplayName'] = $contact->display_name;
// }
//check mandatory $params - others are checked in CRM_Batch_BAO_Batch::createContribution()
foreach (array() as $param) {
if (empty($params[$param])) {
throw new InvalidArgumentException("No param[{$param}] when creating the batch entry");
}
}
if (!isset($params['contact_display_name']) && isset($params['contact_id'])) {
require_once 'CRM/Contact/DAO/Contact.php';
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $params['contact_id'];
$contact->find();
if ($contact->fetch() === false) {
throw new Exception("Can't find user with id = '{$params['contact_id']}'");
}
//$params['contact_id'] = $contact->id;
$params['contact_display_name'] = $contact->display_name;
}
try {
require_once 'CRM/Finance/BAO/Batch.php';
return CRM_Finance_BAO_Batch::createContribution($params);
} catch (RuntimeException $e) {
throw new CRM_Finance_BAO_Import_ProcessException($e->getMessage(), $e->getCode(), $e);
}
}
示例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: updateRecords
/**
* updates contacts affected by the option value passed.
*
* @param Integer $optionValueId the option value id.
* @param int $action the action describing whether prefix/suffix was UPDATED or DELETED
*
* @return void
*/
static function updateRecords(&$optionValueId, $action)
{
//finding group name
$optionValue =& new CRM_Core_DAO_OptionValue();
$optionValue->id = $optionValueId;
$optionValue->find(true);
$optionGroup =& new CRM_Core_DAO_OptionGroup();
$optionGroup->id = $optionValue->option_group_id;
$optionGroup->find(true);
$gName = $optionGroup->name;
//group name
$value = $optionValue->value;
//value
// get the proper group name & affected field name
$individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id');
$contributions = array('payment_instrument' => 'payment_instrument_id');
$activities = array('activity_type' => 'activity_type_id');
$participant = array('participant_role' => 'role_id');
$eventType = array('event_type' => 'event_type_id');
$aclRole = array('acl_role' => 'acl_role_id');
$all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole);
$fieldName = '';
foreach ($all as $name => $id) {
if ($gName == $name) {
$fieldName = $id;
}
}
if ($fieldName == '') {
return true;
}
if (array_key_exists($gName, $individuals)) {
require_once 'CRM/Contact/BAO/Contact.php';
$contactDAO =& new CRM_Contact_DAO_Contact();
$contactDAO->{$fieldName} = $value;
$contactDAO->find();
while ($contactDAO->fetch()) {
if ($action == CRM_Core_Action::DELETE) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $contactDAO->id;
$contact->find(true);
// make sure dates doesn't get reset
$contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date);
$contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date);
$contact->{$fieldName} = 'NULL';
$contact->save();
}
}
return true;
}
if (array_key_exists($gName, $contributions)) {
require_once 'CRM/Contribute/DAO/Contribution.php';
$contribution =& new CRM_Contribute_DAO_Contribution();
$contribution->{$fieldName} = $value;
$contribution->find();
while ($contribution->fetch()) {
if ($action == CRM_Core_Action::DELETE) {
$contribution->{$fieldName} = 'NULL';
$contribution->save();
}
}
return true;
}
if (array_key_exists($gName, $activities)) {
require_once 'CRM/Activity/DAO/Activity.php';
$activity =& new CRM_Activity_DAO_Activity();
$activity->{$fieldName} = $value;
$activity->find();
while ($activity->fetch()) {
$activity->delete();
}
return true;
}
//delete participant role, type and event type option value
if (array_key_exists($gName, $participant)) {
require_once 'CRM/Event/DAO/Participant.php';
$participantValue =& new CRM_Event_DAO_Participant();
$participantValue->{$fieldName} = $value;
if ($participantValue->find(true)) {
return false;
}
return true;
}
//delete event type option value
if (array_key_exists($gName, $eventType)) {
require_once 'CRM/Event/DAO/Event.php';
$event =& new CRM_Event_DAO_Event();
$event->{$fieldName} = $value;
if ($event->find(true)) {
return false;
}
return true;
}
//.........这里部分代码省略.........
示例15: revert
//.........这里部分代码省略.........
case 'Insert':
if (!isset($deletes[$table])) {
$deletes[$table] = array();
}
$deletes[$table][] = $change['id'];
break;
case 'Delete':
case 'Update':
if (!isset($reverts[$table])) {
$reverts[$table] = array();
}
if (!isset($reverts[$table][$change['id']])) {
$reverts[$table][$change['id']] = array('log_action' => $change['action']);
}
$reverts[$table][$change['id']][$change['field']] = $change['from'];
break;
}
}
}
// revert inserts by deleting
foreach ($deletes as $table => $ids) {
CRM_Core_DAO::executeQuery("DELETE FROM `{$table}` WHERE id IN (" . implode(', ', array_unique($ids)) . ')');
}
// revert updates by updating to previous values
foreach ($reverts as $table => $row) {
switch (TRUE) {
// DAO-based tables
case in_array($table, array_keys($daos)):
require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php';
eval("\$dao = new {$daos[$table]};");
foreach ($row as $id => $changes) {
$dao->id = $id;
foreach ($changes as $field => $value) {
if ($field == 'log_action') {
continue;
}
if (empty($value) and $value !== 0 and $value !== '0') {
$value = 'null';
}
$dao->{$field} = $value;
}
$changes['log_action'] == 'Delete' ? $dao->insert() : $dao->update();
$dao->reset();
}
break;
// custom data tables
// custom data tables
case in_array($table, array_keys($ctypes)):
foreach ($row as $id => $changes) {
$inserts = array('id' => '%1');
$updates = array();
$params = array(1 => array($id, 'Integer'));
$counter = 2;
foreach ($changes as $field => $value) {
// don’t try reverting a field that’s no longer there
if (!isset($ctypes[$table][$field])) {
continue;
}
switch ($ctypes[$table][$field]) {
case 'Date':
$value = substr(CRM_Utils_Date::isoToMysql($value), 0, 8);
break;
case 'Timestamp':
$value = CRM_Utils_Date::isoToMysql($value);
break;
}
$inserts[$field] = "%{$counter}";
$updates[] = "{$field} = %{$counter}";
$params[$counter] = array($value, $ctypes[$table][$field]);
$counter++;
}
if ($changes['log_action'] == 'Delete') {
$sql = "INSERT INTO `{$table}` (" . implode(', ', array_keys($inserts)) . ') VALUES (' . implode(', ', $inserts) . ')';
} else {
$sql = "UPDATE `{$table}` SET " . implode(', ', $updates) . ' WHERE id = %1';
}
CRM_Core_DAO::executeQuery($sql, $params);
}
break;
}
}
// CRM-7353: if nothing altered civicrm_contact, touch it; this will
// make sure there’s an entry in log_civicrm_contact for this revert
if (empty($diffs['civicrm_contact'])) {
$query = "\n SELECT id FROM `{$this->db}`.log_civicrm_contact\n WHERE log_conn_id = %1 AND log_date BETWEEN DATE_SUB(%2, INTERVAL 10 SECOND) AND DATE_ADD(%2, INTERVAL 10 SECOND)\n ORDER BY log_date DESC LIMIT 1\n ";
$params = array(1 => array($this->log_conn_id, 'Integer'), 2 => array($this->log_date, 'String'));
$cid = CRM_Core_DAO::singleValueQuery($query, $params);
if (!$cid) {
return;
}
$dao = new CRM_Contact_DAO_Contact();
$dao->id = $cid;
if ($dao->find(TRUE)) {
// CRM-8102: MySQL can’t parse its own dates
$dao->birth_date = CRM_Utils_Date::isoToMysql($dao->birth_date);
$dao->deceased_date = CRM_Utils_Date::isoToMysql($dao->deceased_date);
$dao->save();
}
}
}