Пример #1
0
    public function createOrGet($text)
    {
        $tag = $this->_em->createQuery('
			SELECT t
			FROM VidalDrugBundle:Tag t
			WHERE t.text = :text
		')->setParameter('text', $text)->getOneOrNullResult();
        if (!$tag) {
            $tag = new Tag();
            $tag->setText($text);
            $this->_em->persist($tag);
            $this->_em->flush($tag);
        }
        return $tag;
    }
Пример #2
0
 public function reverseTransform($text)
 {
     $text = trim($text);
     $text = trim($text, ';');
     if (empty($text)) {
         return null;
     }
     $tags = explode(';', $text);
     if (empty($tags)) {
         return null;
     }
     foreach ($tags as $tagText) {
         $tagText = trim($tagText);
         $tag = $this->om->getRepository('VidalDrugBundle:Tag')->findOneByText($tagText);
         if (empty($tag)) {
             $tag = new Tag();
             $tag->setText($tagText);
             $this->om->persist($tag);
         }
         $this->subject->addTag($tag);
         $this->om->flush();
     }
     return null;
 }