You are here

function node_limit_role_node_limit_sql in Node Limit 6

Same name and namespace in other branches
  1. 8 old/node_limit_role/node_limit_role.module \node_limit_role_node_limit_sql()
  2. 7 node_limit_role/node_limit_role.module \node_limit_role_node_limit_sql()

Implementation of hook_node_limit_sql().

File

node_limit_role/node_limit_role.module, line 25
Module to restrict the number of nodes by role.

Code

function node_limit_role_node_limit_sql($lid) {
  $limit = node_limit_role_node_limit_load($lid);
  if (empty($limit)) {
    return array();
  }

  // Have to do something different for DRUPAL_AUTHENTICATED_RID,
  // DRUPAL_ANONYMOUS_RID, and everything else.
  if ($limit['node_limit_role']['rid'] == DRUPAL_AUTHENTICATED_RID) {
    return array(
      'where' => array(
        'n.uid > 0',
      ),
    );
  }
  else {
    if ($limit['node_limit_role']['rid'] == DRUPAL_ANONYMOUS_RID) {
      return array(
        'where' => array(
          'n.uid = 0',
        ),
      );
    }
    else {
      return array(
        'where' => array(
          sprintf("n.uid IN (SELECT uid FROM {users_roles} WHERE rid = '%d')", $limit['node_limit_role']['rid']),
        ),
      );
    }
  }
}