We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22827
    • 129 Posts
    Hello,

    I am looking at the filtering options in wlpe, and would like to give the admins the ability to search for users with a specific post code or surname etc.

    The filtering is pretty comprehensive, but seems to be only accessible via the snippet call - is this right? So in order to use filtering with a form, I’d need to wrap the wple call in another snippet that read $_REQUEST vars and constructed the usersList parameter and then called wple?

    Seems that adding the 2nd line to the snippet:
    	$usersList = isset($usersList) ? $usersList : '';
            $usersList = isset($_REQUEST['wlpe_usersList') ? $_REQUEST['wlpe_usersList'] : $usersList;
    


    Would allow filtering via post variables (perhaps limited to the manager function to avoid monkey business).

    Cheers,

    Paul


    Thanks,
      • 22827
      • 129 Posts
      Ah, ok, adding the $_REQUEST line isn’t actually that useful.

      It seems that a snippet wrapper is required after all. If anyone has created one already, posting it would be cool smiley
        • 22827
        • 129 Posts
        Ok... well I created a wrapper in the end.

        Hopefully it was the right way to go about it... It isn’t general purpose yet as I had some proprietary stuff I needed to manage. If anyone is interested I can clean it up and post it.
          • 1783
          • 23 Posts
          Hi, If you can post the code that you used to add filtering option for user list would be great! Can this be also used for public users list?
          Thanks!
            • 22827
            • 129 Posts
            Here is the call:

            [!wlpe_wrapper? &filters=`username,zip,lastname,webgroup,email`!]
            


            Here is the wrapper. Note the "commonFields" parts of it are because wherever I use wlpe, I use a set of fields that are always the same regardless of the mode I am calling it with. So these are all in a chunk. If you don’t do this, you can strip out that whole section. All the rest of it is hardcoded to my chunknames for wlpe - I never got round to making this more sensible by passing through wlpe parameters from the wrapper call. You should be able to see how the userslist filter works.

            <?php
            global $modx;
            
            // Variables
            
            $paramArray = array(); // Array to hold chunk placeholders
            
            
            // Get Common fields chunk and decompose to array
            
            $commonFields = $modx->getChunk("wplCommonFields");
            
            // Remove first ampersand and backticks in preparation for split:
            
            $commonFields = preg_replace("/\&/",'',$commonFields,1);
            $commonFields = str_replace('`','',$commonFields);
            
            // First split on ampersand
            
            $array = split('&',$commonFields);
            
            $cfArray = array();
            
            // Now split into key/value based on equals:
            
            foreach($array as $param)
            {
              list($key,$value) = split('=',trim($param));
              $cfArray = array_merge($cfArray,array($key => $value));
            }
            
            // Process parameters
            // Filters:
            $formChunk = isset($tplForm) ? $tplForm : "tplAdminForm";
            $filterarray = isset($filters) ? split(",",$filters) : array();
            
            foreach($filterarray as $filter)
            {
              if(isset($_REQUEST[$filter]) && $_REQUEST[$filter] != "")
              {
                $userListFilter .= $filter."(".$_REQUEST[$filter]."),";
                $paramArray = array_merge($paramArray,array("filter.".$filter => $_REQUEST[$filter]));
              }
            }
            $userListFilter = chop($userListFilter,',');
            $usersList = "Customers:default:default:username:ASC:".$userListFilter;
            
            print "Users list: ".$usersList;
            
            $wlpe_array = array_merge( array("type" => "manager", "notifyTpl" => "wplNotifyProfile", "manageTpl" => "wplManage" , "manageOuterTpl" => "wplManageOuter", "manageProfileTpl" => "wplManageProfile", "paging" => "20"), $cfArray, array("usersList" => $usersList));
            
            $formChunk = $modx->parseChunk($formChunk,$paramArray,'[+','+]');
            
            return $formChunk.$modx->runSnippet("WebLoginPE",$wlpe_array);
            ?>
            
              • 1783
              • 23 Posts
              Thank you so much for quick reply!

              Can you explain some bits in the code, which ones I need to change?
              for example, What is : Customers? Is it table name, or field name?

              Thanks!
                • 22827
                • 129 Posts
                Actually, "Customers" is just an identifier I think, it doesn’t get used anywhere.

                So the wlpe call passes through a list of "filters":

                  [!wlpe_wrapper? &filters=`username,zip,lastname,webgroup,email`!]
                


                This list tells the wrapper to look for $_REQUEST variables with the same name, and the contents of those variables will contain the filters:


                $filterarray = isset($filters) ? split(",",$filters) : array();
                
                foreach($filterarray as $filter)
                {
                  if(isset($_REQUEST[$filter]) && $_REQUEST[$filter] != "")
                  {
                    $userListFilter .= $filter."(".$_REQUEST[$filter]."),";
                
                  }
                }
                


                So the filters list looks like "username, zip", which gets converted to an array, then we iterate the array and get the contents of the filter. So we are looking for

                $_REQUEST[username]
                $_REQUEST[zip]

                Lets say that username=’paul’ and zip=’doodaa’, so the outcome of this loop would be:

                $usersList = ’username(paul),zip(doodaa)’

                This is then passed to the webloginpe call as:

                WebLoginPE? usersList=`$usersList`

                Or when called from the snippet below it is effectively:

                $modx->runSnippet("WebLoginPE",array("usersList" => $usersList);

                Then you can see the format of the usersList parameter in the webloginpe instructions:


                http://sottwell.com/assets/snippets/webloginpe/docs/parameters.html