Example #1
0
 public function setCache($body)
 {
     $time = time();
     $date = date('Y-m-d H:i:s', $time);
     #$title = iconv('WINDOWS-1251', 'UTF-8', $this->title);
     $caches = $this->_em->getRepository('VidalMainBundle:MarketCache')->findBy(array('target' => $this->id, 'document' => $this->isDocument));
     foreach ($caches as $val) {
         $this->_em->remove($val);
         $this->_em->flush();
     }
     $marketCache = new MarketCache();
     $marketCache->setDocument($this->isDocument);
     $marketCache->setBody($this->body);
     $marketCache->setTarget($this->id);
     $this->_em->persist($marketCache);
     $this->_em->flush();
 }
Example #2
0
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('--- vidal:parser started');
        $emDrug = $this->getContainer()->get('doctrine')->getManager('drug');
        $em = $this->getContainer()->get('doctrine')->getManager();
        # очищаем таблицы кеширования
        $em->createQuery('
			DELETE FROM VidalMainBundle:MarketCache mc
		')->execute();
        $em->createQuery('
			DELETE FROM VidalMainBundle:MarketDrug md
		')->execute();
        # Загружаем файлы XML в Кеш
        $this->uploadFiles();
        $query = $emDrug->createQuery('SELECT COUNT(d.DocumentID) FROM VidalDrugBundle:Document d');
        $count = $query->getSingleScalarResult();
        for ($i = 0; $i < $count; $i += 100) {
            # Вначале пройдемся по документам ( их тупо меньше )
            # $drugs = $emDrug->getRepository('VidalDrugBundle:Document')->findAll();
            $drugs = $emDrug->createQuery('SELECT d FROM VidalDrugBundle:Document d ')->setMaxResults(100)->setFirstResult($i)->getResult();
            foreach ($drugs as $drug) {
                # Это надолго
                # Добавлем маркет контроллер
                $marketCache = new MarketCache();
                $marketCache->setTarget($drug->getDocumentID());
                $marketCache->setDocument(true);
                $em->persist($marketCache);
                $em->flush($marketCache);
                $em->refresh($marketCache);
                # Удаляем из имени всякую хрень
                $RusName = $drug->getRusName();
                $p = array('/<sup>(.*?)<\\/sup>/i', '/<sub>(.*?)<\\/sub>/i');
                $r = array('', '');
                $name = preg_replace($p, $r, $RusName);
                $first = mb_substr($name, 0, 2);
                //первая буква
                $last = mb_substr($name, 2);
                //все кроме первой буквы
                $last = mb_strtolower($last, 'UTF-8');
                $name = $first . $last;
                $output->writeln('<info>' . $name . '</info>');
                # Ищем в первом магазине и добавляем оттуда лекарства
                $array = $this->findShop_1($name);
                $c1 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('eapteka');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $em->flush();
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                }
                # Ищем во втором магазине и добавляем оттуда лекартсва
                $array = $this->findShop_2($name);
                $c2 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setManufacturer($pr['manufacturer']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('piluli');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $em->flush();
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                }
                # Ищем в третьем магазине и добавляем оттуда лекартсва
                $array = $this->findShop_3($name);
                $c3 = count($array);
                foreach ($array as $pr) {
                    $product = new MarketDrug();
                    $product->setCode($pr['code']);
                    $product->setTitle($pr['title']);
                    $product->setPrice($pr['price']);
                    $product->setManufacturer($pr['manufacturer']);
                    $product->setUrl($pr['url']);
                    $product->setGroupApt('zdravzona');
                    $em->persist($product);
                    $em->flush($product);
                    $em->refresh($product);
                    $marketCache->addDrug($product);
                    $output->writeln('<comment>' . $product->getTitle() . '</comment>');
                    $em->flush();
                }
                $output->writeln('<error>' . $c1 . ' - ' . $c2 . ' - ' . $c3 . '</error>');
            }
        }
        $output->writeln('+++ vidal:parser completed!');
    }