We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi guys,

    I now have a membership system working well (using Login extra) on a site I am building out - last step is to create some way of allowing the users of the MODx manager to search the users(members) based on a wide set of criteria.

    The user(member) profile includes many extended fields and I need to be able to search all the users and return back relevant users that match the search criteria.

    As we all know - the search function in the Manager does not interrogate the extended fields as they are within a JSON string as I understand it...

    The search functionality I would like is to include a freeform text input (which would search ALL user fields (standard and extended) and list back the users which match and also a few <select> dropdown menus to allow searching of a few specific extended fields (e.g. location, specialty 1, specialty 2) - again upon setting of these <select> options and hitting the search button - the results should return the users which match the searched criteria.

    This searching could either happen in the Manager, or in a page which has AdminOnly access - I am not fussed... think maybe easier to create outside of the Manager maybe?

    So...

    As I see it from doing some research, I have 2 main options:

    1) Find a way to create a search function to search these JSON strings for each user and return the relevant search results. I already have a AdminOnly page fetching and display all the fields (standard and extended) for each user (using pdoUsers) - Can I use simpleSearch / AdvancedSearch to query this data and return results?. I appreciate this might not be the ideal way to do it... but I have spent ages getting the user login / register / update system working and am loathed to start again with it to employ another system of collecting the extended fields info...

    2) Use Bob's ClassExtended to extend ModUser (http://bobsguides.com/blog.html/2014/05/27/why-extend-moduser/). I really have no idea how to implement this to be honest, is it a large job to migrate my current working system to use ClassExtender? How does it work with the standard Login extra?

    I would favor option 1 due to having the member registration process now working...

    Any insight guys? Please bear in mind my PHP is weak at best... so really could do with some hand-holding here! No extended the user to search it before...

    P.S. Using pdoUsers: I can return specific users based on a single search/query criteria using the code below:

    [[!pdoUsers?
        &groups=`EXAMPLE_GROUP`
        &tpl=`ExampleTpl`
        &sortdir=`asc`
        &limit=`100000`
        &sortby=`id`   
        &where=`{"modUserProfile.extended:LIKE":"%\"examplelocation_01\":\"Bristol\"%"}`
        &showLog=`1`
    ]]
    


    But, Can I make it so that the "where" element of the code, includes all the user fields, extended and not? If so, then I have half a solution working... Any ideas on hooking this theory up to a search function?

    Cheers,

    dubbs.

    This question has been answered by dubbs. See the first response.

    [ed. note: dubbs last edited this post 8 years, 6 months ago.]
      • 3749
      • 24,544 Posts
      I assume that the search criteria are flexible and come from a form. I'm not sure, but I think you'd need a custom snippet to create a much more complex &where statement for pdoResources. It would not be trivial, but complex searches rarely are. It's pretty unlikely that you could do this without a custom snippet, unless the number and form of the possible search configurations is relatively small.

      To clarify, what I'm suggesting is this:

      [[!pdoUsers?
          &groups=`MEMBERS`
          &tpl=`MembersListItemTpl`
          &sortdir=`asc`
          &limit=`100000`
          &sortby=`id`   
          &where=`[[!SearchSnippet`]]`
          &showLog=`1`
      ]]


      The snippet would build and return the custom JSON string for the &where clause based on the data in the $_POST array.

      Offhand, I don't think that ClassExtender would make this much easier. It could speed up the search somewhat, but I'm not sure how much.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 8168
        • 1,118 Posts
        Thanks Bob. Any thoughts on code for the custom snippet? I have about 20 extended mod user fields to search through. Hope you are able to help here as I have hit my PHP ability limits! Appreciate your thoughts here.
          • 3749
          • 24,544 Posts
          If the search will always check the same fields, you may be able to get by without the snippet. See my answer in the other thread.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 8168
            • 1,118 Posts
            Thanks Bob, the search form I was thinking of having would include:

            Freeform text input - so search all standard and extended fields for the value entered in the input box, then additionally
            x3 <select> menus which would each search a defined set of extended fields.

            So upon hit of the SEARCH button on the form, the snippet would need to query the pdoUsers as above.... Possible? Any clues on how???

            I guess the snippet needs to create all the various &Where arguments and pass them to the pdoUsers code call to make the function work....

            The &where code below, works to query all the extended fields for the term 'london' - but how can I include the standard userfields as well?

            &where=`{
               "modUserProfile.extended:LIKE":"%\"london\"%"
            }`
            


            Thanks Bob wink


            So thinking is...

            Here is a simplified version of the search form:

            <form>
            
            <input type="text" name="value01" id="value01" />
            
            <select id="location" name="location">
            <option value="">Please select a working region…</option>
            <option value="Region 01">Region 01</option>
            <option value="Region 02">Region 02</option>
            <option value="Region 03">Region 03</option>
            </select>
            
            <select id="TeachingAge" name="TeachingAge">
            <option value="">Please select a schooling phase…</option>
            <option value="Schooling phase 01">Schooling phase 01</option>
            <option value="Schooling phase 02">Schooling phase 02</option>
            <option value="Schooling phase 03">Schooling phase 03</option>
            </select>
            
            <select id="SubjectsTaught" name="SubjectsTaught">
            <option value="">Please select a subject offered…</option>
            <option value="Subject 01">Subject 01</option>
            <option value="Subject 02">Subject 02</option>
            <option value="Subject 03">Subject 03</option>
            </select>
            
            <input type="submit" />
            
            </form>
            


            And here is the logic for the snippet to be called on the pdoUsers &where element... So this is the bit I need some help with, how can I get that working in PHP to allow all of these functions to be processed based on the users input into the search form....

            //search all standard and extended fields based on freeform text input:
            //note - need code to include search of standard fields too!
            &where=`{
               "modUserProfile.extended:LIKE":"%\"value01\"%"
            }`
            
            //search work region fields (all) based on <select> option
            &where=`[
            {"modUserProfile.extended:LIKE":"%\"location_01\":\"location\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"location_02\":\"location\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"location_03\":\"location\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"location_04\":\"location\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"location_05\":\"location\"%"}
            ]`
            
            //search schooling phase fields (all) based on <select> option
            &where=`[
            {"modUserProfile.extended:LIKE":"%\"TeachingAge_01\":\"TeachingAge\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"TeachingAge_02\":\"TeachingAge\"%"}
            ]`
            
            //search subjects offered fields (all) based on <select> option
            &where=`[
            {"modUserProfile.extended:LIKE":"%\"SubjectsTaught_01\":\"SubjectsTaught\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"SubjectsTaught_02\":\"SubjectsTaught\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"SubjectsTaught_03\":\"SubjectsTaught\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"SubjectsTaught_04\":\"SubjectsTaught\"%"},
            {"OR:modUserProfile.extended:LIKE":"%\"SubjectsTaught_05\":\"SubjectsTaught\"%"}
            ]`
            
            [ed. note: dubbs last edited this post 8 years, 6 months ago.]
              • 3749
              • 24,544 Posts
              Are those four separate searches, or do you need to AND all four for a single search?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 8168
                • 1,118 Posts
                They could all happen at once in theory. Or the search could just be one of those &where lines. Depends on user. Need to allow for ability for them to all occur at once though yes.
                  • 3749
                  • 24,544 Posts
                  If they all occurred together, would there be one result or multiple results? IOW, would there be one search with multiple criteria that could generate a single report, or would there be one search for each section that produced several independent reports?


                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 8168
                    • 1,118 Posts
                    Possibly one, likely more. Depends on the search criteria the users searched with...
                      • 8168
                      • 1,118 Posts
                      E.g one could put London in free form text input, then Select maths from subjects select menu and primary from schooling phase and hit search, then showing all members with any reference to London in any field, with members who are tagged maths and primary. Make sense? Hope so....