-1

I have a content type name students list and 100 nodes in this content type.

I have a user role named alpha role.

When a user belonging to alpha role logged in, he could see all the 100 nodes list with basic details and should only see any 10 nodes with full contact details one by one

how can we do this in drupal?

Thanks

  • Are you asking how to create a view that shows 10 at a time, full display mode? – Christia Mar 28 '18 at 23:32
  • Sorry if My Question is confused. For Eg: Student List fields are - Name - Email - Mobile - Qualification - Certification - Experiences - Gender And a total of 100 Nodes are currently Available. Out of This, when an user from Alpha role logged in to View. He should see all the 100 Nodes with all fields except mobile number and email id hidden. We already limited this user to view only 10 Nodes Mobile and Email field data.. when clicked on this private fields, it should count as 1 and should increment by one – Jaseer Kinangattil Mar 31 '18 at 10:41
1

You can implement hook_node_access() in your custom module, and check how many of nodes from a certain content-type the user has visited.

For example:

<?php 
function YOURMODULE_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node->type;

  if (($type === 'page') && ($op === 'view')) {
    $view_limit = variable_get('YOURMODULE_limit', 10);
    $view_count = YOURMODULE_get_view_count($node, $account);
    if ($view_count > $view_limit) {
      return NODE_ACCESS_DENY;
    }
  }
}

function YOURMODULE_get_view_count($node, $account) {
  // Depending on your implementation
  // get the view count for specific node and the user.
  //
  return 10;
} 

For getting the view count, you may want to consider enabling core module Statistics, it could carry the heavy lifting. Or you can create a logic based on sessions, or create a DB schema for your own node view counter logic.

However you get the count return it as an integer in YOURMODULE_get_view_count() custom function, then you can implement your access logic fairly easily for any content type, and for any role.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.