/**
  * Set tags to this photo. If tag doesn't exist it will be created.
  * If photo hasn't tag anymore it will be removed for this photo.
  * Take into account stack of photos
  *
  * @param int $photo_id
  * @param array $tags NAMES of tags
  * @throws Exception
  */
 public function set($photo_id, $tags = array())
 {
     if (!$photo_id) {
         throw new Exception("Can't set tags: unkown photo id");
     }
     $photo_model = new photosPhotoModel();
     $photo = $photo_model->select('id, parent_id, stack_count')->where('id = i:photo_id', array('photo_id' => $photo_id))->fetch();
     // we have photo in stack
     if ($photo['parent_id'] != 0) {
         $photo_id = $photo['parent_id'];
     }
     $children = $photo_model->select('id')->where('parent_id = i:photo_id', array('photo_id' => $photo_id))->fetchAll('id', true);
     if ($children) {
         // we have children in stack
         $photo_id = array_merge((array) $photo_id, array_keys($children));
     } else {
         // we have just photo
         $photo_id = (array) $photo_id;
     }
     $tag_model = new photosTagModel();
     $tag_ids = $tag_model->getIds($tags, true);
     foreach ($photo_id as $id) {
         $this->_set($id, $tag_ids);
     }
 }
 public function filterAllowedPhotoIds($photo_id)
 {
     if (!$photo_id) {
         return $photo_id;
     }
     if (wa()->getEnv() == 'backend') {
         if (wa()->getUser()->getRights('photos', 'edit')) {
             return $photo_id;
         }
         $photo_model = new photosPhotoModel();
         return array_keys($photo_model->select('id')->where("rate > 0 AND id IN (" . implode(',', $photo_id) . ")")->fetchAll('id'));
     } else {
         return $photo_id;
     }
 }
 private function validateUrl($url, $photo_id)
 {
     $this->photo_model = new photosPhotoModel();
     $where = "url = s:url AND id != i:id";
     return !$this->photo_model->select('id')->where($where, array('url' => $url, 'id' => $photo_id))->fetch();
 }
Example #4
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");
 private function urlExists($url, $photo_id)
 {
     $where = "url = s:url AND id != i:id";
     return !!$this->model->select('id')->where($where, array('url' => $url, 'id' => $photo_id))->fetch();
 }