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,

    In SimpleSearch (v1.9.0-pl on Revo 2.3.1) Can one tell the search function to ignore the contents of resources who fall into a resource group called "Members" - No mention of this in the rtfm site - but surely possible?

    Any ideas? a postHook maybe?

    Cheers


    dubbs.
      • 39767
      • 6 Posts
      Met the same problem today... me too, didn't found any solution. So far I mentioned every single resource...
        • 4172
        • 5,888 Posts
        this is untested, but something like that could work:

        snippet mySimpleSearch:
        <?php
        
        $group_ids = explode(',', $modx->getOption('group_ids', $scriptProperties, 0));
        $mode = $modx->getOption('mode', $scriptProperties, 'show'); //show or hide resources in given resource-groups
        
        $c = $modx->newQuery('modResourceGroupResource');
        $c->where(array('document_group:IN' => $group_ids));
        if ($collection = $modx->getCollection('modResourceGroupResource')) {
            foreach ($collection as $object) {
                $ids[] = $object->get('document');
            }
        }
        
        if ($mode == 'hide') {
            $c = $modx->newQuery('modResource');
            $c->select($modx->getSelectColumns('modResource', 'modResource', array('id')));
            $rows = array();
            $resources = array();
            if ($c->stmt->execute()) {
                if ($results = $c->stmt->fetchAll(PDO::FETCH_ASSOC)) {
                    $rows = $results;
                }
            }
            foreach ($rows as $row){
                if (isset($row['id'])){
                    $resources[] =  $row['id'];
                }
            }
            $scriptProperties['ids'] = implode(',', $resources);
            $scriptProperties['exclude'] = implode(',', $ids);
        
        } else {
            $scriptProperties['ids'] = implode(',', $ids);
        }
        
        return $modx->runSnippet('SimpleSearch', $scriptProperties);
        
        


        call it as you would call simpleSearch, but with additional properties, like

        [[!mySimpleSearch?
        &group_ids=`3,4,5`
        &idType=`documents` 
        &mode=`hide`
        &otherproperties...
        ]]


        or if you want to show only resouces in given groups:

        [[!mySimpleSearch?
        &group_ids=`3,4,5`
        &idType=`documents` 
        &otherproperties...
        ]]



          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 8168
          • 1,118 Posts
          Thanks Bruno, When I try and create and save this new snippet MODx will not save it... Any ideas why? It shows the save progress bar, then looks like it has saved, but never shows the Snippet saved message and if you look in the LHS site tree - it is not shown there...
            • 39767
            • 6 Posts
            Perhaps you wrote the closing php tag (this one: ?>). For snippets you just have to put the opening tag and let it open at the end.
              • 8168
              • 1,118 Posts
              Quote from: wildsue at Nov 27, 2014, 08:11 AM
              Perhaps you wrote the closing php tag (this one: ?>). For snippets you just have to put the opening tag and let it open at the end.

              No - I didn't do that - think there must be a phrase in the snippet which my host objects too... not the first time this has happened! Is this new approach working for you?
                • 8168
                • 1,118 Posts
                Hi Bruno - this script gives a server 500 php error when trying to use the snippet - any chance you could have a look at it and see what the issue might be... Afraid PHP is not something I understand well enough to pick out the scripting bug - I'd love to get a site search with restrictions working ASAP // thanks
                  • 50646
                  • 2 Posts
                  I know that's not what you asked for, but you could also uncheck the "searchable" setting in the resources that you do not want to see in the results.
                    • 11055 ☆ A M B ☆
                    • 3,112 Posts
                    This is an old thread, but I just want to throw my solution here, because google gets this first.

                    Let say this is a new snippet called "fixedSimpleSearch", that will wrap SimpleSearch.
                    <?php
                    
                    $memberIds = $modx->getOption('memberIds', $scriptProperties);
                    if (empty($memberIds)) {
                        $memberIds = array();
                    } else {
                        $memberIds = array_map('trim', @explode(',', $memberIds));
                    }
                    $ids = $modx->getOption('ids', $scriptProperties);
                    $isMember = $modx->user->isMember('Administrator', 'Editor', 'Member');
                    if (!empty($ids)) {
                        $ids = array_map('trim', @explode(',', $ids));
                        if ($isMember) {
                            $ids = array_merge($ids, $memberIds);
                        }
                        $scriptProperties['ids'] = @implode(',', $ids);
                    }
                    
                    $output = $modx->runSnippet('SimpleSearch', $scriptProperties);
                    
                    return $output;


                    Your snippet call would be just the same, because this snippet passes over the $scriptProperties to SimpleSearch

                    [[!fixedSimpleSearch?
                    &idType=`parents`
                    &ids=`1,2,3,4,5`
                    &memberIds=`6,7,8,9`
                    &highlightTag=`strong`
                    &pageLimit=`3`
                    &tpl=`SimpleSearch_tpl`
                    &containerTpl=`SimpleSearch_containerTpl`
                    &pagingSeparator=``
                    &pageTpl=`SimpleSearch_pageTpl`
                    &currentPageTpl=`SimpleSearch_currentPageTpl`
                    ]]
                    


                    The new snippet appends the memberIds (resources for member) when the user is logged in.
                    memberIds IS NOT SimpleSearch's property.

                    Hope you can get the idea.
                      Rico
                      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                      MODx is great, but knowing how to use it well makes it perfect!

                      www.virtudraft.com

                      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                      Maintainter/contributor of Babel

                      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.