tags:

views:

43

answers:

1

On my site, I have three roles:

  1. Role 1
  2. Role 2
  3. Role 3

Role 1 may only ever have 10 nodes of type "NODE_TYPE". Role 2 may only ever have 100 nodes of type "NODE_TYPE". Role 3 may only ever have 1000 nodes of type "NODE_TYPE".

What can I use to enforce this? The following modules don't do the trick:

  • node_limit
  • user quota

Anyone?

+2  A: 

How this can be achieved largely depends on how NODE_TYPE is created. Assuming you have a NODE_TYPE module you could implement hook_validate by doing something like this:

function NODE_TYPE_validate($node, &$form) {
  if (NODE_TYPE_reached_post_limit()) {
    form_set_error('form_name', t('You have reached your post limit'));
  }
}

function NODE_TYPE_reached_post_limit() {
  global $user;
  //Write code to do the following:
  //-> Check which group $user belongs to
  //-> Create query to see how many posts $user has made
  //-> Return true if $user has reached the limit
}

If you do not have access to the module that creates the NODE_TYPE you could create a new module and implement hook_nodeapi:

function yournewmodule_nodeapi(&$node, $op) {
  switch ($op) {
    case 'validate':
      if ($node->type == "NODE_TYPE" && yournewmodule_reached_post_limit()) {
        form_set_error('form_name', t('You have reached your post limit'));
      }
      break;
  }
}

function yournewmodule_reached_post_limit() {
  global $user;
  //Write code to do the following:
  //-> Check which group $user belongs to
  //-> Create query to see how many posts $user has made
  //-> Return true if $user has reached the limit
}

I'm not 100% sure whether validate is the best hook to implement but it certainly is an option.

Heinrich Filter
This is probably a better solution than what I did. I used another module, called user_quota, which works, but now everytime a node is deleted, I have to increase the person's quota.
RD

related questions