home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (views_handler_filter_node_access.inc)

This example Drupal source code file (views_handler_filter_node_access.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, as, extends, foreach, function, gids, grants, grants_sql, if, implode, nodes, php, realm, return

The views_handler_filter_node_access.inc Drupal example source code

<?php
// $Id: views_handler_filter_node_access.inc,v 1.2 2009/09/15 22:08:42 merlinofchaos Exp $
/**
 * Filter by node_access records.
 */
class views_handler_filter_node_access extends views_handler_filter {
  function admin_summary() { }
  function operator_form() { }
  function can_expose() {
    return FALSE;
  }

  /**
   * See _node_access_where_sql() for a non-views query based implementation.
   */
  function query() {
    if (!user_access('administer nodes')) {
      $table = $this->ensure_my_table();
      $grants = array();
      foreach (node_access_grants('view') as $realm => $gids) {
        foreach ($gids as $gid) {
          $grants[] = "($table.gid = $gid AND $table.realm = '$realm')";
        }
      }
      $grants_sql = '';
      if (count($grants)) {
        $grants_sql = implode(' OR ', $grants);
      }
      $this->query->add_where('AND', $grants_sql);
      $this->query->add_where('AND', "$table.grant_view >= 1");
    }
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_handler_filter_node_access.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.