/** * Constructor * * @param object TagIterator $sourceIterator * @param array $filterValues Values to filter out of the resulting tags. * @return object * @access public * @since 12/8/06 */ function TagFilterIterator($sourceIterator, $filterValues = array()) { $this->HarmoniIterator($null = null); $this->_sourceIterator = $sourceIterator; $this->_toFilter = array(); foreach ($filterValues as $string) { $tag = new Tag($string); if ($tag->getValue()) { $this->_toFilter[] = $tag->getValue(); } } $this->_nextElement = null; $this->_numSoFar = 0; // Load our first element $this->advance(); }
/** * Execute this action. * * @param object Harmoni $harmoni * @return mixed * @access public * @since 11/10/06 */ function execute() { $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("polyphony-tags"); $itemId = RequestContext::value('item_id'); $system = RequestContext::value('system'); $tagValue = RequestContext::value('tag'); $harmoni->request->endNamespace(); $item = TaggedItem::forId($itemId, $system); // Add the tag $tag = new Tag($tagValue); if (!$tag->getValue()) { $this->error(_("Cannot tag with an empty value.")); } else { $tag->tagItem($item); } // send the new tag list $this->writeXmlResponse($item->getUserTags()); }
/** * Rename the tag for the given agent * * @param object Id $agentId * @param string $newValue * @return void * @access public * @since 11/27/06 */ function renameForAgent($agentId, $newValue) { $newTag = new Tag($newValue); $query = new UpdateQuery(); $query->setTable('tag'); $query->setColumns(array('value')); $query->setValues(array("'" . addslashes($newTag->getValue()) . "'")); $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'"); $query->addWhere("tag.user_id='" . addslashes($agentId->getIdString()) . "'"); $dbc = Services::getService("DatabaseManager"); $dbc->query($query, $this->getDatabaseIndex()); }
/** * Prints tag to <code>$wgOut</code> * * @param $tag Tag * @param $attribute */ private function printTag(Tag $tag, $attribute) { global $wgOut; $wgOut->addHTML(sprintf('<div class="fptc_tag" style="font-size:%dpx;">%s</div>', $this->fontSizeMin + ($this->fontSizeMax - $this->fontSizeMin) * $tag->getRate(), $attribute == wfMsg('fptc-categoryname') ? $wgOut->parseInline(sprintf('[[:%s:%s|%s]]', self::CATEGORY_PAGE, $tag->getValue(), $tag->getValue())) : $wgOut->parseInline(sprintf('[[:%s:%s/%s/%s|%s]]', self::SPECIALPAGE_PREFIX, self::ATTRIBUTE_VALUE_INDEX_SPECIALPAGE, $attribute, $tag->getValue(), $tag->getValue())))); }
/** * Update the auto-generated tags for the asset * * @param object Id $assetId * @return void * @access public * @since 11/21/06 */ function updateAssetTags($assetId) { // Clean the values into nice tag values $newTagValues = array(); foreach ($this->_newStructuredTagValues[$assetId->getIdString()] as $value) { $tag = new Tag($value); if ($tag->getValue()) { $newTagValues[] = $tag->getValue(); } } // Get the TaggedItem for this asset $idManager = Services::getService("Id"); $systemAgentId = $idManager->getId('system:concerto'); $item = TaggedItem::forId($assetId, 'concerto'); // Remove any missing tags $systemTags = $item->getTagsByAgent($systemAgentId); $existingTagValues = array(); while ($systemTags->hasNext()) { $tag = $systemTags->next(); if (in_array($tag->getValue(), $newTags)) { $existingTagValues[] = $tag->getValue(); } else { $tag->removeFromItemsForAgent($item, $systemAgentId); printpre("Removing tag '{$tagValue}'"); } } // Add any new tags foreach ($newTagValues as $tagValue) { if (!in_array($tagValue, $existingTagValues)) { printpre("Adding tag '{$tagValue}'"); $tag = new Tag($tagValue); $tag->tagItemForAgent($item, $systemAgentId); } } unset($this->_newStructuredTagValues[$assetId->getIdString()]); }
/** * Regenerate tags for a single Asset * * @param object Asset $asset * @param object Id $agent Id The agent id to associate with these tags * @param string $system The system to associate with these tags * @param optional object Id $repositoryId Not required, but can enhance * efficiency if it is known ahead of time. * @return void * @access public * @since 11/27/06 */ function regenerateTagsForAsset($asset, $agentId, $system, $repositoryId = null) { if (!is_object($repositoryId)) { $repository = $asset->getRepository(); $repositoryId = $repository->getId(); } $assetId = $asset->getId(); printpre("<hr/>Asset: " . $assetId->getIdString() . " " . $asset->getDisplayName()); $item = TaggedItem::forId($asset->getId(), $system); $item->deleteTagsByAgent($agentId); // Loop through the records and generate tags from the values $partStructIds = $this->getPartStructureIdsForTagGeneration($repositoryId); while ($partStructIds->hasNext()) { $values = $asset->getPartValuesByPartStructure($partStructIds->next()); while ($values->hasNext()) { $value = $values->next(); $tag = new Tag($value->asString()); $tag->tagItemForAgent($item, $agentId); printpre("Adding Tag: " . $tag->getValue()); } } }