tag() public static method

Tags a bean or returns tags associated with a bean. If $tagList is NULL or omitted this method will return a comma separated list of tags associated with the bean provided. If $tagList is a comma separated list (string) of tags all tags will be associated with the bean. You may also pass an array instead of a string.
public static tag ( OODBBean $bean, mixed $tagList = NULL ) : string
$bean OODBBean bean to tag
$tagList mixed tags to attach to the specified bean
return string
Esempio n. 1
0
 /**
  * Fetching tagged items.
  *
  * @return void
  */
 public function fetchTaggedItems()
 {
     $b = R::dispense("book");
     $b->title = 'horror';
     R::store($b);
     $c = R::dispense("book");
     $c->title = 'creepy';
     R::store($c);
     $d = R::dispense("book");
     $d->title = "chicklit";
     R::store($d);
     R::tag($b, "horror,classic");
     R::tag($d, "women,classic");
     R::tag($c, "horror");
     $x = R::tagged("book", "classic");
     asrt(count($x), 2);
     $x = R::tagged("book", "classic,horror");
     asrt(count($x), 3);
     $x = R::tagged("book", array("classic", "horror"));
     asrt(count($x), 3);
 }
Esempio n. 2
0
 /**
  * Test FUSE and model formatting.
  * 
  * @todo move tagging tests to tag tester.
  * 
  * @return void
  */
 public function testFUSE()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $blog = R::dispense('blog');
     $blog->title = 'testing';
     $blog->blog = 'tesing';
     R::store($blog);
     $blogpost = R::load("blog", 1);
     $post = R::dispense("post");
     $post->message = "hello";
     $blog->sharedPost[] = $post;
     R::store($blog);
     $a = R::getAll("select * from blog ");
     R::tag($post, "lousy,smart");
     asrt(implode(',', R::tag($post)), "lousy,smart");
     R::tag($post, "clever,smart");
     $tagz = implode(',', R::tag($post));
     asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
     R::tag($blog, array("smart", "interesting"));
     asrt(implode(',', R::tag($blog)), "smart,interesting");
     try {
         R::tag($blog, array("smart", "interesting", "lousy!"));
         pass();
     } catch (RedException $e) {
         fail();
     }
     asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
     asrt(implode(",", R::tag($blog)), "smart,interesting,lousy!");
     R::untag($blog, array("smart", "interesting"));
     asrt(implode(",", R::tag($blog)), "lousy!");
     asrt(R::hasTag($blog, array("lousy!")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
     R::tag($blog, FALSE);
     asrt(count(R::tag($blog)), 0);
     R::tag($blog, array("funny", "comic"));
     asrt(count(R::tag($blog)), 2);
     R::addTags($blog, array("halloween"));
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
     R::unTag($blog, array("funny"));
     R::addTags($blog, "horror");
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     // No double tags
     R::addTags($blog, "horror");
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     asrt(count(R::tag($blog)), 3);
 }