We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32540
    • 19 Posts
    Has anyone extended the WLPE class to handle a lookup of an array of user ids?

    I wrote this snippet [[WebLoginPEUsers]]
    <?php
    
    if (isset($_REQUEST['userids'])) {
    
        	$ids = explode(',', str_replace(', ',',',$_REQUEST['userids']));
        	$ids = array_unique($ids);
        	$first = reset($ids);
        	$last = end($ids);
        	$idList = "";
        	
        	foreach($ids as $id){
        		$idList = $idList . "Members:default:default:username:ASC:id(".$id.")";
        		
        		if($id != $last) {
        			$idList = $idList . "||";
        		}
        	}
        	//$output = $idList;
    	$output = $modx->runSnippet(
            "WebLoginPE",
            array(
                "type" => "users",
                "usersOuterTpl" => "User:VariantUsersWrapper",
                "usersTpl" => "User:VariantUsers",
                "messageTpl" => "User:ServerResponse",
                "usersList" => $idList
            )
    	);
    	
    unset($ids);
    return $output;
    }
    ?>
    


    And I modified ViewAllUsers() in webloginpe.class.php:

    case 'id':
    	$idCheck = "SELECT * FROM ".$web_users." WHERE `id` = '".$filterValue."'";
    	$hasValidID = $modx->db->query($idCheck);
    	$count = $modx->db->getRecordCount($hasValidID);
    	if (empty($theUser[$filterBy]) || $theUser[$filterBy] == '' && $filterBy !== 'webgroup' || $count === 0)
    	{
    		$username = $theUser['username'];
    		unset($CompleteUserList[$username]);
    	}
    
    	if (isset($filterValue) && $filterBy !== 'webgroup')
    	{
    		if ($theUser[$filterBy] !== '' && !empty($theUser[$filterBy]))
    		{
    			$isValue = strpos(strtolower($filterValue), strtolower($theUser[$filterBy]));
    			$isValueAlt = strpos(strtolower($theUser[$filterBy]), strtolower($filterValue));
    			if ($isValue === false && $isValueAlt === false)
    			{
    				$username = $theUser['username'];
    				unset($CompleteUserList[$username]);
    			}
    		}
    	}
    	break;
    


    It works okay, but it’s returning user records when their id’s contain a partial match of another id. For example /index.php?id=70&userids=1,2 will return user ids of 1, 2, 10, 11, and 12. Any thoughts?
      • 32540
      • 19 Posts
      Fixed it myself:

      case 'id':
      	$username = $theUser['username'];
      	$userid = $theUser['internalKey'];
      	if ($filterValue != $userid) {
      		unset($CompleteUserList[$username]);
      	}
      	break;