I have exposed the category, category_node and category_hiearchy tables to views. I'm trying to create a view of parent categories for a particular container, but running into the problem of sub-categories being included on the list.

I wish to write a filter handler for the category_node.nid field which will basically say this:

Include this node only if the node id is equal to category_node.nid AND category_node.cid

Can someone help me do this? My views module api code for exposing the category_node table is included below. Thanks!

  return array(
    'category_node' => array(
      'name' => 'category_node',
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ), // end right array
      ), // end join array

      'fields' => array(
        'cid' => array(
          'name' => t('Category Node: ID'),
          'sortable' => true
         ), // end cid array
        'nid' => array(
          'name' => t('Category Node: Node ID'),
          'sortable' => true
         ), // end nid array
       ), // end fields array

      'filters' => array(
        'cid' => array(
          'name' => t('Category Node: ID'),
          'operator' => 'category_handler_operator_eqto',
          'handler' => 'category_handler_filter_eqto',
          'help' => t('This filter allows categories to be filtered by their IDs.'),
        ), // end cid array
//
// Right now, I'm just using a straight equal to handler
//
        'nid' => array(
          'name' => t('Category Node: Node ID'),
          'operator' => 'views_handler_operator_eqto',
          'handler' => 'category_handler_filter_eqto',
          'help' => t('This filter allows categories to be filtered by their node IDs.'),
        ), // end nid array
	  ), // end filters
    ), // end category_node array

Comments

somebodysysop’s picture

OK, this one I figured out:

function category_handler_filter_nid($op, $filter, $filterinfo, &$query) {
      $query->ensure_table('category_node');
      $query->add_where("category_node.nid = category_node.cid");
}

However, what I really want to do is join the category_node table to the category_hiearchy table in this way:

Let's say that $arg is the value submitted, I want to code my handler to do this:

select from category_hierarchy inner join category_node on category_node.cid = category_hierarchy.cid where category_node.nid = category_node.cid and category_hierarchy.parent = $arg

Can someone show me how this filter is constructed?

jyamada1’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev

I've got a similar issue that I've posted over here: http://drupal.org/node/134680#comment-220645

from the above comment it looks like the $query object used to be passed to filter handlers, but is not any more?

sun’s picture

Status: Active » Closed (won't fix)

Sorry, unfortunately this support request is way too specific. Please have a look at the issue queue - Views maintainers are buried already. You might want to try to get further support at http://drupal.org/support.

somebodysysop’s picture

Support requested nearly 2 years ago. I guess better late than never, eh?