make tag setting work

This commit is contained in:
Shish
2009-01-17 17:07:06 -08:00
parent 4a8034cabe
commit 94c0ab0255
2 changed files with 12 additions and 8 deletions

View File

@@ -238,14 +238,17 @@ class Image {
public function set_tags($tags) {
$tags = tag_explode($tags);
$tags = array_map(array($this, 'resolve_alias'), $tags);
$tags = array_map(array($this, 'sanitise'), $tags);
$tags = array_map(array('Tag', 'resolve_alias'), $tags);
$tags = array_map(array('Tag', 'sanitise'), $tags);
$tags = array_iunique($tags); // remove any duplicate tags
assert(is_array($tags));
assert(count($tags) > 0);
// delete old
$this->delete_tags_from_image();
// insert each new tag
// insert each new tags
foreach($tags as $tag) {
$this->database->execute(
"INSERT IGNORE INTO tags(tag) VALUES (?)",
@@ -253,7 +256,7 @@ class Image {
$this->database->execute(
"INSERT INTO image_tags(image_id, tag_id) ".
"VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
array($image_id, $tag));
array($this->id, $tag));
$this->database->execute(
"UPDATE tags SET count = count + 1 WHERE tag = ?",
array($tag));