<![CDATA[ Is it possible to get a modUser based on just a profile field? - My Forums]]> https://forums.modx.com/thread/?thread=104048 <![CDATA[Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559553 zenpixel Jul 13, 2018, 05:06 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559553 <![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-563407 annaxh55 Dec 31, 2018, 05:20 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-563407 <![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559660
I think this would do it:

$pattern = '/.*129.*871.*2987/';
]]>
BobRay Jul 18, 2018, 06:57 AM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559660
<![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559642 zenpixel Jul 16, 2018, 10:30 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559642 <![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559567
$phone = '1298712987';

$profile = $modx->getObject('modUserProfile', array('phone' => $phone));

if ($profile) {
    $user = $modx->getObject('modUser', array('id' => $profile->get('internalKey')));
} else {
   /* Error */
}


I think using $modx->getObjectGraph() would be faster yet, since it would make only one query to the DB, but I'm too tired to work it out. wink
]]>
BobRay Jul 14, 2018, 06:07 AM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559567
<![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559558 donshakespeare Jul 13, 2018, 09:03 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559558 <![CDATA[Re: Is it possible to get a modUser based on just a profile field?]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559557 zenpixel Jul 13, 2018, 08:57 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559557 <![CDATA[Re: Is it possible to get a modUser based on just a profile field? (Best Answer)]]> https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559556 Since the profile items are in a different table and its fields are not found on the id card of the user, you need to make a couple of filtration on the db query level, and then the rest is history!

$userRecord = "";
$userID = "";


$c = $modx->newQuery('modUser'); //query the users table
$c->innerJoin('modUserProfile','Profile'); //add on the profile table to the query
$c->where(array( //the filtration is right here. query the joined tables with "WHERE"...
'active' => true, //is the user active?
'Profile.phone' => "8009991234", //change the phone number, or use whatever field you want
// 'Profile.phone:LIKE' => "800%", //phone number starts with 800
// 'Profile.phone:LIKE' => "%800", //phone number ends in 800
// 'Profile.phone:LIKE' => "%800%", //phone number contains 800
));

$users = $modx->getCollection('modUser',$c); //move from raw query to usable items
foreach($users as $user){
  $userRecord = $user; //the user record with that phone number and hopefully the only one
  $userID = (string)$user->get("id"); //let's test this record by grabbing the id
}

/*if the phone# was good $userRecord and $userID will now become available */


Cheers!]]>
donshakespeare Jul 13, 2018, 08:03 PM https://forums.modx.com/thread/104048/is-it-possible-to-get-a-moduser-based-on-just-a-profile-field#dis-post-559556