/** * * @param int $photoId * @param int $tagText * @return BOL_EntityTag */ public function addTag($photoId, $tagText) { $tags = BOL_TagDao::getInstance()->findTagsByLabel(array($tagText)); if (empty($tags)) { $tag = new BOL_Tag(); $tag->label = $tagText; BOL_TagDao::getInstance()->save($tag); } else { $tag = $tags[0]; } $entityTagItem = new BOL_EntityTag(); $entityTagItem->setEntityId($photoId)->setEntityType(self::ENTITY_PHOTO)->setTagId($tag->getId()); BOL_EntityTagDao::getInstance()->save($entityTagItem); return $entityTagItem; }
/** * Adds tag list to entity item. * * @param integer $entityId * @param string $entityType * @param array $tags */ public function updateEntityTags($entityId, $entityType, array $tags) { $tags = array_map('htmlspecialchars', $tags); $tags = array_map('mb_strtolower', $tags); $tags = $this->updateTagList($tags); $entityTags = $this->findEntityTags($entityId, $entityType); $tagsToAdd = array_udiff($tags, $entityTags, array($this, 'tagDiff')); /* @var $tag BOL_Tag */ foreach ($tagsToAdd as $tag) { $entityTagItem = new BOL_EntityTag(); $entityTagItem->setEntityId($entityId)->setEntityType($entityType)->setTagId($tag->getId()); $this->entityTagDao->save($entityTagItem); } $tagsToDelete = array_udiff($entityTags, $tags, array($this, 'tagDiff')); foreach ($tagsToDelete as $tag) { $this->entityTagDao->deleteEntityTagItem($entityId, $entityType, $tag->getId()); } }