Changeset 3
- Timestamp:
- 08/02/06 05:12:04
- Files:
-
- trunk/phptagengine.class.inc.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phptagengine.class.inc.php
r2 r3 333 333 */ 334 334 function save_tags($item, $tags, $type = null, $user = null) { 335 $type = $this->default_value('type', $type); 336 $user = $this->default_value('user', $user); 335 337 $old_tags = $this->get_tags($item, $type, $user); 336 338 $new_tags = array(); … … 345 347 if ($tag != '') { 346 348 if ($this->add_tag($user, $item, $tag, $type)) { 347 $new_tags[] = $t ag;349 $new_tags[] = $this->normalize($tag); 348 350 } 349 351 else { … … 474 476 } 475 477 $tag_id = $this->get_tag_id($tag); 478 if ($tag_id == false) { 479 return false; 480 } 476 481 $result = $this->db->Execute(" 477 482 DELETE … … 518 523 if (!$result) { 519 524 return false; 525 } 526 // check for dupes 527 $result = $this->db->Execute(" 528 SELECT * 529 FROM $this->table_tags 530 WHERE tag = '$new_tag_id' 531 ") or die($this->db->ErrorMsg().' in '.__FILE__); 532 if (!$result) { 533 return false; 534 } 535 else if ($result->RowCount() > 0) { 536 $tags = array(); 537 $ids_to_delete = array(); 538 while ($data = $result->FetchNextObject()) { 539 $key = $data->TAG.$data->ITEM.$data->TYPE.$data->USER; 540 if (!in_array($key, $tags)) { 541 $tags[] = $key; 542 } 543 else { 544 $ids_to_delete[] = $data->ID; 545 } 546 } 547 // remove dupes 548 if (count($ids_to_delete) > 0) { 549 $result = $this->db->Execute(" 550 DELETE 551 FROM $this->table_tags 552 WHERE id IN (".implode(',', $ids_to_delete).") 553 ") or die($this->db->ErrorMsg().' in '.__FILE__); 554 if (!$result) { 555 return false; 556 } 557 } 520 558 } 521 559 }
