public function loadOrCreateTags(array $names)
    {
        if (empty($names)) {
            return array();
        }

        $names = array_unique($names);

        $builder = $this->em->createQueryBuilder();

        $tags = $builder
            ->select('t')
            ->from($this->tagClass, 't')

            ->where($builder->expr()->in('t.name', $names))

            ->getQuery()
            ->getResult()
        ;

        $loadedNames = array();
        foreach ($tags as $tag) {
            $loadedNames[] = $tag->getName();
        }

        $missingNames = array_udiff($names, $loadedNames, 'strcasecmp');
        if (sizeof($missingNames)) {
            foreach ($missingNames as $name) {
                $tag = $this->createTag($name);
                $this->em->persist($tag);

                $tags[] = $tag;
            }

            $this->em->flush();
        }

        return $tags;
    }
public function loadOrCreateTags(array $names)
    {
        if (empty($names)) {
            return array();
        }

        $names = array_unique($names);

        $builder = $this->em->createQueryBuilder();

        $tags = $builder
            ->select('t')
            ->from($this->tagClass, 't')

            ->where($builder->expr()->in('t.name', $names))

            ->getQuery()
            ->getResult()
        ;

        $loadedNames = array();
        foreach ($tags as $tag) {
            $loadedNames[] = $tag->getName();
        }

        $missingNames = array_udiff($names, $loadedNames, 'strcasecmp');
        if (sizeof($missingNames)) {
            foreach ($missingNames as $name) {
                $tag = $this->createTag($name);
                $this->em->persist($tag);

                $tags[] = $tag;
            }

            $this->em->flush();
        }

        return $tags;
    }
public function loadOrCreateTags ( array $ names ) { if ( empty ( $ names ) ) { return array ( ) ; } $ names = array_unique ( $ names ) ; $ builder = $ this -> em -> createQueryBuilder ( ) ; $ tags = $ builder -> select ( 't' ) -> from ( $ this -> tagClass , 't' ) -> where ( $ builder -> expr ( ) -> in ( 't.name' , $ names ) ) -> getQuery ( ) -> getResult ( ) ; $ loadedNames = array ( ) ; foreach ( $ tags as $ tag ) { $ loadedNames [ ] = $ tag -> getName ( ) ; } $ missingNames = array_udiff ( $ names , $ loadedNames , 'strcasecmp' ) ; if ( sizeof ( $ missingNames ) ) { foreach ( $ missingNames as $ name ) { $ tag = $ this -> createTag ( $ name ) ; $ this -> em -> persist ( $ tag ) ; $ tags [ ] = $ tag ; } $ this -> em -> flush ( ) ; } return $ tags ; }
Loads or creates multiples tags from a list of tag names

@param array  $names   Array of tag names
@return Tag[]
Loads or creates multiples tags from a list of tag names