Only show public groups for non logged in users

georg yurij Posted in Beginning Developers 2 years ago

I use Unloggedin Menu, how i can change the search query "/search?type=groups" in that way, that not logged in users become only public groups displayed and that the query "/search?type=groups&q=private" also show no results for non logged in users?

Replies
Indonesian Arsalan Shah Replied 2 years ago

.

<?php
    function groups_search_handler($hook, $type, $return, $params) {
            $groups = new OssnGroup();
            if(ossn_isLoggedin()) {
                    $data  = $groups->searchGroups($params['q']);
                    $count = $groups->searchGroups($params['q'], array(
                            'count' => true,
                    ));
            } else {
                    $data = $groups->searchGroups($params['q'], array(
                            'entities_pairs' => array(
                                    array(
                                            'name'  => 'membership',
                                            'value' => OSSN_PUBLIC,
                                    ),
                            ),
                    ));
                    $count = $groups->searchGroups($params['q'], array(
                            'count'          => true,
                            'entities_pairs' => array(
                                    array(
                                            'name'  => 'membership',
                                            'value' => OSSN_PUBLIC,
                                    ),
                            ),
                    ));
            }

            $group['groups'] = $data;
            $search          = ossn_plugin_view('groups/search/view', $group);
            $search .= ossn_view_pagination($count);
            if(empty($data)) {
                    return ossn_print('ossn:search:no:result');
            }
            return $search;
    }

I beleive like this you need to change handler.