/[drupal]/contributions/modules/jrating/jrating.module
ViewVC logotype

Diff of /contributions/modules/jrating/jrating.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2.2.41, Wed Nov 21 17:27:41 2007 UTC revision 1.2.2.42, Thu Nov 22 16:06:40 2007 UTC
# Line 93  function jrating_settings() { Line 93  function jrating_settings() {
93      //'#options' => array ('1' => t('Yes'), '0' => t('No')),      //'#options' => array ('1' => t('Yes'), '0' => t('No')),
94      '#description' => t('Should users be allowed to change their ratings? (doesn\'t apply to anonymous users)'),      '#description' => t('Should users be allowed to change their ratings? (doesn\'t apply to anonymous users)'),
95      );      );
96    
97      $form['jrating_allow_rate_own_nodes'] = array(
98        '#type' => 'checkbox',
99        '#title' => t('Allow users to rate their own nodes'),
100        '#default_value' => variable_get('jrating_allow_rate_own_nodes', 1),
101        //'#options' => array ('1' => t('Yes'), '0' => t('No')),
102        '#description' => t('Should users be allowed to rate nodes they created?'),
103        );
104    
105    $form['jrating_form_weight'] = array(    $form['jrating_form_weight'] = array(
106      '#type' => 'weight',      '#type' => 'weight',
# Line 169  function jrating_comment($comment, $op) Line 177  function jrating_comment($comment, $op)
177  }  }
178    
179  function jrating_display_rating_form($content_type, $content_id, $teaser = FALSE){  function jrating_display_rating_form($content_type, $content_id, $teaser = FALSE){
180    if (jrating_display_to_user() && (!$teaser || variable_get('jrating_display_form_teaser', 0))){    if ((!$teaser || variable_get('jrating_display_form_teaser', 0)) && jrating_display_form_to_user($content_type, $content_id)){
181      $rating_form = drupal_get_form(      $rating_form = drupal_get_form(
182        'rating_form_' . $content_type . '_' . $content_id,        'rating_form_' . $content_type . '_' . $content_id,
183          array(          array(
# Line 186  function jrating_display_rating_form($co Line 194  function jrating_display_rating_form($co
194    return theme('jrating_rating_item', $content_type, $content_id, $mean_rating, $rating_form);    return theme('jrating_rating_item', $content_type, $content_id, $mean_rating, $rating_form);
195  }  }
196    
197  function jrating_display_to_user(){  function jrating_display_form_to_user($content_type, $content_id){
198      global $user;
199      // anonymous and 'display rating widget to anonymous' set
200      if (!$user->uid && variable_get('jrating_display_anonymous', 1)) {
201        return TRUE;
202      }
203    
204      // signed in and allowed to rate this item
205      if (jrating_allow_user_rating($content_type, $content_id)){
206        return TRUE;
207      }
208      return FALSE;
209    }
210    
211    function jrating_allow_user_rating($content_type, $content_id){
212   global $user;   global $user;
213   if (user_access('rate content')) {   if (user_access('rate content')) {
214     return TRUE;     if ($user->uid && $content_type == 'node' && !variable_get('jrating_allow_rate_own_nodes', 1)){
215   }       $node = node_load($content_id);
216         if ($node->uid == $user->uid){
217   if (!$user->uid) {         return FALSE;
218     if (variable_get('jrating_display_anonymous', 1)){       }
      return TRUE;  
219     }     }
220       return TRUE;
221   }   }
   
222   return FALSE;   return FALSE;
223  }  }
224    
# Line 275  function jrating_rate_submit($form_id, $ Line 296  function jrating_rate_submit($form_id, $
296    global $user;    global $user;
297    $vote = new stdClass;    $vote = new stdClass;
298    
299    if (user_access('rate content')) {    $content_type = $form_values['content_type'];
300      $content_type = $form_values['content_type'];    $content_id = $form_values['content_id'];
301      $content_id = $form_values['content_id'];  
302      if (jrating_allow_user_rating($content_type, $content_id)) {
303      $vote->value = max(0, min(100, $form_values['rating']));      $vote->value = max(0, min(100, $form_values['rating']));
304      $vote->value_type = 'percent';      $vote->value_type = 'percent';
305      $vote->tag = 'vote';      $vote->tag = 'vote';
# Line 303  function jrating_rate_submit($form_id, $ Line 324  function jrating_rate_submit($form_id, $
324      }      }
325    }    }
326    else {    else {
327      if (!$user->uid){      $response = array('error' => $user->uid ?
328        $error = t('You need to !login to rate items', array('!login' => l(t('login or register'), 'user/login', NULL, 'destination=' . $_GET['q'])));        t('Sorry, you haven\'t got permission to vote on this item') :
329      }        t('You need to !login to rate items', array('!login' => l(t('login or register'), 'user/login', NULL, 'destination=' . $_GET['q'])))
330      else{      );
       $error = t('Sorry, you haven\'t got permission to vote on this item');  
     }  
     $response = array('error' => $error);  
331    }    }
332    
333    if ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest') {    if ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest') {

Legend:
Removed from v.1.2.2.41  
changed lines
  Added in v.1.2.2.42

  ViewVC Help
Powered by ViewVC 1.1.2