/**
  * {@inheritDoc}
  */
 public function load(ObjectManager $om)
 {
     $p = 0;
     foreach ($this->getData('AdPrice') as $o) {
         $obj = new AdPrice();
         $obj->setMainpage($o['mainpage']);
         $obj->setSubpages($o['subpages']);
         $obj->setPeriod($o['period']);
         $obj->setDuration($o['duration']);
         $obj->setPrice($o['price']);
         $om->persist($obj);
         $this->setReference('ad-price-' . ++$p, $obj);
     }
     $om->flush();
     foreach ($this->getData('AdType') as $o) {
         $obj = new AdType();
         $obj->setId($o['id']);
         $obj->setName($o['name']);
         $obj->setDefinition($o['definition']);
         foreach (range(1, $p) as $i) {
             $obj->addPrice($this->getReference('ad-price-' . $i));
         }
         $this->setReference('ad-type-' . $o['id'], $obj);
         $om->persist($obj);
     }
     $om->flush();
     foreach ($this->getData('Client') as $o) {
         $obj = new Client();
         $obj->setName($o['name']);
         $obj->setEmail($o['email']);
         $obj->setPhone($o['phone']);
         $obj->setInvoiceName($o['invoice_name']);
         $obj->setInvoiceNip($o['invoice_nip']);
         $obj->setInvoiceAddress($o['invoice_address']);
         $this->setReference('ad-client-' . $o['name'], $obj);
         $om->persist($obj);
     }
     $om->flush();
     foreach ($this->getData('Ad') as $o) {
         $obj = new Ad();
         $obj->setEnabled($o['enabled']);
         $obj->setType($this->getReference('ad-type-' . $o['type']));
         $obj->setOption($this->getReference('ad-price-' . $o['option']));
         $obj->setClient($this->getReference('ad-client-' . $o['client']));
         $obj->setLeadsTo($o['leads_to']);
         $def = $obj->getType()->getDefinition();
         $forig = sprintf('%s%dx%d/%s', $this->getBinariesPath(), $def['width'], $def['height'], $o['uploaded_file']);
         $fcopy = $this->getBinariesPath() . 'copy.' . $o['uploaded_file'];
         copy($forig, $fcopy);
         $file = new UploadedFile($fcopy, $o['uploaded_file'], mime_content_type($fcopy), filesize($fcopy), null, true);
         $obj->setUploadRootDir($this->container->get('kernel')->getRootDir() . '/../web/');
         $obj->setUploadedFile($file);
         $om->persist($obj);
         $title = sprintf('%s - %s landing page', strtoupper($file->getExtension()), $obj->getLeadsTo() === null ? 'NO' : 'WITH');
         $obj->setTitle($title);
         $om->persist($obj);
     }
     $om->flush();
 }
Example #2
0
 public function updateObject(Ad $object)
 {
     $path = $object->getPath();
     if (!preg_match('|^https?://|', $path)) {
         $object->setUploadRootDir($this->getConfigurationPool()->getContainer()->get('kernel')->getRootDir() . '/../web/');
         $object->upload('setPath');
     }
 }
 /**
  * Returns ad data as a simple array, useful for ajax usage
  * @param Ad $ad
  * @return array
  */
 public static function getAdData(Ad $ad, Container $container)
 {
     $path = $ad->getPath();
     $src = null;
     $href = null;
     if ($ad->getLeadsTo() !== null) {
         $href = $container->get('router')->generate('_sar_landing_page', array('slug' => $ad->getSlug()), true);
     }
     if (preg_match('|^https?://|', $path)) {
         $src = $path;
     } else {
         $src = $container->get('router')->generate('_sar_file', array('slug' => $ad->getSlug()), true);
     }
     return array('filetype' => preg_match('/\\.swf$/', $ad->getPath()) ? 'flash' : 'image', 'pos' => preg_replace('/\\D/', '', microtime()), 'slug' => $ad->getSlug(), 'type' => $ad->getType()->getId(), 'title' => $ad->getTitle(), 'params' => $ad->getType()->getDefinition(), 'src' => $src, 'href' => $href);
 }