Skip to content

Commit

Permalink
fixed #28 added option for index widget to list groups based on
Browse files Browse the repository at this point in the history
popularity
  • Loading branch information
jdalsem committed Oct 25, 2013
1 parent e6315c0 commit b4c1277
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
4 changes: 2 additions & 2 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@
'widgets:group_forum_topics:description' => "Show the latest discussions",

// index_groups
'widgets:index_groups:description' => "Show the latest groups on your community",
'widgets:index_groups:description' => "List groups from your community",
'widgets:index_groups:show_members' => "Show members count",
'widgets:index_groups:featured' => "Show only featured groups",
'widgets:index_groups:apply_sorting' => "Apply sorting if available",
'widgets:index_groups:sorting' => "How to sort the groups",

'widgets:index_groups:filter:field' => "Filter groups based on group field",
'widgets:index_groups:filter:value' => "with value",
Expand Down
2 changes: 1 addition & 1 deletion languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
'widgets:discussion:settings:group_only' => 'Toon alleen discussies uit je eigen groepen',
'widgets:discussion:more' => 'Bekijk meer discussies',
'widgets:discussion:description' => 'Toont de laatste discussies',
'widgets:index_groups:description' => 'Toon de laatste groepen uit de community',
'widgets:index_groups:description' => 'Toont groepen uit de community',
'widgets:index_groups:show_members' => 'Toon aantal groepsleden',
'widgets:index_groups:featured' => 'Toon enkel aangeraden groepen',
'widgets:group_news:settings:group_icon_size' => 'Groep icoon grootte',
Expand Down
41 changes: 29 additions & 12 deletions views/default/widgets/index_groups/content.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

$widget = $vars["entity"];

Expand Down Expand Up @@ -47,18 +47,35 @@
}
}

// check if groups should respect ordering
if($widget->apply_sorting == "yes"){
$dbprefix = elgg_get_config("dbprefix");
$order_id = add_metastring("order");

$options["selects"] = array(
"IFNULL((SELECT order_ms.string as order_val FROM " . $dbprefix . "metadata mo JOIN " . $dbprefix . "metastrings order_ms ON mo.value_id = order_ms.id WHERE e.guid = mo.entity_guid AND mo.name_id = " . $order_id . "), 99999) AS order_val"
);

$options["order_by"] = "CAST(order_val AS SIGNED) ASC, e.time_created DESC";
$sorting_value = $widget->sorting;
if (empty($sorting_value) && ($widget->apply_sorting == "yes")) {
$sorting_value = "ordered";
}

$getter = "elgg_get_entities_from_metadata";
// check if groups should respect a specific order
switch ($sorting_value) {
case "ordered":
$dbprefix = elgg_get_config("dbprefix");
$order_id = add_metastring("order");

$options["selects"] = array(
"IFNULL((SELECT order_ms.string as order_val FROM " . $dbprefix . "metadata mo JOIN " . $dbprefix . "metastrings order_ms ON mo.value_id = order_ms.id WHERE e.guid = mo.entity_guid AND mo.name_id = " . $order_id . "), 99999) AS order_val"
);

$options["order_by"] = "CAST(order_val AS SIGNED) ASC, e.time_created DESC";
break;
case "popular":
$getter = "elgg_get_entities_from_relationship_count";

$options["relationship"] = "member";
$options["inverse_relationship"] = false;
break;
default:
// just use default time created sorting
break;
}

// show group member count
if($widget->show_members == "yes"){
$show_members = true;
Expand All @@ -68,7 +85,7 @@
}

// list groups
if($groups = elgg_list_entities_from_metadata($options)){
if($groups = elgg_list_entities($options, $getter)){
echo $groups;
} else {
echo elgg_echo("groups:none");
Expand Down
25 changes: 18 additions & 7 deletions views/default/widgets/index_groups/edit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

$widget = $vars["entity"];

Expand Down Expand Up @@ -28,28 +28,39 @@
}
}

$sorting_options = array(
"newest" => elgg_echo("groups:newest"),
"popular" => elgg_echo("groups:popular"),
"ordered" => elgg_echo("group_tools:groups:sorting:ordered")
);

$sorting_value = $widget->sorting;
if (empty($sorting_value) && ($widget->apply_sorting == "yes")) {
$sorting_value = "ordered";
}

?>
<div>
<?php echo elgg_echo("widget:numbertodisplay"); ?><br />
<?php echo elgg_view("input/text", array("name" => "params[group_count]", "value" => $count, "size" => "4", "maxlength" => "4")); ?>
</div>

<div>
<?php
<?php
echo elgg_echo("widgets:index_groups:show_members");
echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[show_members]", "options_values" => $noyes_options, "value" => $widget->show_members));
?>
</div>

<div>
<?php
<?php
echo elgg_echo("widgets:index_groups:featured");
echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[featured]", "options_values" => $noyes_options, "value" => $widget->featured));
?>
</div>
<?php if(!empty($tag_fields)) { ?>
<div>
<?php
<?php
$tag_fields = array_reverse($tag_fields);
$tag_fields[""] = elgg_echo("widgets:index_groups:filter:no_filter");
$tag_fields = array_reverse($tag_fields);
Expand All @@ -65,8 +76,8 @@
</div>
<?php } ?>
<div>
<?php
echo elgg_echo("widgets:index_groups:apply_sorting");
echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[apply_sorting]", "options_values" => $noyes_options, "value" => $widget->apply_sorting));
<?php
echo elgg_echo("widgets:index_groups:sorting");
echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[sorting]", "options_values" => $sorting_options, "value" => $sorting_value));
?>
</div>

0 comments on commit b4c1277

Please sign in to comment.