Changeset 20252 for extensions/user_tags/include/t4u_ws.class.php
- Timestamp:
- Jan 18, 2013, 8:22:05 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/user_tags/include/t4u_ws.class.php
r20251 r20252 28 28 29 29 $service->addMethod(T4U_WS.'list', array($this, 'tagsList'), 30 31 32 33 30 array('q' => array()), 31 'retrieves a list of tags than can be filtered' 32 ); 33 34 34 $service->addMethod(T4U_WS.'update', array($this, 'updateTags'), 35 36 37 38 39 35 array('image_id' => array(), 36 'tags' => array('default' => array()) 37 ), 38 'Updates (add or remove) tags associated to an image (POST method only)' 39 ); 40 40 } 41 41 42 42 public function tagsList($params, &$service) { 43 43 $query = 'SELECT id AS tag_id, name AS tag_name FROM '.TAGS_TABLE; … … 45 45 $query .= sprintf(' WHERE name like \'%%%s%%\'', $params['q']); 46 46 } 47 47 48 48 $tagslist = $this->__makeTagsList($query); 49 49 unset($tagslist['__associative_tags']); … … 53 53 return $tagslist; 54 54 } 55 55 56 56 public function updateTags($params, &$service) { 57 57 if (!$service->isPost()) { … … 62 62 return array('error' => l10n('You are not allowed to add nor delete tags')); 63 63 } 64 64 65 65 if (empty($params['tags'])) { 66 66 $params['tags'] = array(); … … 90 90 if (count($removed_tags)>0) { 91 91 if (!t4u_Config::getInstance()->hasPermission('delete')) { 92 92 $message['error'][] = l10n('You are not allowed to delete tags'); 93 93 } else { 94 94 $message['info'] = l10n('Tags updated'); 95 95 } 96 96 } 97 97 if (count($new_tags)>0) { 98 98 if (!t4u_Config::getInstance()->hasPermission('add')) { 99 100 99 $message['error'][] = l10n('You are not allowed to add tags'); 100 $tags_to_associate = array_diff($tags_to_associate, $new_tags); 101 101 } else { 102 102 $message['info'] = l10n('Tags updated'); 103 103 } 104 104 } … … 106 106 if (empty($message['error'])) { 107 107 if (empty($tags_to_associate)) { // remove all tags for an image 108 109 110 108 $query = 'DELETE FROM '.IMAGE_TAG_TABLE; 109 $query .= sprintf(' WHERE image_id = %d', $params['image_id']); 110 pwg_query($query); 111 111 } else { 112 113 112 $tag_ids = get_tag_ids(implode(',', $tags_to_associate)); 113 set_tags($tag_ids, $params['image_id']); 114 114 } 115 115 } … … 126 126 $associative_tags['~~'.$row['tag_id'].'~~'] = $row['tag_name']; 127 127 $tagslist[] = array('id' => '~~'.$row['tag_id'].'~~', 128 129 128 'name' => $row['tag_name'] 129 ); 130 130 131 131 }
Note: See TracChangeset
for help on using the changeset viewer.