/** * Returns an array of blog entries associated with the tag string passed in. * * @param string $tagName * The name of the tag against which this method will try to find * associated blog entries. * * @return mixed * Returns an array of blog entries associated with the tag name * passed in, or null if there are no associated blog entries. */ public function getBlogEntriesByTagName($tagName) { $blogEntryTags = new Datasource_Cms_Connect_BlogEntryTags(); $tagId = $blogEntryTags->getID($tagName); //Now get all the blog entries associated with that tag id. $blogEntryTagMap = new Datasource_Cms_Connect_BlogEntryTagMap(); $blogEntryDetails = $blogEntryTagMap->getByTagId($tagId); $returnArray = array(); if (!empty($blogEntryDetails)) { $blogEntries = new Datasource_Cms_Connect_BlogEntries(); foreach ($blogEntryDetails as $currentBlogEntry) { $returnArray[] = $blogEntries->getByID($currentBlogEntry->blog_entry_id); } } //Provide a return value consistent with this function's contract. if (empty($returnArray)) { $returnVal = null; } else { $returnVal = $returnArray; } return $returnVal; }
/** * Saves tags associated with the blog entry ID passed in. Also maps * the tags to the entry. * * @param int $blogEntryID * The blog entry ID to which the tags should be mapped. * * @param array $tags * The array of tags to associate with the blog entry ID. */ protected function _saveTags($blogEntryID, $tags) { //Add any tags from $tags which are unique. $blogEntryTags = new Datasource_Cms_Connect_BlogEntryTags(); if (!empty($tags)) { $blogEntryTags->upsert($tags); } //Delete all associations with the blogentry $blogEntryTagMap = new Datasource_Cms_Connect_BlogEntryTagMap(); $blogEntryTagMap->removeAllMaps($blogEntryID); //Now associate the blog entry with each tag in $tags if (!empty($tags)) { foreach ($tags as $currentTag) { $tagID = $blogEntryTags->getID($currentTag); $blogEntryTagMap->addMap($blogEntryID, $tagID); } } }