public function execute()
 {
     $photo_model = new photosPhotoModel();
     $config = $this->getConfig();
     $last_activity_datetime = $config->getLastLoginTime(false);
     $this->response['count'] = $photo_model->countAll();
     $this->response['rated_count'] = $photo_model->countRated();
 }
 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 execute()
 {
     $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
     if (in_array($name, $this->availableFields) === false) {
         throw new waException("Can't update photo: unknown field");
     }
     $photo_id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT);
     $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM);
     if ($photo_id) {
         $photo_rights_model = new photosPhotoRightsModel();
         if (count($photo_id) == 1) {
             // editing only one photo
             if (!$photo_rights_model->checkRights(current($photo_id), true)) {
                 throw new waException(_w("You don't have sufficient access rights"));
             }
             // validations for one photo
             if ($name == 'url') {
                 if (!$this->validateUrl($value, current($photo_id))) {
                     // $photo_id is array of ids, so make current()
                     $this->errors['url'] = _w('URL is in use');
                     return;
                 }
             }
             $allowed_photo_id = $photo_id;
             $denied_photo_id = array();
         } else {
             $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true);
             $denied_photo_id = array_diff($photo_id, $allowed_photo_id);
         }
         if ($allowed_photo_id) {
             if ($name == 'rate') {
                 $value = (int) $value;
                 if ($value < 0 || $value > 5) {
                     $value = 0;
                 }
             }
             $data[$name] = $value;
             $this->photo_model = new photosPhotoModel();
             if ($name == 'description' || $name == 'rate') {
                 $this->photo_model->update($allowed_photo_id, $data);
                 if (count($photo_id) == 1 && $allowed_photo_id) {
                     // means that we edit field in one-photo page
                     $photo_id = current($photo_id);
                     if ($parent_id = $this->photo_model->getStackParentId($photo_id)) {
                         $this->response['parent_id'] = $parent_id;
                     }
                 }
                 // change count of rated
                 if ($name == 'rate') {
                     $this->response['count'] = $this->photo_model->countRated();
                     $this->log('photos_rate', 1);
                 }
             } else {
                 // update only parent photo(s)
                 $this->photo_model->updateById($allowed_photo_id, $data);
             }
             if ($name == 'name') {
                 $this->response['value'] = photosPhoto::escape($value);
             }
         }
         if (count($denied_photo_id) > 0 && count($photo_id) > 0) {
             $this->response['alert_msg'] = photosPhoto::sprintf_wplural("The operation was not performed to %d photo (%%s)", "The operation was not performed to %d photos (%%s)", count($denied_photo_id), _w("out of %d selected", "out of %d selected", count($photo_id))) . ', ' . _w("because you don't have sufficient access rights") . '.';
         }
         $allowed_photo_id_map = array();
         foreach ($allowed_photo_id as $id) {
             $allowed_photo_id_map[$id] = true;
         }
         $this->response['allowed_photo_id'] = $allowed_photo_id_map;
     }
 }