plugin->loadType("tag", $tag->tag); $tag_id = $tag_obj->getId(); $tags [$tag_id]= $tag_obj->getName(); } return $tags; } function addNewTagRelations($tags, $obj_id, $obj_type) { global $TeKe; foreach ($tags as $tag) { $tag = trim($tag); if ($tag == "") { continue; } $obj = $TeKe->plugin->loadType("tag", $tag); if ($obj->getId()) { $tag_id = $obj->getId(); } else { $tag_id = $obj->build(array("name"=>$tag)); } $this->addTagRelation($tag_id, $obj_id, $obj_type); } } function addTagRelation($tag_id, $obj_id, $obj_type) { $insert = query_insert("INSERT INTO " . DB_PREFIX . "tag_relations (tag, object, object_type) values (".$tag_id.", ".$obj_id.", '".$obj_type."')"); } function deleteOldTagRelations($tags, $obj_id, $obj_type) { foreach ($tags as $tag_id => $tag) { $this->deleteTagRelation($tag_id, $obj_id, $obj_type); } } function deleteTagRelation($tag_id, $obj_id, $obj_type) { global $TeKe; $res = query("DELETE FROM ". DB_PREFIX . "tag_relations WHERE tag=${tag_id} AND object=${obj_id} AND object_type='${obj_type}'"); $existing_tag_relations = query_rows("SELECT * FROM ". DB_PREFIX . "tag_relations WHERE tag=".$tag_id); if (count($existing_tag_relations) == 0) { $tag_obj = $TeKe->plugin->loadType("tag", $tag_id); $tag_obj->delete(); } } } ?>