In which hook i can filter nodes to display?

Guide - June 30, 2009 - 15:01

Which hook i should use to hide nodes specific parameter?

People are going to need more

nevets - June 30, 2009 - 15:13

People are going to need more context to provide help.

"In which hook i can filter nodes to display" makes it sound like an access/permission issue.

And what is a "nodes specific parameter"?

The bottom line, exactly what do you want to filter and when/where?

I've added new parameter to

Guide - June 30, 2009 - 15:29

I've added new parameter to node table "private" and created new table with list of "friends"... i need to show only nodes with parameter "private" = 0 for users which are is not in "friend" table

You might want to check out

nevets - June 30, 2009 - 18:01

You might want to check out the User Relationships and Friendlist modules.

Side note: It is a bad practice to modify core tables (it can make upgrading more difficult).

Thanks

Guide - June 30, 2009 - 20:45

Thanks... i'm trying to make some modules :)
So i've found how to use access hooks:

<?php
/**
* Implementation of hook_node_grants().
*/
function offer_node_grants($account, $op) {
 
// module only controls view operations
 
if ($op == 'view') {
   
$partners = _partners_get_partners($account->uid);
   
$grants['user_partner'][] = $account->uid;
    if (!empty(
$partners)) {
     
$grants['user_partner'] = array_keys($partners);
    }
    return
$grants;
  }
}

/**
* Implementation of hook_node_access_records().
*/
function offer_node_access_records($node) {
  if (
$node->partners) { // from hook_form_alter
   
return array(
      array(
       
'realm' => 'user_partner',
       
'gid' => $node->uid,
       
'grant_view' => 1,
       
'grant_update' => 0,
       
'grant_delete' => 0,
       
'priority' => 5,
      ),
    );
  }
}

function
_partners_get_partners($uid, $reset = NULL) {
  static
$partners;

  if (!isset(
$partners[$uid]) || $reset) {
   
$result = db_query("SELECT * FROM {partners} WHERE uid = %d OR pid = %d", $uid, $uid);
    while (
$partner = db_fetch_object($result)) {
     
// if the current user is in the uid column
     
if ($partner->uid == $uid) {
       
// load the friend_uid
       
$partners[$uid][$partner->pid] = user_load(array('uid' => $partner->pid));
      }
      else {
// the current user is the friend_uid
        // load the uid column as the friend
       
$partners[$uid][$partner->uid] = user_load(array('uid' => $partner->uid));
      }
    }
  }

  return
$partners[$uid];
}
?>

Thanks for help and sorry for my english :)

 
 

Drupal is a registered trademark of Dries Buytaert.