Skip to content

Commit

Permalink
changed: activity filter in group river widget (now more advanced)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Nov 30, 2011
1 parent afa7172 commit cdc7e3e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 32 deletions.
5 changes: 5 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ToDo
====================
- group listing
- latest activity in my groups
- my groups (and remove menu item)
- group icon cron tool
- group invite
Expand All @@ -57,11 +58,15 @@ ToDo
- invitation report
- per user what happend
- better description of options
- group widgets
- group listing on popular
- closed group, but show widgets
====================
Version History
====================
x.x:
- changed: activity filter in group river widget (now more advanced)
- changed: group status (open/closed) CSS
1.8 (2011-11-11):
Expand Down
50 changes: 27 additions & 23 deletions views/default/widgets/group_river_widget/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$widget = $vars["entity"];

// filter activity
// get filter options
$filter_contents = array();
$filter_contents['all'] = 'all';
if (!empty($vars['config']->registered_entities)) {
foreach ($vars['config']->registered_entities as $type => $ar) {
if($type == "user"){
Expand All @@ -26,6 +26,28 @@
}
}
}

// build selector
$activity_filter = $widget->getMetadata("activity_filter");
if(empty($activity_filter)){
// fallback to old situation
$activity_filter = $widget->activity_filter;
}

if(!empty($activity_filter) && !is_array($activity_filter)){
$activity_filter = array($activity_filter);
} elseif(empty($activity_filter)){
$activity_filter = array();
}

$filter_selector = elgg_view("input/hidden", array("internalname" => "params[activity_filter][]", "value" => "")); // needed to be able to store no selection
foreach($filter_contents as $label => $content){
if(in_array($content, $activity_filter)){
$filter_selector .= "<input type='checkbox' name='params[activity_filter][]' checked='checked' value='" . $content . "'>" . elgg_echo($label) . "<br />";
} else {
$filter_selector .= "<input type='checkbox' name='params[activity_filter][]' value='" . $content . "'>" . elgg_echo($label) . "<br />";
}
}

if($widget->context != "groups"){
//the user of the widget
Expand Down Expand Up @@ -72,17 +94,8 @@
echo "</div>";

echo "<div>";
echo elgg_echo("filter");
echo "<select name='params[activity_filter]'>";
foreach($filter_contents as $label => $content) {
if (($widget->activity_filter == $content)) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option value='" . $content . "' " . $selected . ">" . elgg_echo($label) . "</option>";
}
echo "</select>";
echo elgg_echo("filter") . "<br />";
echo $filter_selector;
echo "</div>";

echo "<div>";
Expand All @@ -108,16 +121,7 @@
echo "</div>";

echo "<div>";
echo elgg_echo("filter");
echo "<select name='params[activity_filter]'>";
foreach($filter_contents as $label => $content) {
if (($widget->activity_filter == $content)) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option value='" . $content . "' " . $selected . ">" . elgg_echo($label) . "</option>";
}
echo "</select>";
echo elgg_echo("filter") . "<br />";
echo $filter_selector;
echo "</div>";
}
42 changes: 33 additions & 9 deletions views/default/widgets/group_river_widget/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@
unset($group_guid[$key]);
}

$filter = $widget->activity_filter;
if(empty($filter) || ($filter == "all")){
$filter = "";
// get activity filter
$activity_filter = $widget->getMetadata("activity_filter");
if(empty($activity_filter)){
// fallback to old situation
$activity_filter = $widget->activity_filter;
if($activity_filter == "all"){
$activity_filter = array();
}
}

if(!empty($activity_filter) && !is_array($activity_filter)){
$activity_filter = array($activity_filter);
} elseif(empty($activity_filter)){
$activity_filter = array();
}

if(!empty($group_guid)){
Expand All @@ -43,17 +54,30 @@
$sql .= " INNER JOIN {$CONFIG->dbprefix}entities AS entities1 ON {$CONFIG->dbprefix}river.object_guid = entities1.guid";
$sql .= " WHERE (entities1.container_guid in (" . implode(",", $group_guid) . ")";
$sql .= " OR {$CONFIG->dbprefix}river.object_guid IN (" . implode(",", $group_guid) . "))";
if(!empty($filter)){
list($type, $subtype) = explode(",", $filter);

if(!empty($activity_filter)){
$filter_wheres = array();

if(!empty($type)){
$sql .= " AND {$CONFIG->dbprefix}river.type = '" . sanitise_string($type) . "'";
foreach($activity_filter as $filter){
list($type, $subtype) = explode(",", $filter);

if(!empty($type)){
$filter_where = " ({$CONFIG->dbprefix}river.type = '" . sanitise_string($type) . "'";

if(!empty($subtype)){
$filter_where .= " AND {$CONFIG->dbprefix}river.subtype = '" . sanitise_string($subtype) . "'";
}

$filter_where .= ")";
$filter_wheres[] = $filter_where;
}
}

if(!empty($subtype)){
$sql .= " AND {$CONFIG->dbprefix}river.subtype = '" . sanitise_string($subtype) . "'";
if(!empty($filter_wheres)){
$sql .= " AND (" . implode(" OR ", $filter_wheres) . ")";
}
}

$sql .= " AND " . get_access_sql_suffix("entities1");
$sql .= " ORDER BY {$CONFIG->dbprefix}river.posted DESC";
$sql .= " LIMIT {$offset},{$limit}";
Expand Down

0 comments on commit cdc7e3e

Please sign in to comment.