Merge pull request #16884 from civicrm/5.24
[civicrm-core.git] / CRM / Core / BAO / UFMatch.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
8eedd10a 19 * The basic class that interfaces with the external user framework.
6a488035
TO
20 */
21class CRM_Core_BAO_UFMatch extends CRM_Core_DAO_UFMatch {
22
b5c2afd0 23 /**
b44e3f84 24 * Create UF Match, Note that this function is here in it's simplest form @ the moment
b5c2afd0 25 *
ced9bfed
EM
26 * @param $params
27 *
28 * @return \CRM_Core_DAO_UFMatch
b5c2afd0 29 */
00be9182 30 public static function create($params) {
6a488035
TO
31 $hook = empty($params['id']) ? 'create' : 'edit';
32 CRM_Utils_Hook::pre($hook, 'UFMatch', CRM_Utils_Array::value('id', $params), $params);
22e263ad 33 if (empty($params['domain_id'])) {
e0e29b3c 34 $params['domain_id'] = CRM_Core_Config::domainID();
35 }
6a488035
TO
36 $dao = new CRM_Core_DAO_UFMatch();
37 $dao->copyValues($params);
ce4abc8e 38 // Fixme: this function cannot update records
69301426 39 if (!$dao->find(TRUE)) {
40 $dao->save();
ce4abc8e
CW
41 Civi::$statics[__CLASS__][$params['domain_id']][(int) $dao->contact_id] = (int) $dao->uf_id;
42 CRM_Utils_Hook::post($hook, 'UFMatch', $dao->id, $dao);
69301426 43 }
6a488035
TO
44 return $dao;
45 }
46
6a488035
TO
47 /**
48 * Given a UF user object, make sure there is a contact
49 * object for this user. If the user has new values, we need
50 * to update the CRM DB with the new values
51 *
6a0b768e
TO
52 * @param Object $user
53 * The drupal user object.
54 * @param bool $update
55 * Has the user object been edited.
77b97be7
EM
56 * @param $uf
57 *
58 * @param $ctype
59 * @param bool $isLogin
6a488035 60 */
00be9182 61 public static function synchronize(&$user, $update, $uf, $ctype, $isLogin = FALSE) {
2b617cb0 62 $userSystem = CRM_Core_Config::singleton()->userSystem;
6a488035
TO
63 $session = CRM_Core_Session::singleton();
64 if (!is_object($session)) {
65 CRM_Core_Error::fatal('wow, session is not an object?');
66 return;
67 }
68
2b617cb0
EM
69 $userSystemID = $userSystem->getBestUFID($user);
70 $uniqId = $userSystem->getBestUFUniqueIdentifier($user);
6a488035
TO
71
72 // if the id of the object is zero (true for anon users in drupal)
73 // have we already processed this user, if so early
74 // return.
75 $userID = $session->get('userID');
76 $ufID = $session->get('ufID');
77
32998c82 78 if (!$update && $ufID == $userSystemID) {
6a488035
TO
79 return;
80 }
81
82 //check do we have logged in user.
83 $isUserLoggedIn = CRM_Utils_System::isUserLoggedIn();
84
85 // reset the session if we are a different user
32998c82 86 if ($ufID && $ufID != $userSystemID) {
6a488035
TO
87 $session->reset();
88
89 //get logged in user ids, and set to session.
90 if ($isUserLoggedIn) {
91 $userIds = self::getUFValues();
92 $session->set('ufID', CRM_Utils_Array::value('uf_id', $userIds, ''));
93 $session->set('userID', CRM_Utils_Array::value('contact_id', $userIds, ''));
94 $session->set('ufUniqID', CRM_Utils_Array::value('uf_name', $userIds, ''));
95 }
96 }
97
98 // return early
32998c82 99 if ($userSystemID == 0) {
6a488035
TO
100 return;
101 }
102
32998c82 103 $ufmatch = self::synchronizeUFMatch($user, $userSystemID, $uniqId, $uf, NULL, $ctype, $isLogin);
6a488035
TO
104 if (!$ufmatch) {
105 return;
106 }
107
108 //make sure we have session w/ consistent ids.
353ffa53
TO
109 $ufID = $ufmatch->uf_id;
110 $userID = $ufmatch->contact_id;
6a488035
TO
111 $ufUniqID = '';
112 if ($isUserLoggedIn) {
113 $loggedInUserUfID = CRM_Utils_System::getLoggedInUfID();
114 //are we processing logged in user.
115 if ($loggedInUserUfID && $loggedInUserUfID != $ufID) {
353ffa53
TO
116 $userIds = self::getUFValues($loggedInUserUfID);
117 $ufID = CRM_Utils_Array::value('uf_id', $userIds, '');
118 $userID = CRM_Utils_Array::value('contact_id', $userIds, '');
6a488035
TO
119 $ufUniqID = CRM_Utils_Array::value('uf_name', $userIds, '');
120 }
121 }
122
123 //set user ids to session.
124 $session->set('ufID', $ufID);
125 $session->set('userID', $userID);
126 $session->set('ufUniqID', $ufUniqID);
127
128 // add current contact to recently viewed
129 if ($ufmatch->contact_id) {
79d7553f 130 list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl)
131 = CRM_Contact_BAO_Contact::getDisplayAndImage($ufmatch->contact_id, TRUE, TRUE);
6a488035 132
be2fb01f 133 $otherRecent = [
6a488035
TO
134 'imageUrl' => $contactImageUrl,
135 'subtype' => $contactSubtype,
136 'editUrl' => CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$ufmatch->contact_id}"),
be2fb01f 137 ];
6a488035
TO
138
139 CRM_Utils_Recent::add($displayName,
140 CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$ufmatch->contact_id}"),
141 $ufmatch->contact_id,
142 $contactType,
143 $ufmatch->contact_id,
144 $displayName,
145 $otherRecent
146 );
147 }
148 }
149
150 /**
151 * Synchronize the object with the UF Match entry. Can be called stand-alone from
152 * the drupalUsers script
153 *
6a0b768e
TO
154 * @param Object $user
155 * The drupal user object.
156 * @param string $userKey
157 * The id of the user from the uf object.
158 * @param string $uniqId
159 * The OpenID of the user.
160 * @param string $uf
161 * The name of the user framework.
162 * @param int $status
163 * Returns the status if user created or already exits (used for CMS sync).
72b3a70c
CW
164 * @param string $ctype
165 * contact type
fd31fa4c 166 * @param bool $isLogin
6a488035 167 *
72b3a70c 168 * @return CRM_Core_DAO_UFMatch|bool
6a488035 169 */
00be9182 170 public static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $status = NULL, $ctype = NULL, $isLogin = FALSE) {
6a488035
TO
171 $config = CRM_Core_Config::singleton();
172
173 if (!CRM_Utils_Rule::email($uniqId)) {
174 $retVal = $status ? NULL : FALSE;
175 return $retVal;
176 }
177
178 $newContact = FALSE;
179
180 // make sure that a contact id exists for this user id
353ffa53 181 $ufmatch = new CRM_Core_DAO_UFMatch();
6a488035 182 $ufmatch->domain_id = CRM_Core_Config::domainID();
353ffa53 183 $ufmatch->uf_id = $userKey;
6a488035
TO
184
185 if (!$ufmatch->find(TRUE)) {
186 $transaction = new CRM_Core_Transaction();
187
188 $dao = NULL;
189 if (!empty($_POST) && !$isLogin) {
190 $params = $_POST;
191 $params['email'] = $uniqId;
192
be2fb01f 193 $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, 'Individual', 'Unsupervised', [], FALSE);
6a488035 194
aaffa79f 195 if (!empty($ids) && Civi::settings()->get('uniq_email_per_site')) {
6a488035
TO
196 // restrict dupeIds to ones that belong to current domain/site.
197 $siteContacts = CRM_Core_BAO_Domain::getContactList();
198 foreach ($ids as $index => $dupeId) {
199 if (!in_array($dupeId, $siteContacts)) {
200 unset($ids[$index]);
201 }
202 }
203 // re-index the array
204 $ids = array_values($ids);
205 }
206 if (!empty($ids)) {
207 $dao = new CRM_Core_DAO();
208 $dao->contact_id = $ids[0];
209 }
210 }
211 else {
212 $dao = CRM_Contact_BAO_Contact::matchContactOnEmail($uniqId, $ctype);
213 }
214
215 $found = FALSE;
216 if ($dao) {
217 // ensure there does not exists a contact_id / uf_id pair
218 // in the DB. This might be due to multiple emails per contact
219 // CRM-9091
220 $sql = "
221SELECT id
222FROM civicrm_uf_match
223WHERE contact_id = %1
224AND domain_id = %2
225";
be2fb01f
CW
226 $params = [
227 1 => [$dao->contact_id, 'Integer'],
228 2 => [CRM_Core_Config::domainID(), 'Integer'],
229 ];
6a488035
TO
230 $conflict = CRM_Core_DAO::singleValueQuery($sql, $params);
231
232 if (!$conflict) {
353ffa53 233 $found = TRUE;
6a488035 234 $ufmatch->contact_id = $dao->contact_id;
353ffa53 235 $ufmatch->uf_name = $uniqId;
6a488035
TO
236 }
237 }
238
239 if (!$found) {
3eb59ab5
AS
240 // Not sure why we're testing for this. Is there ever a case
241 // in which $user is not an object?
b7d765aa 242 if (is_object($user)) {
3eb59ab5
AS
243 if ($config->userSystem->is_drupal) {
244 $primary_email = $uniqId;
245 }
246 elseif ($uf == 'WordPress') {
247 $primary_email = $user->user_email;
248 }
249 else {
250 $primary_email = $user->email;
251 }
be2fb01f 252 $params = ['email-Primary' => $primary_email];
6a488035
TO
253 }
254
255 if ($ctype == 'Organization') {
256 $params['organization_name'] = $uniqId;
257 }
258 elseif ($ctype == 'Household') {
259 $params['household_name'] = $uniqId;
260 }
261
262 if (!$ctype) {
263 $ctype = "Individual";
264 }
265 $params['contact_type'] = $ctype;
266
267 // extract first / middle / last name
268 // for joomla
269 if ($uf == 'Joomla' && $user->name) {
270 CRM_Utils_String::extractName($user->name, $params);
271 }
272
273 if ($uf == 'WordPress') {
274 if ($user->first_name) {
275 $params['first_name'] = $user->first_name;
276 }
277
278 if ($user->last_name) {
279 $params['last_name'] = $user->last_name;
280 }
281 }
282
7b4b0b68 283 $contactId = CRM_Contact_BAO_Contact::createProfileContact($params);
6a488035 284 $ufmatch->contact_id = $contactId;
353ffa53 285 $ufmatch->uf_name = $uniqId;
6a488035
TO
286 }
287
288 // check that there are not two CMS IDs matching the same CiviCRM contact - this happens when a civicrm
289 // user has two e-mails and there is a cms match for each of them
290 // the gets rid of the nasty fata error but still reports the error
291 $sql = "
292SELECT uf_id
293FROM civicrm_uf_match
294WHERE ( contact_id = %1
295OR uf_name = %2
296OR uf_id = %3 )
297AND domain_id = %4
298";
be2fb01f
CW
299 $params = [
300 1 => [$ufmatch->contact_id, 'Integer'],
301 2 => [$ufmatch->uf_name, 'String'],
302 3 => [$ufmatch->uf_id, 'Integer'],
303 4 => [$ufmatch->domain_id, 'Integer'],
304 ];
6a488035
TO
305
306 $conflict = CRM_Core_DAO::singleValueQuery($sql, $params);
307
308 if (!$conflict) {
309 $ufmatch = CRM_Core_BAO_UFMatch::create((array) $ufmatch);
6a488035
TO
310 $newContact = TRUE;
311 $transaction->commit();
312 }
313 else {
314 $msg = ts("Contact ID %1 is a match for %2 user %3 but has already been matched to %4",
be2fb01f 315 [
6a488035
TO
316 1 => $ufmatch->contact_id,
317 2 => $uf,
318 3 => $ufmatch->uf_id,
21dfd5f5 319 4 => $conflict,
be2fb01f 320 ]
6a488035
TO
321 );
322 unset($conflict);
323 }
324 }
325
326 if ($status) {
327 return $newContact;
328 }
329 else {
330 return $ufmatch;
331 }
332 }
333
334 /**
fe482240 335 * Update the uf_name in the user object.
6a488035 336 *
6a0b768e
TO
337 * @param int $contactId
338 * Id of the contact to update.
6a488035 339 */
00be9182 340 public static function updateUFName($contactId) {
5e7f101a 341 if (!Civi::settings()->get('syncCMSEmail') || !$contactId) {
6a488035
TO
342 return;
343 }
5e7f101a 344
6a488035
TO
345 $config = CRM_Core_Config::singleton();
346 $ufName = CRM_Contact_BAO_Contact::getPrimaryEmail($contactId);
347
348 if (!$ufName) {
349 return;
350 }
351
352 $update = FALSE;
353
354 // 1.do check for contact Id.
353ffa53 355 $ufmatch = new CRM_Core_DAO_UFMatch();
6a488035 356 $ufmatch->contact_id = $contactId;
353ffa53 357 $ufmatch->domain_id = CRM_Core_Config::domainID();
6a488035
TO
358 if (!$ufmatch->find(TRUE)) {
359 return;
360 }
361 if ($ufmatch->uf_name != $ufName) {
362 $update = TRUE;
363 }
364
365 // CRM-6928
366 // 2.do check for duplicate ufName.
367 $ufDupeName = new CRM_Core_DAO_UFMatch();
368 $ufDupeName->uf_name = $ufName;
369 $ufDupeName->domain_id = CRM_Core_Config::domainID();
370 if ($ufDupeName->find(TRUE) &&
371 $ufDupeName->contact_id != $contactId
372 ) {
373 $update = FALSE;
374 }
375
376 if (!$update) {
377 return;
378 }
379
380 // save the updated ufmatch object
381 $ufmatch->uf_name = $ufName;
382 $ufmatch->save();
383 $config->userSystem->updateCMSName($ufmatch->uf_id, $ufName);
384 }
385
386 /**
fe482240 387 * Update the email value for the contact and user profile.
6a488035 388 *
5a4f6742
CW
389 * @param int $contactId
390 * Contact ID of the user.
8eedd10a 391 * @param string $emailAddress
6a0b768e 392 * Email to be modified for the user.
6a488035 393 */
00be9182 394 public static function updateContactEmail($contactId, $emailAddress) {
6a488035
TO
395 $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
396 $emailAddress = $strtolower($emailAddress);
397
353ffa53 398 $ufmatch = new CRM_Core_DAO_UFMatch();
6a488035 399 $ufmatch->contact_id = $contactId;
353ffa53 400 $ufmatch->domain_id = CRM_Core_Config::domainID();
6a488035
TO
401 if ($ufmatch->find(TRUE)) {
402 // Save the email in UF Match table
403 $ufmatch->uf_name = $emailAddress;
404 CRM_Core_BAO_UFMatch::create((array) $ufmatch);
405
5e7f101a 406 // If CMS integration is disabled skip Civi email update if CMS user email is changed
407 if (Civi::settings()->get('syncCMSEmail') == FALSE) {
408 return;
409 }
410
6a488035
TO
411 //check if the primary email for the contact exists
412 //$contactDetails[1] - email
413 //$contactDetails[3] - email id
414 $contactDetails = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId);
415
416 if (trim($contactDetails[1])) {
56e50a8b 417 //update if record is found but different
6a488035 418 $emailID = $contactDetails[3];
56e50a8b
AS
419 if (trim($contactDetails[1]) != $emailAddress) {
420 civicrm_api3('Email', 'create', [
421 'id' => $emailID,
422 'email' => $emailAddress,
423 ]);
424 }
6a488035
TO
425 }
426 else {
427 //else insert a new email record
56e50a8b
AS
428 $result = civicrm_api3('Email', 'create', [
429 'contact_id' => $contactId,
430 'email' => $emailAddress,
431 'is_primary' => 1,
432 ]);
a650ed47 433 $emailID = $result['id'];
6a488035
TO
434 }
435
436 CRM_Core_BAO_Log::register($contactId,
437 'civicrm_email',
438 $emailID
439 );
440 }
441 }
442
443 /**
fe482240 444 * Delete the object records that are associated with this cms user.
6a488035 445 *
6a0b768e
TO
446 * @param int $ufID
447 * Id of the user to delete.
6a488035 448 */
00be9182 449 public static function deleteUser($ufID) {
6a488035
TO
450 $ufmatch = new CRM_Core_DAO_UFMatch();
451
452 $ufmatch->uf_id = $ufID;
ce4abc8e 453 $ufmatch->domain_id = $domainId = CRM_Core_Config::domainID();
6a488035 454 $ufmatch->delete();
ce4abc8e
CW
455
456 // Flush cache
457 Civi::$statics[__CLASS__][$domainId] = [];
6a488035
TO
458 }
459
460 /**
fe482240 461 * Get the contact_id given a uf_id.
6a488035 462 *
6a0b768e
TO
463 * @param int $ufID
464 * Id of UF for which related contact_id is required.
6a488035 465 *
e97c66ff 466 * @return int|null
a6c01b45 467 * contact_id on success, null otherwise
6a488035 468 */
00be9182 469 public static function getContactId($ufID) {
ce4abc8e 470 if (!$ufID) {
6a488035
TO
471 return NULL;
472 }
ce4abc8e 473 $domainId = CRM_Core_Config::domainID();
6a488035 474
ce4abc8e
CW
475 if (!isset(Civi::$statics[__CLASS__][$domainId])) {
476 Civi::$statics[__CLASS__][$domainId] = [];
477 }
478 $contactId = array_search($ufID, Civi::$statics[__CLASS__][$domainId]);
479 if ($contactId) {
480 return $contactId;
481 }
6a488035 482 $ufmatch = new CRM_Core_DAO_UFMatch();
6a488035 483 $ufmatch->uf_id = $ufID;
ce4abc8e 484 $ufmatch->domain_id = $domainId;
6a488035 485 if ($ufmatch->find(TRUE)) {
ce4abc8e
CW
486 $contactId = (int) $ufmatch->contact_id;
487 Civi::$statics[__CLASS__][$domainId][$contactId] = (int) $ufID;
488 return $contactId;
6a488035
TO
489 }
490 return NULL;
491 }
492
493 /**
fe482240 494 * Get the uf_id given a contact_id.
6a488035 495 *
6a0b768e
TO
496 * @param int $contactID
497 * ID of the contact for which related uf_id is required.
6a488035 498 *
e97c66ff 499 * @return int|null
a6c01b45 500 * uf_id of the given contact_id on success, null otherwise
6a488035 501 */
00be9182 502 public static function getUFId($contactID) {
ce4abc8e 503 if (!$contactID) {
6a488035
TO
504 return NULL;
505 }
ce4abc8e
CW
506 $domainId = CRM_Core_Config::domainID();
507 $contactID = (int) $contactID;
508
509 if (empty(Civi::$statics[__CLASS__][$domainId]) || !array_key_exists($contactID, Civi::$statics[__CLASS__][$domainId])) {
510 Civi::$statics[__CLASS__][$domainId][$contactID] = NULL;
511 $ufmatch = new CRM_Core_DAO_UFMatch();
512 $ufmatch->contact_id = $contactID;
513 $ufmatch->domain_id = $domainId;
514 if ($ufmatch->find(TRUE)) {
515 Civi::$statics[__CLASS__][$domainId][$contactID] = (int) $ufmatch->uf_id;
516 }
6a488035 517 }
ce4abc8e 518 return Civi::$statics[__CLASS__][$domainId][$contactID];
6a488035
TO
519 }
520
b5c2afd0 521 /**
f0612cdb 522 * @deprecated
b5c2afd0
EM
523 * @return bool
524 */
00be9182 525 public static function isEmptyTable() {
f0612cdb 526 CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
6a488035
TO
527 $sql = "SELECT count(id) FROM civicrm_uf_match";
528 return CRM_Core_DAO::singleValueQuery($sql) > 0 ? FALSE : TRUE;
529 }
530
531 /**
fe482240 532 * Get the list of contact_id.
6a488035 533 *
f0612cdb 534 * @deprecated
a6c01b45
CW
535 * @return int
536 * contact_id on success, null otherwise
6a488035 537 */
00be9182 538 public static function getContactIDs() {
f0612cdb 539 CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
be2fb01f 540 $id = [];
6a488035
TO
541 $dao = new CRM_Core_DAO_UFMatch();
542 $dao->find();
543 while ($dao->fetch()) {
544 $id[] = $dao->contact_id;
545 }
546 return $id;
547 }
548
549 /**
100fef9d 550 * See if this user exists, and if so, if they're allowed to login
6a488035 551 *
f0612cdb 552 * @deprecated
100fef9d 553 * @param int $openId
2a6da8d7 554 *
a6c01b45
CW
555 * @return bool
556 * true if allowed to login, false otherwise
6a488035 557 */
00be9182 558 public static function getAllowedToLogin($openId) {
f0612cdb 559 CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
6a488035
TO
560 $ufmatch = new CRM_Core_DAO_UFMatch();
561 $ufmatch->uf_name = $openId;
562 $ufmatch->allowed_to_login = 1;
563 if ($ufmatch->find(TRUE)) {
564 return TRUE;
565 }
566 return FALSE;
567 }
568
569 /**
100fef9d 570 * Get the next unused uf_id value, since the standalone UF doesn't
6a488035
TO
571 * have id's (it uses OpenIDs, which go in a different field)
572 *
f0612cdb 573 * @deprecated
a6c01b45
CW
574 * @return int
575 * next highest unused value for uf_id
6a488035 576 */
00be9182 577 public static function getNextUfIdValue() {
f0612cdb 578 CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
6a488035
TO
579 $query = "SELECT MAX(uf_id)+1 AS next_uf_id FROM civicrm_uf_match";
580 $dao = CRM_Core_DAO::executeQuery($query);
581 if ($dao->fetch()) {
582 $ufId = $dao->next_uf_id;
583 }
584
585 if (!isset($ufId)) {
586 $ufId = 1;
587 }
588 return $ufId;
589 }
590
b5c2afd0
EM
591 /**
592 * @param $email
f0612cdb 593 * @deprecated
b5c2afd0
EM
594 * @return bool
595 */
00be9182 596 public static function isDuplicateUser($email) {
f0612cdb 597 CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
6a488035
TO
598 $session = CRM_Core_Session::singleton();
599 $contactID = $session->get('userID');
600 if (!empty($email) && isset($contactID)) {
601 $dao = new CRM_Core_DAO_UFMatch();
602 $dao->uf_name = $email;
603 if ($dao->find(TRUE) && $contactID != $dao->contact_id) {
604 return TRUE;
605 }
606 }
607 return FALSE;
608 }
609
610 /**
611 * Get uf match values for given uf id or logged in user.
612 *
6a0b768e
TO
613 * @param int $ufID
614 * Uf id.
6a488035 615 *
77b97be7 616 * @return array
76e7a76c 617 * uf values.
77b97be7 618 */
00be9182 619 public static function getUFValues($ufID = NULL) {
6a488035
TO
620 if (!$ufID) {
621 //get logged in user uf id.
622 $ufID = CRM_Utils_System::getLoggedInUfID();
623 }
624 if (!$ufID) {
be2fb01f 625 return [];
6a488035
TO
626 }
627
628 static $ufValues;
629 if ($ufID && !isset($ufValues[$ufID])) {
353ffa53
TO
630 $ufmatch = new CRM_Core_DAO_UFMatch();
631 $ufmatch->uf_id = $ufID;
6a488035
TO
632 $ufmatch->domain_id = CRM_Core_Config::domainID();
633 if ($ufmatch->find(TRUE)) {
be2fb01f 634 $ufValues[$ufID] = [
6a488035
TO
635 'uf_id' => $ufmatch->uf_id,
636 'uf_name' => $ufmatch->uf_name,
637 'contact_id' => $ufmatch->contact_id,
638 'domain_id' => $ufmatch->domain_id,
be2fb01f 639 ];
6a488035
TO
640 }
641 }
642 return $ufValues[$ufID];
643 }
96025800 644
d343069c
CW
645 /**
646 * @inheritDoc
647 */
20e41014 648 public function addSelectWhereClause() {
d343069c 649 // Prevent default behavior of joining ACLs onto the contact_id field
be2fb01f 650 $clauses = [];
032346cc
CW
651 CRM_Utils_Hook::selectWhereClause($this, $clauses);
652 return $clauses;
d343069c
CW
653 }
654
6a488035 655}