<?php
$sectors = explode('||',str_replace(',','||',$resource->getTVValue('Sector')));
$functions = explode('||',str_replace(',','||',$resource->getTVValue('Function')));
$userClass = $modx->getOption('userDataClass', $sp, 'userData');
$c = $modx->newQuery($userClass);
$c->where(array($userClass.'.sector:IN'=>$sectors,$userClass.'.function:IN'=>$functions));
if ($users = $modx->getCollectionGraph($userClass, '{"Profile":{},"User":{}}', $c)){
foreach ($users as $user){
//do something with the user here:
$user_array = $user->toArray();
}
}
<?php
$sector = $resource->getTVValue('Sector');
$function = $resource->getTVValue('Function');
$userClass = $modx->getOption('userDataClass', $sp, 'userData');
$c = $modx->newQuery($userClass);
$c->where(array($userClass.'.sector:LIKE'=>'%'.$sector.'%',$userClass.'.function:LIKE'=>'%'.$function.'%'));
if ($users = $modx->getCollectionGraph($userClass, '{"Profile":{},"User":{}}', $c)){
foreach ($users as $user){
//do something with the user here:
$user_array = $user->toArray();
}
}
$tvid = 'yourTvId';
if ($tv = $modx->getObject('modTemplateVarResource',array('contentid'=>$resource->get('id'),'tmplvarid'=>$tvid))){
$sections = explode('||',$tv->get('value'));
}<?php
$profiles = $modx->getCollection('modUserProfile');
foreach ($profiles as $profile) {
$sendmail = false;
$extended = $profile->get('extended');
$usersectors = explode(',',$extended['Sector']);
foreach($sections as $section){
if (in_array($section,$usersectors)){
$sendmail = true;
}
}
if ($sendmail){
sendmail();
}
}$Sector = $resource->getTVValue('Sector');
$Function = explode(', ',$resource->getTVValue('Function');
$profiles = $modx->getCollection('modUserProfile');
foreach ($profiles as $profile) {
$extended = $profile->get('extended');
$usersector = $extended['Sector'];
$userfunction = $extended['Function'];
$intersection = array_intersect($Function, $userfunction);
// Loop though the Profiles and select qualified users & Get extended profile
if (in_array($Sector,$usersector) || !empty($intersection))
{send an email}Thank you, Bruno. I couldn't get the raw value working, so what I did was use the output from getTVValue, which was delimited in the TV Output Options with ", ":
For checking a single "Sector" TV value against an array of multiple values in the user Sector extended fields OR checking if one value of a multi-select TV "Function" is also present in an array of multiple values in the user Function extended fields, I used
$Sector = $resource->getTVValue('Sector'); $Function = explode(', ',$resource->getTVValue('Function'); $profiles = $modx->getCollection('modUserProfile'); foreach ($profiles as $profile) { $extended = $profile->get('extended'); $usersector = $extended['Sector']; $userfunction = $extended['Function']; $intersection = array_intersect($Function, $userfunction); // Loop though the Profiles and select qualified users & Get extended profile if (in_array($Sector,$usersector) || !empty($intersection)) {send an email}
It's probably not ideal, but it works! Thanks for your help.