I have created a content type called Details it is the collection of employees detail. And also I have created a Taxonomy terms called manager, employee, lead. Also I have created a field(as Taxonomy reference) for user profile to indicate whether she/he is manager or lead or employee. Now I want to put the restriction based on the user. I have achieve the restriction using my custom module. The codes are below:
function my_module_node_access($node, $op, $account) {
global $user;
$user_obj = user_load($account->uid);
if (isset($node->type) && ($node->type == 'details') && ($op == 'view')) {
if (($user->uid == 0) || ($user_obj->field_user_company['und'][0]['tid'] != $node->field_company['und'][0]['tid'])){
return NODE_ACCESS_DENY;
}
}
return NODE_ACCESS_IGNORE;
}
The above code simply do, if the node taxonomy term, and the user field taxonomy term is same then he will perfectly access to the nodes. I got struggle with views. I have created a view to show the node title that can be access by the user. Manager has 100 nodes to view, in views settings I have enable the pager, 25 items per page to display. Pager splits into 4 page and shows correctly. But when comes to employee user he has access to 1 node only, but in views it still shows the pager in 4 parts.
function my_module_views_post_execute(&$view) {
if (($view->name == 'views1') || ($view->name == 'views2')) {
$nids = array();
foreach($view->result as $key=>$result) {
$nids[$key] = $result->nid;
}
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
if (!node_access('view',$node)) {
$key = array_search($node->nid, $nids);
unset($view->result[$key]);
}
}
}
}
The views pager display must be changed dynamically depends on the number of nodes. Is anyone knows kindly show me a right path to achieve this???