示例#1
0
 /**
  * Remove Tag from Multimedia Object
  *
  * @param MultimediaObject $mmobj
  * @param string $tagId
  * @param  boolean          $executeFlush
  * @return Array[Tag] removed tags
  */
 public function removeTagFromMultimediaObject(MultimediaObject $mmobj, $tagId, $executeFlush = true)
 {
     $removeTags = array();
     $tag = $this->repository->find($tagId);
     if (!$tag) {
         throw new \Exception("Tag with id " . $tagId . " not found.");
     }
     do {
         $children = $tag->getChildren();
         if (!$mmobj->containsAnyTag($children->toArray())) {
             $removeTags[] = $tag;
             $removed = $mmobj->removeTag($tag);
             if ($removed && !$mmobj->isPrototype()) {
                 $tag->decreaseNumberMultimediaObjects();
             }
             $this->dm->persist($tag);
         } else {
             break;
         }
     } while ($tag = $tag->getParent());
     $this->dm->persist($mmobj);
     if ($executeFlush) {
         $this->dm->flush();
     }
     return $removeTags;
 }
 public function testTagCollection()
 {
     $mm = new MultimediaObject();
     $tag0 = new Tag();
     $tag0->setCod('cod0');
     $tag1 = new Tag();
     $tag1->setCod('cod1');
     $tag2 = new Tag();
     $tag2->setCod('cod2');
     $tag3 = new Tag();
     $tag3->setCod('cod3');
     $tag4 = new Tag();
     $tag4->setCod('cod4');
     $this->assertFalse($mm->containsTag($tag1));
     $mm->addTag($tag1);
     $this->assertTrue($mm->containsTag($tag1));
     $mm->removeTag($tag1);
     $this->assertFalse($mm->containsTag($tag1));
     $this->assertFalse($mm->containsTagWithCod($tag1->getCod()));
     $mm->addTag($tag1);
     $this->assertTrue($mm->containsTagWithCod($tag1->getCod()));
     $mm->removeTag($tag1);
     $this->assertFalse($mm->containsTagWithCod($tag1->getCod()));
     //Repeat Tag
     $this->assertFalse($mm->containsTag($tag1));
     $mm->addTag($tag1);
     $mm->addTag($tag1);
     $this->assertTrue($mm->containsTag($tag1));
     $mm->removeTag($tag1);
     $this->assertFalse($mm->containsTag($tag1));
     $this->assertFalse($mm->removeTag($tag1));
     //containsAllTag and containsAnyTag
     $mm->addTag($tag1);
     $mm->addTag($tag2);
     $mm->addTag($tag3);
     $this->assertTrue($mm->containsAnyTag(array($tag0, $tag2)));
     $this->assertTrue($mm->containsAnyTag(array($tag2, $tag3)));
     $this->assertFalse($mm->containsAnyTag(array($tag0, $tag4)));
     $this->assertTrue($mm->containsAllTags(array($tag1, $tag2)));
     $this->assertTrue($mm->containsAllTags(array($tag1)));
     $this->assertFalse($mm->containsAllTags(array($tag0, $tag2)));
     $this->assertFalse($mm->containsAllTags(array($tag0, $tag1, $tag2, $tag3)));
     //containsAllTagsWithCodes and containsAnyTagWithCodes
     $mm->removeTag($tag1);
     $mm->removeTag($tag2);
     $mm->removeTag($tag3);
     $mm->addTag($tag1);
     $mm->addTag($tag4);
     $this->assertTrue($mm->containsAllTagsWithCodes(array($tag1->getCod(), $tag4->getCod())));
     $mm->removeTag($tag4);
     $this->assertFalse($mm->containsAllTagsWithCodes(array($tag4->getCod())));
     $this->assertTrue($mm->containsAllTagsWithCodes(array($tag1->getCod())));
     $this->assertFalse($mm->containsAnyTagWithCodes(array($tag4->getCod())));
     $this->assertTrue($mm->containsAnyTagWithCodes(array($tag1->getCod())));
 }