public function execute() { $photo_id = $this->post('id', true); if (!is_array($photo_id)) { if (strpos($photo_id, ',') !== false) { $photo_id = array_map('intval', explode(',', $photo_id)); } else { $photo_id = array($photo_id); } } $tag = waRequest::post('tag', ''); if (!$tag) { $tag = array(); } if (!is_array($tag)) { if (strpos($tag, ',') !== false) { $tag = explode(',', $tag); } else { $tag = array($tag); } } $tag = array_map('trim', $tag); $tag_model = new photosTagModel(); $photo_tag_model = new photosPhotoTagsModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); if ($allowed_photo_id) { $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tag, true)); $this->response = true; } else { throw new waAPIException('access_denied', 403); } }
public function execute() { $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT); $one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT); $tags = waRequest::post('tags', '', waRequest::TYPE_STRING_TRIM); $tags = $tags ? explode(',', $tags) : array(); $delete_tags = waRequest::post('delete_tags', array(), waRequest::TYPE_ARRAY_INT); $tag_model = new photosTagModel(); $photo_tag_model = new photosPhotoTagsModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); $denied_photo_id = array_values(array_diff($photo_id, $allowed_photo_id)); if ($allowed_photo_id) { if ($one_photo) { $allowed_photo_id = $allowed_photo_id[0]; $photo_tag_model->set($allowed_photo_id, $tags); $photo_model = new photosPhotoModel(); if ($parent_id = $photo_model->getStackParentId($allowed_photo_id)) { $this->response['parent_id'] = $parent_id; } } else { if ($delete_tags) { $photo_tag_model->delete($allowed_photo_id, $delete_tags); } $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tags, true)); } $allowed_photo_id = (array) $allowed_photo_id; $tags = $photo_tag_model->getTags($allowed_photo_id); if (!$tags && $allowed_photo_id) { $tags = array_fill_keys($allowed_photo_id, array()); } $this->response['tags'] = $tags; } if ($denied_photo_id) { $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") . '.'; } $this->response['cloud'] = $tag_model->getCloud(); }
/** * 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); } }