Ejemplo n.º 1
0
 public function sendOpticRegisteredEmailMessage(Optic $optic)
 {
     //envio el email con la clave
     $message = \Swift_Message::newInstance()->setSubject('Bienvenido a core')->setFrom(array('*****@*****.**' => 'Core avisos'))->setTo($optic->getEmail())->setBody($this->templating->render('FrontBundle:Registration:register.email.optic.html.twig', array('nombre' => $optic->getName(), 'email' => $optic->getEmail(), 'hss_validacion' => md5($optic->getEmail() . 'corekey' . $optic->getId()))), 'text/html');
     //Presencia en la plataforma
     if ($optic->getPack()->getId() == 2) {
         $html = $this->templating->render('FrontBundle:Registration/Contract:plataforma.html.twig', array('optic' => $optic));
         $html2pdf = $this->html2pdf_factory->create();
         $html2pdf->WriteHTML($html);
         $filename = 'contrato_presencia-plataforma_' . $optic->getId() . '-' . $optic->getPack()->getId() . '.pdf';
         $fileDir = $this->kernel->getRootDir() . '/../web/uploads/documents/' . $filename;
         $html2pdf->Output($fileDir, 'F');
         $message->attach(\Swift_Attachment::fromPath($fileDir));
     }
     //Pack Internet Plus
     if ($optic->getPack()->getId() == 3) {
         $html = $this->templating->render('FrontBundle:Registration/Contract:plus.html.twig', array('optic' => $optic));
         $html2pdf = $this->html2pdf_factory->create();
         $html2pdf->WriteHTML($html);
         $filename = 'contrato_internet-plus_' . $optic->getId() . '-' . $optic->getPack()->getId() . '.pdf';
         $fileDir = $this->kernel->getRootDir() . '/../web/uploads/documents/' . $filename;
         $html2pdf->Output($fileDir, 'F');
         $message->attach(\Swift_Attachment::fromPath($fileDir));
     }
     //Pack Internet Total
     if ($optic->getPack()->getId() == 4) {
         $html = $this->templating->render('FrontBundle:Registration/Contract:total.html.twig', array('optic' => $optic));
         $html2pdf = $this->html2pdf_factory->create();
         $html2pdf->WriteHTML($html);
         $filename = 'contrato_internet-total_' . $optic->getId() . '-' . $optic->getPack()->getId() . '.pdf';
         $fileDir = $this->kernel->getRootDir() . '/../web/uploads/documents/' . $filename;
         $html2pdf->Output($fileDir, 'F');
         $message->attach(\Swift_Attachment::fromPath($fileDir));
     }
     $this->mailer->send($message);
 }
Ejemplo n.º 2
0
 public function importOptics(Import $entity, $output)
 {
     $factory = $this->container->get('security.encoder_factory');
     $encoder = $factory->getEncoder(new Optic());
     $em = $this->container->get('doctrine')->getManager();
     $role = $em->getRepository('CoreBundle:Role')->findOneByRole('ROLE_OPTIC');
     $sql = ' SELECT o.id, o.id_usuario, o.id_pack, o.id_codigo_postal, o.nombre, o.asociacion, o.codigo, o.cuenta, o.recibir_paquete, ' . ' o.direccion, o.provincia, o.cp, o.lat, o.lang, o.descripcion, o.url_img, slug, o.acu_visitas, o.acu_ventas, o.extension_img, ' . ' o.autor, o.autor_descripcion, o.acu_productos, o.acu_servicios, o.url_facebook, o.url_twitter, o.tiene_web, o.newsletter, ' . ' o.recibir_informacion, o.meta_titulo, o.meta_descripcion, o.meta_keywords, o.bank_account_token, o.bank_account_time, ' . ' o.responsable, o.razon, o.cif, u.email, u.password, u.username, u.salt, u.estado, u.fecha_alta ' . ' FROM  `optica` AS o ' . ' LEFT JOIN usuario AS u ON o.id_usuario = u.id ' . ' ORDER BY o.id ' . ' LIMIT ' . $entity->getLimitStart() . ', ' . $entity->getLimitEnd();
     $title = null;
     $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link));
     $resultado = $link->query($sql);
     if (mysqli_num_rows($resultado) > 0) {
         $x = 0;
         $count = 0;
         $count2 = 0;
         while ($fila = mysqli_fetch_assoc($resultado)) {
             $x++;
             print_r($x . '-' . utf8_encode($fila['nombre']));
             echo PHP_EOL;
             $user = new Optic();
             if ($fila['id_usuario'] == 1) {
                 $count++;
                 $username = $this->slugify(utf8_encode($fila['nombre']));
                 $user->setUsername($username);
                 $user->setEmail($username . $fila['id'] . '@optisoop.com');
             } else {
                 $count2++;
                 $user->setUsername(utf8_encode($fila['username']));
                 $user->setEmail(utf8_encode($fila['email']));
             }
             $user->setName(utf8_encode($fila['nombre']));
             $user->setCreated(new DateTime($fila['fecha_alta']));
             $user->addRole($role);
             $user->setPassword($fila['password']);
             $user->setSalt($fila['salt']);
             $user->setDescription(utf8_encode($fila['descripcion']));
             $user->setSlug($this->slugify(utf8_encode($fila['nombre'])));
             $user->setLatitude($fila['lat']);
             $user->setLongitude($fila['lang']);
             $user->setAssociation(utf8_encode($fila['asociacion']));
             $user->setBankAccountNumber($fila['cuenta']);
             $user->setAddress(utf8_encode($fila['direccion']));
             $user->setPostalCode($fila['cp']);
             $user->setCity(utf8_encode($fila['provincia']));
             $user->setFacebookUrl($fila['url_facebook']);
             $user->setTwitterUrl($fila['url_twitter']);
             if (utf8_encode($fila['meta_titulo']) != '') {
                 $user->setMetaTitle($fila['meta_titulo']);
             } else {
                 $user->setMetaTitle($fila['nombre']);
             }
             if (utf8_encode($fila['meta_descripcion']) != '') {
                 $user->setMetaDescription($fila['meta_descripcion']);
             } else {
                 $user->setMetaDescription($fila['descripcion']);
             }
             if (utf8_encode($fila['meta_keywords']) != '') {
                 $user->setMetaTags($fila['meta_keywords']);
             } else {
                 $user->setMetaTags($fila['nombre']);
             }
             //pack
             $pack = $em->getRepository('CoreBundle:Pack')->find($fila['id_pack']);
             $user->setPack($pack);
             //state and country
             $this->setStateAndCountry($fila, $user);
             $em->persist($user);
             $em->flush();
             //                print_r($fila);
             //image
             if ($fila['url_img'] != '') {
                 $dir = '/home/sebastian/www/optisoop/src/Symfony/web/optisoop/uploads/documents';
                 $imagePath = '';
                 $absoluteImagePath = $dir . '/' . utf8_encode($fila['url_img']);
                 if (file_exists($absoluteImagePath . '.jpeg')) {
                     $imagePath = utf8_encode($fila['url_img']) . '.jpeg';
                 }
                 if (file_exists($absoluteImagePath . '.jpg')) {
                     $imagePath = utf8_encode($fila['url_img']) . '.jpg';
                 }
                 if (file_exists($absoluteImagePath . '.gif')) {
                     $imagePath = utf8_encode($fila['url_img']) . '.gif';
                 }
                 if (file_exists($absoluteImagePath . '.png')) {
                     $imagePath = utf8_encode($fila['url_img']) . '.png';
                 }
                 //Thumb
                 $imagePathThumb = '';
                 $absoluteImagePathThumb = $dir . '/' . utf8_encode($fila['url_img']) . '_260.jpg';
                 if (file_exists($absoluteImagePathThumb)) {
                     $imagePathThumb = utf8_encode($fila['url_img']) . '_260.jpg';
                 }
                 $imagePathThumb2 = '';
                 $absoluteImagePathThumb2 = $dir . '/' . utf8_encode($fila['url_img']) . '_142.jpg';
                 if (file_exists($absoluteImagePathThumb2)) {
                     $imagePathThumb2 = utf8_encode($fila['url_img']) . '_142.jpg';
                 }
                 print_r($dir . '/' . $imagePath);
                 echo PHP_EOL;
                 @mkdir(__DIR__ . '/../../../../../web/uploads/images/profile');
                 @mkdir(__DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId());
                 @mkdir(__DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId() . '/thumbnail');
                 copy($dir . '/' . $imagePath, __DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId() . '/' . $imagePath);
                 if ($imagePathThumb != '') {
                     copy($dir . '/' . $imagePathThumb, __DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId() . '/thumbnail/' . $imagePathThumb);
                 }
                 if ($imagePathThumb2 != '') {
                     copy($dir . '/' . $imagePathThumb2, __DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId() . '/thumbnail/' . $imagePathThumb2);
                 }
                 $image0 = new Image();
                 $image0->setPath($imagePath);
                 $user->setImage($image0);
                 $em->persist($image0);
             }
             $em->flush();
         }
         $output->writeln('Opticas sin usuarios = ' . $count . ' ');
         $output->writeln('Opticas con usuarios = ' . $count2 . ' ');
     } else {
         $output->writeln('No se ha procesado ningun usuario');
     }
 }