public function execute()
 {
     $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT);
     $photo_model = new photosPhotoModel();
     $photo = $photo_model->getById($photo_id);
     if (!$photo) {
         throw new waException(_w('Photo not found'), 404);
     }
     $vote_model = new photosPublicgalleryVoteModel();
     $this->view->assign(array('photo_name' => $photo['name'], 'distribution' => $vote_model->getDistribution($photo_id), 'rate' => $photo['rate'], 'votes_count' => $photo['votes_count'], 'users' => $vote_model->getVotedUsers($photo_id)));
 }
 public function execute()
 {
     if (!$this->getUser()->getId()) {
         $this->errors[] = sprintf_wp("Please %ssign in%s to be able to vote for photos", '<a href="' . wa()->getRouteUrl('/login', null, true) . '">', '</a>');
         return;
     }
     $plugin = wa()->getPlugin('publicgallery');
     $photo_id = waRequest::post('photo_id', null, waRequest::TYPE_ARRAY_INT);
     $allowed_photo_id = $this->filterAllowedPhotoIds($photo_id);
     if (!$allowed_photo_id) {
         return;
     }
     $vote_model = new photosPublicgalleryVoteModel();
     $photo_model = new photosPhotoModel();
     if (wa()->getEnv() == 'frontend' && !$plugin->getSettings('self_vote')) {
         $photo = $photo_model->getById($allowed_photo_id);
         if (!$photo) {
             $this->errors[] = _w("Photo not found");
             return;
         }
         $photo = reset($photo);
         if ($photo && $photo['contact_id'] == wa()->getUser()->getId()) {
             $this->errors[] = _wp("You may not vote for your own photos");
             return;
         }
     }
     $vote = (int) waRequest::post('rate', 0);
     if ($vote > 0) {
         $vote_model->vote($allowed_photo_id, $vote);
     } else {
         $vote_model->clearVote($allowed_photo_id);
     }
     $this->response['photos'] = $photo_model->select('id, rate, votes_count')->where("id IN (" . implode(',', $photo_id) . ")")->fetchAll();
     foreach ($this->response['photos'] as &$p) {
         if ($p['votes_count']) {
             $p['votes_count_text'] = _wp('%d vote', '%d votes', $p['votes_count']);
         } else {
             $p['votes_count_text'] = '';
         }
     }
     unset($p);
     $this->response['count'] = $photo_model->countRated();
     if (count($photo_id) == 1) {
         $this->response['you_voted'] = (int) $vote_model->getByField(array('photo_id' => $photo_id[0], 'contact_id' => wa()->getUser()->getId()));
     }
 }
示例#3
0
<?php

$model = new waModel();
try {
    $model->query("SELECT moderation FROM `photos_photo` WHERE 0");
} catch (waException $e) {
    // 0 - waited
    // 1 - approved
    // -1 - declined
    $sql = "ALTER TABLE `photos_photo` ADD COLUMN moderation TINYINT(1) NOT NULL DEFAULT 1";
    $model->query($sql);
}
try {
    $model->query("SELECT `votes_count` FROM `photos_photo` WHERE 0");
} catch (waException $e) {
    $model->exec("ALTER TABLE `photos_photo` ADD COLUMN votes_count INT(11) NOT NULL DEFAULT 0");
}
$contact_id = wa()->getUser()->getId();
$photo_model = new photosPhotoModel();
$data = array();
foreach ($photo_model->select('id, rate')->where('rate > 0')->fetchAll() as $item) {
    $data[] = array('photo_id' => $item['id'], 'contact_id' => $contact_id, 'rate' => $item['rate'], 'datetime' => date('Y-m-d H:i:s'), 'ip' => waRequest::getIp(true));
}
$vote_model = new photosPublicgalleryVoteModel();
$vote_model->multipleInsert($data);
$model->exec("UPDATE `photos_photo` SET votes_count = 1 WHERE rate > 0");
 public function backendPhoto($photo_id)
 {
     $photo_model = new photosPhotoModel();
     $photo = $photo_model->getById($photo_id);
     if ($photo) {
         $votes_count_text = '';
         if ($photo['votes_count'] > 0) {
             $votes_count_text = _wp('%d vote', '%d votes', $photo['votes_count']);
         }
         $vote_model = new photosPublicgalleryVoteModel();
         $vote_item = $vote_model->getByField(array('photo_id' => $photo['id'], 'contact_id' => wa()->getUser()->getId()));
         $your_rate = 0;
         if ($vote_item) {
             $your_rate = $vote_item['rate'];
         }
         $html = '<a class="hint" href="javascript:void(0);" id="photo-rate-votes-count" data-you-voted="' . (int) ($your_rate > 0) . '"><u>' . $votes_count_text . '</u></a>' . '<span id="p-your-rate-wrapper">' . _wp('My vote: ') . '<a href="javascript:void(0);" id="your-rate" class="p-rate-photo" data-rate="' . $your_rate . '">' . photosPhoto::getRatingHtml($your_rate, 10, true) . '</a></span>' . '<a class="inline-link p-rate-clear small" href="javascript:void(0);" style="display:none;" id="clear-photo-rate"><b><i>' . _wp('cancel my vote') . '</b></i></a>';
         $html .= '<script>$.photos.publicgalleryInitYourRate();</script>';
         return array('after_rate' => $html);
     }
 }