Group by List needs to be added
nick_wayne - January 18, 2009 - 00:37
| Project: | Views 'Group-By' Pack |
| Version: | 5.x-1.3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Group by List needs to be added in this if this is to become any useful. Without that this is totally useless and waste of time.

#1
Group by List View -- Resolved.
Hi all ,
I have figured out the way to Group by properly in List view. This method will group nicely and will eliminate duplicates. Here are the steps.
1. Follow the instructions on the post below to add basic Group By List functionality.
http://drupal.org/node/257343#comment-840401
This will produce duplicates in the list view for the terms that are being used on more than on node, which is how the taxonomy is intended to be used.
To fix that replace the code for theme_taxonomygroup_group_list function in taxonomygroup.inc file with the code below.
This will :-
1. Remove the duplicates in Term Names in List view
2. Remove the Headings which you probably do not need anyway in List view.
Enjoy.
Nick.
www.toolerp.com
TooLERP -- Small Business ERP Accounting Software
function theme_taxonomygroup_group_list($view, $nodes, $type) {
drupal_add_css(drupal_get_path('module', 'views_group_pack').'/taxonomygroup.css');
if (isset($view->sort[0]['field'])) {
$sort_field = $view->sort[0]['field'];
} // if it's got a sort field
if ($sort_field != 'term_data.weight') {
drupal_set_message(t("The view must be sorted first by a 'taxonomy term' field, in order to be Grouped By Taxonomy Term."), 'error');
return theme('views_view_teasers', $view, $nodes, $type);
} // if the sort field isn't set
$by_taxonomy = array();
foreach ($nodes as $proto_node) {
$node = node_load($proto_node->nid);
$val = array_values($node->taxonomy);
$term = $val[0]->name;
$by_taxonomy[$term][] = $node;
} // foreach node
return theme("taxonomygroup_taxonomylist", $view, $by_taxonomy, $type);
}
function theme_taxonomygroup_taxonomylist($view, $by_taxonomy, $type) {
$output = "";
foreach ($by_taxonomy as $term => $termlist) {
$output .= theme('taxonomygroup_listterm', $termlist, $term, $view);
} // foreach term
$output .= "";
return $output;
}
function theme_taxonomygroup_listterm($termlist, $term, $view) {
$output = "";
//$output .= "{$term}";
$output .= "";
$fields = _views_get_fields();
foreach ($termlist as $node) {
$item = '';
foreach ($view->field as $field) {
if (!($field_prv == $field['queryname'])){
if (!isset($fields[$field['id']]['visible']) && $fields[$field['id']]['visible'] !== FALSE) {
if ($field['label']) {
$item .= "" . $field['label'] . "";
}
$item .= "" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "";
}
}//if field_prv
$field_prv = $field['queryname'];
}
if ($item){
$items[] = "name) ."'>$item\n"; // l($node->title, "node/$node->nid");
}
}
if ($items) {
$output .= theme('item_list', $items);
}
$output .= "";
return $output;
}
#2
This is fixed using the following method
http://drupal.org/node/360411#comment-1207756
It will be great if the module owners include the code in the module.
Nick
www.toolerp.com
#3
Automatically closed -- issue fixed for 2 weeks with no activity.
#4
It's buggy : we can display corrdctly the node title for example.
The reason is that the nodes supplied in
views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view)thus the function views_handler_fieldnodelink is called with the $value argument (the 3rd one, see the source for that) which is empty.
As result it is return just a link like
<a href="/node/2"></a>I haven't found to solve that yet.