You are here

function template_preprocess_photos_vote in Album Photos 6.2

File

./photos.module, line 1266

Code

function template_preprocess_photos_vote(&$variables) {
  global $user;
  if ($variables['fid']) {
    $fid = $variables['fid'];
    $x = votingapi_select_votes(array(
      'uid' => $user->uid,
      'content_type' => 'image',
      'content_id' => $fid,
    ));
    if (!user_access('allowed to vote')) {
      $variables['vote']['access'] = true;
      $variables['vote']['down']['#href'] = $variables['up']['#href'] = url('user/login', array(
        'query' => drupal_get_destination(),
      ));
      $variables['vote']['down']['#title'] = $variables['up']['#title'] = t('Login to vote');
    }
    else {
      if ($x['0']['value'] == 1) {
        $down_href = url("photos/image/{$fid}/vote/down", array(
          'query' => drupal_get_destination(),
        ));
      }
      else {
        if ($x['0']['value'] == -1) {
          $up_href = url("photos/image/{$fid}/vote/up", array(
            'query' => drupal_get_destination(),
          ));
        }
        else {
          $down_href = url("photos/image/{$fid}/vote/down", array(
            'query' => drupal_get_destination(),
          ));
          $up_href = url("photos/image/{$fid}/vote/up", array(
            'query' => drupal_get_destination(),
          ));
        }
      }
      $variables['vote']['up'] = array(
        '#title' => t('I like this image'),
        '#href' => $up_href,
      );
      $variables['vote']['down'] = array(
        '#title' => t('I do not like this image'),
        '#href' => $down_href,
      );
    }
    $sum = votingapi_recalculate_results('image', $fid);
    if ($sum['0']['value']) {
      $t_sum = $sum['2']['value'];
      $t_average = $sum['1']['value'];
      $t_count = $sum['0']['value'];
    }
    else {
      $t_count = $t_sum = 0;
    }
    $variables['vote']['count'] = array(
      '#count' => $t_count,
      '#sum' => $t_sum,
      '#average' => $t_average,
      '#title' => t('View voting users'),
    );
    if (user_access('view vote list')) {
      $variables['vote']['count']['#href'] = url("photos/zoom/{$fid}/vote");
    }
  }
}