First off I just want to say that I love this module and it works for my uses beautifully so far. Basically I'm using this module to allow my users to vote in one of the forums on my site called "Ideas". Users can submit their ideas so that other members can vote to promote the idea. These ideas are features that our company does not currently have, but they would like to see put in place.

However, I have 3 other forums on this site that have nothing to do with the Ideas forum. I want to restrict voting to only the Ideas forum. Currently you can only control the options to allow voting for Forum Node in overall. I think it would be a nice feature to be able to enable or disable voting for specific forums within the Forum node. Even if there was something as simple as using Views to disable the widget on specific forums that would work as well. Are there any plans for this?

Comments

NancyDru’s picture

I guess there are now. I will need to look at the Forum module to see if there is any kind of setting that can be hooked into.

voxpelli’s picture

Realted to #709006: Create hook for access control and #1015808: Allow per-node vote disabling - there really need to be some extendable system for handling these situations. Wild thought: Is there some existing access system we could build upon to easily get a powerful pluggable system? Like Chaos tool's access plugins?

NancyDru’s picture

We probably need some kind of hooks/alters to extend this. However, I am very much opposed to requiring Ctools.

NancyDru’s picture

This will be included with my commit if I get permission [uses hook_plus1_access()]:

// $Id$

/**
 * @file
 * Limit which forums allow voting.
 */

/**
 * Implementation of hook_plus1_access().
 */
function plus1_forums_plus1_access($node, $op, $account) {
  if ($node->type == 'forum') {
    // Only show widget on selected forums.
    if (in_array($node->forum_tid, variable_get('plus1_forums', array()))) {
      return PLUS1_ACCESS_ALLOW;
    }
    else {
      return PLUS1_ACCESS_DENY;
    }
  }

  // Not a forum node, so ignore it.
  return PLUS1_ACCESS_IGNORE;
}

/**
 * Implements hook_form_alter().
 * Add individual node vote disabling.
 */
function plus1_forums_form_alter(&$form, $form_state, $form_id) {
// drupal_set_message($form_id);
  switch ($form_id) {
    case 'plus1_settings':
      $form['plus1_forums_fieldset'] = array(
        '#type' => 'fieldset',
        '#title' => t('Forum settings'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#weight' => -3,
        );

      $fora = forum_get_forums();
      $forums_list = array();
      foreach ($fora as $forum) {
        $forums_list[$forum->tid] = $forum->name;
      }

      if ($forums_list) {
        $form['plus1_forums_fieldset']['plus1_forums'] = array(
          '#type' => 'checkboxes',
          '#options' => $forums_list,
          '#title' => t('Allow voting on these forums'),
          '#default_value' => variable_get('plus1_forums', array()),
          '#attributes' => array('class' => 'container-inline'),
          );
      }

      return;

    case 'forum_form_forum':
      $noyes = array(t('No'), t('Yes'));

      $state = FALSE;
      if (isset($form['tid'])) {
        $enabled = variable_get('plus1_forums', array());
        $state = in_array($form['tid']['#value'], $enabled);
      }

      $form['plus1_enable'] = array(
          '#type' => 'radios',
          '#options' => $noyes,
          '#title' => t('Allow voting on this forum'),
          '#default_value' => (int) $state,
          '#description' => t('Do you want to allow Plus 1 module voting for this forum?'),
          '#attributes' => array('class' => 'container-inline'),
          );

      $form['submit']['#weight'] = 99;
      $form['delete']['#weight'] = 99;

      // By letting the standard submit handler run first, we will get a tid
      // filled in for new forums.
      $form['#submit'][] = '_plus1_forums_form_submit';
      return;
  }
}

function _plus1_forums_form_submit($form, &$form_state) {
  if (isset($form_state['values']['tid'])) {
    $tid = $form_state['values']['tid'];
  }
  else {
    drupal_set_message(t('Incomplete data for forum "@name".', array('@name' => $form_state['values']['name'])), 'error');
    return;
  }

  // Get the current list of enabled forums.
  $forums = variable_get('plus1_forums', array());

  // Did they enable voting?
  if ($form_state['values']['plus1_enable']) {
    // Add this forum tid to the list, if it's new.
    if (!in_array($tid, $forums)) {
      $forums[] = $tid;
      variable_set('plus1_forums', $forums);
    }
  }
  else {
    // They disabled voting so remove the tid from the list.
    $key = array_search($tid, $forums);
    if ($key !== FALSE) {
      unset($forums[$key]);
      variable_set('plus1_forums', $forums);
    }
  }
}
NancyDru’s picture

Status: Active » Patch (to be ported)
NancyDru’s picture

Status: Patch (to be ported) » Fixed

Committed to 6.x-2.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.