HACK: modifing the group-tools plugin to display profile_manager field categories in the group listing

I spend some time (total Elgg and php beginner) figuring out how to sort and display groups according to a set metadata group profile field and would like to share it with others as this seems to be a very often asked for feature that isn't yet included in the profile-manager plugin.

For that I hacked/modified the group-tools plugin, as that has the basic framework already in place.

In a very similar fashion the same can be done for member profile fields, a start can be found in this thread ( http://community.elgg.org/discussion/view/1468616/categorizing-members-and-listing-them ), but I might actually make a plugin for that once I have learned to do that (since the Elgg core members plug-in is really simple and needs replacement).

Start of tutorial:

For modified settings view:

Edit file: /group_tools/views/default/plugins/group_tools/settings.php

Under “$listing_options = array(“ add your own custom categories and adjust the language files accordingly.

For example:

$listing_options = array(

"myowncategory" => elgg_echo("group_tools:groups:sorting:myowncategory"),

);

 

This will allow you to choose which sorting categories to display and with on is the default.

 

For modified group tabs view:

Edit file: /group_tools/views/default/groups/group_sort_menu.php

Under “$tabs = array(“ add your own custom categories in a similar fashion as before

For example:

$tabs = array(

    "myowncategory" => array(

     "text" => elgg_echo("group_tools:groups:sorting:myowncategory"),

     "href" => "groups/all?filter=myowncategory",

     "priority" => 900,              //sorting order of the tabs

     ),

);

This will make the different tabs available in the “groups” page.

 

For modified groups page:

Edit file: /group_tools/pages/groups/all.php

Under “switch ($selected_tab) {“  add your own custom sorting code for each custom category.

For example:

switch ($selected_tab) {

     case "myowncategory":

            $group_options["metadata_name_value_pairs"] = array(

                        "name" => "categories",

                        "value" => "myowncategory"

                        );

       brake;

}

 

This will allow displaying only the groups that have a dropdown group profile field (via the profile_manager plugin) called “categories” with the value “myowncategory” selected in the edit group menu.

Registering plug-in hooks to render content:

Finally you need to edit the hooks to allow the content of the new tabs to be rendered.

Edit file: /group_tools/lib/hooks.php

In line 42 add your categories like this:

if(in_array($filter, array("open", "closed", "alpha", "ordered", "myowncategory" )){

 

Setting up our page:

Technically everything should be working now, but in case you haven’t done so already, you need to of course create a group profile field with the profile_manager plug-in. To keep with the example above it would need to be called “categories” and have at least the drop down option to select a option called “myowncategory”.

Last but not least make sure the group-tools settings has the proper checkboxes at your newly created sorting tab and you should be all set up.

Hopefully a less manual way of doing this will be included in the profile_manager plug-in in the future.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking