$tagged_with_tag127 = TagPeer::getTaggedWith('tag1, tag2, tag7', array('nb_common_tags' => 2)); $t->ok(count($tagged_with_tag127) == 6, 'the "nb_common_tags" option of getTaggedWith() returns objects tagged with a certain number of tags within a set of specific tags.'); // these tests check the isTaggable() method $t->diag('detecting if a model is taggable or not'); $t->ok(deppPropelActAsTaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.'); $object = _create_object(); $t->ok(deppPropelActAsTaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.'); $t->ok(deppPropelActAsTaggableToolkit::isTaggable('Tristan\'s cat') === false, 'Tristan\'s cat is not taggable, and that is fine.'); TagPeer::doDeleteAll(); TaggingPeer::doDeleteAll(); call_user_func(array(_create_object()->getPeer(), 'doDeleteAll')); // these tests check for the application of triple tags $t->diag('applying triple tagging'); $t->ok(deppPropelActAsTaggableToolkit::extractTriple('ns:key=value') === array('ns:key=value', 'ns', 'key', 'value'), 'triple extracted successfully.'); $t->ok(deppPropelActAsTaggableToolkit::extractTriple('ns:key') === array('ns:key', null, null, null), 'ns:key is not a triple.'); $t->ok(deppPropelActAsTaggableToolkit::extractTriple('ns') === array('ns', null, null, null), 'ns is not a triple.'); $object = _create_object(); $object->addTag('tutu'); $object->save(); $object = _create_object(); $object->addTag('ns:key=value'); $object->addTag('ns:key=tutu'); $object->addTag('ns:key=titi'); $object->addTag('ns:key=toto'); $object->save(); $object_tags = $object->getTags(); $t->ok($object->hasTag('ns:key=value'), 'object has triple tag'); $tag = TagPeer::retrieveOrCreateByTagname('ns:key=value'); $t->ok($tag->getIsTriple(), 'a triple tag created from a string is identified as a triple.'); $tag = TagPeer::retrieveOrCreateByTagname('tutu'); $t->ok(!$tag->getIsTriple(), 'a non tripled tag created from a string is not identified as a triple.');
<?php if (count($related_tags) > 0) { ?> <div class="evidence-box float-container"> <h5 class="subsection">Argomenti correlati</h5> <p class="pad10"> <?php foreach ($related_tags as $tag_name => $relevance) { ?> <?php list($tag, $namespace, $key, $value) = deppPropelActAsTaggableToolkit::extractTriple($tag_name); ?> <?php echo link_to(strtolower($value), '@argomento?triple_value=' . $value, array('class' => 'folk' . $relevance)); ?> <?php } ?> </p> </div> <?php }
/** * Adds a tag to the object. The "tagname" param can be a string or an array * of strings. These 3 code sequences produce an equivalent result : * * 1- $object->addTag('tag1,tag2,tag3'); * 2- $object->addTag('tag1'); * $object->addTag('tag2'); * $object->addTag('tag3'); * 3- $object->addTag(array('tag1','tag2','tag3')); * * @param BaseObject $object * @param mixed $tagname */ public function addTag(BaseObject $object, $tagname) { $tagname = deppPropelActAsTaggableToolkit::explodeTagString($tagname); if (is_array($tagname)) { foreach ($tagname as $tag) { $this->addTag($object, $tag); } } else { $removed_tags = self::get_removed_tags($object); if (isset($removed_tags[$tagname])) { unset($removed_tags[$tagname]); self::set_removed_tags($object, $removed_tags); self::add_saved_tag($object, $tagname); } else { $saved_tags = $this->getSavedTags($object); if (sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_triple_distinct', false)) { // the binome namespace:key must be unique $triple = deppPropelActAsTaggableToolkit::extractTriple($tagname); if (!is_null($triple[1]) && !is_null($triple[2])) { $pattern = '/^' . $triple[1] . ':' . $triple[2] . '=(.*)$/'; $tags = $object->getTags(array('triple' => true, 'return' => 'tag')); $removed = array(); foreach ($tags as $tag) { if (preg_match($pattern, $tag)) { $removed[] = $tag; } } $object->removeTag($removed); } } if (!isset($saved_tags[$tagname])) { self::add_tag($object, $tagname); } } } }
/** * Retrieves a tag by his triple_name (given the whole triplet string). * If it does not exist, creates it (but does not * save it) * If tags exist, having that triple value, then return the FIRST ONE * * @param String $tagname the whole triplet * @return Tag */ public static function retrieveOrCreateByTripleValue($tagname) { // retrieve or create the tag $triple = deppPropelActAsTaggableToolkit::extractTriple($tagname); list($tagname, $triple_namespace, $triple_key, $triple_value) = $triple; $tag = self::retrieveFirstByTripleValue($triple_value); if (!$tag) { $tag = new Tag(); $tag->setName($tagname); $tag->setTripleNamespace($triple_namespace); $tag->setTripleKey($triple_key); $tag->setTripleValue($triple_value); $tag->setIsTriple(!is_null($triple_namespace)); } return $tag; }