You are here

nat_views.inc in Node Auto Term [NAT] 5

File

includes/nat_views.inc
View source
<?php

function nat_views_tables() {
  $tables['nat'] = array(
    'name' => 'nat',
    'provider' => 'internal',
    'join' => array(
      'type' => 'left',
      'left' => array(
        'table' => 'term_node',
        'field' => 'tid',
      ),
      'right' => array(
        'field' => 'tid',
      ),
    ),
    'filters' => array(
      'nat_assigned_term' => array(
        'name' => t('NAT: Assigned Term'),
        'field' => 'nid',
        'operator' => array(
          '=' => t('Equals'),
        ),
        'help' => t('This allows you to filter nodes based on term assigned from node.'),
      ),
    ),
  );
  return $tables;
}
function nat_views_arguments() {
  $arguments = array(
    'nat_assigned_term' => array(
      'name' => t('NAT: Assigned Term'),
      'handler' => 'nat_views_handler_arg_nid',
      'help' => t('Filter by the node\'s term assigned with NAT.'),
    ),
  );
  return $arguments;
}
function nat_views_handler_arg_nid($op, &$query, $argtype, $arg = '') {
  switch ($op) {
    case 'summary':
      $query
        ->add_table('nat', true);
      $query
        ->add_field('nid', 'nat');
      $query
        ->add_field('tid', 'nat');
      $fieldinfo['field'] = "nat.nid";
      return $fieldinfo;
    case 'sort':

      // do nothing here.
      break;
    case 'filter':
      $nid = intval($arg);
      $query
        ->add_table('nat', true);
      $query
        ->add_where("nat.nid = {$nid}");
      break;
    case 'link':

      // do nothing here
      break;
    case 'title':

      // do nothing here
      break;
  }
}