예제 #1
0
파일: ModelTagTrait.php 프로젝트: ephp/tag
 public function addCreateTag(\Doctrine\ORM\EntityManager $em, $tag_name, $campo, $descrizione = '')
 {
     $_tag = $em->getRepository('EphpTagBundle:Tag');
     $tag = $_tag->findOneBy(array('tag' => $tag_name));
     if (!$tag) {
         $tag = new \Ephp\TagBundle\Entity\Tag();
         $tag->setTag($tag_name);
         $tag->setFavicon($campo);
         $tag->setDescrizione($descrizione);
         $tag->setPubblico(true);
         $em->persist($tag);
         $em->flush();
     }
     $this->addTag($tag, $campo);
 }
예제 #2
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     $dialog->writeSection($output, 'Import Tag', 'bg=white;fg=black');
     $gruppoClass = $this->getContainer()->get('doctrine')->getEntityNamespace('EphpTagBundle') . '\\Gruppo';
     $entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace('EphpTagBundle') . '\\Tag';
     $conn = $this->getDoctrineConnection('default');
     $em = $this->getEntityManager('default');
     $_gruppo = $em->getRepository($gruppoClass);
     $_tag = $em->getRepository($entityClass);
     $exclude = array('.', '..', 'index.html.twig', 'portlets.xml');
     $bundle = $this->getContainer()->get('kernel')->getBundle('EphpTagBundle');
     $bundle_namespace = get_class($bundle);
     echo "\n\n" . $bundle_namespace;
     $path = $bundle->getPath();
     $sep = $path[0] == '/' ? '/' : '\\';
     $path = $path . "{$sep}..{$sep}..{$sep}..{$sep}..{$sep}..{$sep}app{$sep}Resources{$sep}tags";
     echo "\n";
     if ($handle_action = opendir($path)) {
         while (false !== ($file = readdir($handle_action))) {
             if (!in_array($file, $exclude)) {
                 echo "- {$file}\n";
                 if (($handle = fopen($path . $sep . $file, "r")) !== false) {
                     $sigla = str_replace('.csv', '', $file);
                     $gruppo = $_gruppo->findOneBy(array('sigla' => $sigla));
                     if (!$gruppo) {
                         $gruppo = new \Ephp\TagBundle\Entity\Gruppo();
                         $gruppo->setSigla($sigla);
                         $gruppo->setTag($sigla);
                         $gruppo->setDescrizione($sigla);
                         $em->persist($gruppo);
                         $em->flush();
                     }
                     $tags = array();
                     foreach ($gruppo->getTags() as $tag) {
                         $tags[] = $tag;
                     }
                     $_gruppo->removeAllTag($sigla);
                     while (($data = fgetcsv($handle, 1000, ",")) !== false) {
                         $tag = $_tag->findOneBy(array('tag' => $data[0]));
                         if (!$tag) {
                             $data[0] = trim($data[0]);
                             foreach ($gruppo->getTags() as $tagg) {
                                 if (trim($tagg->getTag()) == $data[0]) {
                                     $tag = $tagg;
                                 }
                             }
                             if (!$tag) {
                                 $tag = new \Ephp\TagBundle\Entity\Tag();
                                 $tag->setTag($data[0]);
                             }
                         }
                         $tag->setPubblico(true);
                         if (isset($data[1])) {
                             $tag->setDescrizione($data[1]);
                         }
                         if (isset($data[2])) {
                             $tag->setFavicon($data[2]);
                         }
                         $em->persist($tag);
                         $em->flush();
                         $gruppo->addTags($tag);
                     }
                     fclose($handle);
                     $em->persist($gruppo);
                     $em->flush();
                 }
             }
         }
         closedir($handle_action);
     }
     $dialog->writeSection($output, $entityClass);
 }