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()));
     }
 }
 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);
     }
 }