/**
  * Removes a tag or a set of tags from the object. As usual, the second
  * parameter might be an array of tags or a comma-separated string.
  *
  * @param      BaseObject  $object
  * @param      mixed       $tagname
  */
 public function removeTag(BaseObject $object, $tagname)
 {
     $tagname = sfPropelActAsTaggableToolkit::explodeTagString($tagname);
     if (is_array($tagname)) {
         foreach ($tagname as $tag) {
             $this->removeTag($object, $tag);
         }
     } else {
         $tagname = sfPropelActAsTaggableToolkit::cleanTagName($tagname);
         $tags = self::get_tags($object);
         $saved_tags = $this->getSavedTags($object);
         if (isset($tags[$tagname])) {
             unset($tags[$tagname]);
             self::set_tags($object, $tags);
         }
         if (isset($saved_tags[$tagname])) {
             unset($saved_tags[$tagname]);
             self::set_saved_tags($object, $saved_tags);
             self::add_removed_tag($object, $tagname);
         }
     }
 }
$tagged_with_tag17 = TagPeer::getTaggedWith(array('tag1', 'tag7'));
$t->ok(count($tagged_with_tag17) == 3, 'getTaggedWith() returns objects tagged with several specific tags.');
// these tests check the isTaggable() method
$t->diag('detecting if a model is taggable or not');
$t->ok(sfPropelActAsTaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.');
$object = _create_object();
$t->ok(sfPropelActAsTaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.');
$t->ok(sfPropelActAsTaggableToolkit::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(sfPropelActAsTaggableToolkit::extractTriple('ns:key=value') === array('ns:key=value', 'ns', 'key', 'value'), 'triple extracted successfully.');
$t->ok(sfPropelActAsTaggableToolkit::extractTriple('ns:key') === array('ns:key', null, null, null), 'ns:key is not a triple.');
$t->ok(sfPropelActAsTaggableToolkit::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.');
Esempio n. 3
0
 /**
  * Retrieves a tag by his name. If it does not exist, creates it (but does not
  * save it)
  *
  * @param      String      $tagname
  * @return     Tag
  */
 public static function retrieveOrCreateByTagname($tagname)
 {
     // retrieve or create the tag
     $tag = TagPeer::retrieveByTagName($tagname);
     if (!$tag) {
         $tag = new Tag();
         $tag->setName($tagname);
         $triple = sfPropelActAsTaggableToolkit::extractTriple($tagname);
         list($tagname, $triple_namespace, $triple_key, $triple_value) = $triple;
         $tag->setTripleNamespace($triple_namespace);
         $tag->setTripleKey($triple_key);
         $tag->setTripleValue($triple_value);
         $tag->setIsTriple(!is_null($triple_namespace));
     }
     return $tag;
 }