Offer a views filter

telex4 - March 30, 2006 - 00:57
Project:Clipper
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Not full integration with views, but one feature I'd dearly like: expose a filter to views that allows admins to filter according to how many parents a node has, or perhaps even just whether or not nodes have a parent.

This would allow me to build a table only with "top-level" nodes for a tasks list.

With a bit of guidance I could probably hack this up myself.

#1

telex4 - March 30, 2006 - 12:00
Status:active» needs work

OK, here's a first stab. I get an odd error, though:

user warning: Unknown table 'relations' in where clause query: SELECT count(DISTINCT(node.nid)) FROM node node LEFT JOIN signup_log signup_log ON node.nid = signup_log.nid WHERE (node.type IN ('content-task')) AND (relations.left_id = node.nid) in /var/www/spreadkde_dev/drupal-cvs/includes/database.mysql.inc on line 120.

Even though I've used ensure_table it doesn't appear in the query. Not too sure what's going on there... here's the code:

function clipper_views_tables() {
  $tables['relations'] = array(
    "filters" => array(
      "left_id" => array(
        "name" => "Clipper: Node is a parent",
        "operator" => array('is a'),
        "list" => array("parent"),
        "handler" => "views_handler_filter_children",
        "value-type" => "array",
        "help" => t("This filter allows you to only show nodes that are clipper parents")
      ),
    ),
  );
  return $tables;
}

function views_handler_filter_children($op, $filter, $filterinfo, &$query) {
  $query->ensure_table("relations");
  $query->add_where("relations.left_id = node.nid");
}

#2

Bèr Kessels - March 31, 2006 - 08:20

can you upload the patch, please?

#3

telex4 - March 31, 2006 - 14:42

Here you go.

AttachmentSize
clipper_views.patch.txt 864 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.