You are here

function _photos_down_vote in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 inc/photos.down.inc \_photos_down_vote()

Vote.

1 call to _photos_down_vote()
photos_down_page in inc/photos.down.inc
Photos download (share) page.

File

inc/photos.down.inc, line 146
Handles share image page(s) and content.

Code

function _photos_down_vote($fid) {
  $output = '';
  $header = array(
    array(
      'data' => t('Vote user'),
      'field' => 'v.uid',
    ),
    array(
      'data' => t('Vote result'),
      'field' => 'v.value',
    ),
    array(
      'data' => t('Vote time'),
      'field' => 'v.timestamp',
      'sort' => 'desc',
    ),
  );
  $rows = array();
  $query = db_select('votingapi_vote', 'v')
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->join('users', 'u', 'u.uid = v.uid');
  $query
    ->fields('v', array(
    'uid',
    'value',
    'timestamp',
    'vote_source',
  ))
    ->fields('u', array(
    'name',
  ))
    ->condition('v.entity_type', 'image')
    ->condition('v.entity_id', $fid)
    ->orderByHeader($header)
    ->limit(30);
  $result = $query
    ->execute();
  foreach ($result as $a) {
    if ($a->uid != 0) {
      $name = theme('username', array(
        'account' => $a,
      ));
    }
    else {
      $name = $a->vote_source;
    }
    $rows[] = array(
      $name,
      $a->value,
      format_date($a->timestamp, 'small'),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No vote available.'),
        'colspan' => 3,
      ),
    );
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  $output .= theme('pager');
  drupal_set_title(t('See a image vote'));
  return $output;
}