Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $em = $container->get('doctrine')->getManager();
     $webDir = $container->get('kernel')->getRootDir() . '/../web/';
     $miniDir = $webDir . 'upload/publication-mini/';
     $this->checkDirectory($miniDir);
     # ресайзить все
     if ($input->getOption('all')) {
         $publications = $em->createQuery("\r\n\t\t\t\tSELECT p.imageFile\r\n\t\t\t\tFROM EvrikaMainBundle:Publication p\r\n\t\t\t\tWHERE p.imageFile is not null AND p.imageFile != ''\r\n\t\t\t")->getResult();
         foreach ($publications as $publication) {
             try {
                 $imgFile = $publication['imageFile'];
                 $origPath = $webDir . $imgFile['path'];
                 $miniPath = $miniDir . $imgFile['originalName'];
                 $thumbnailer = new Thumbnailer($origPath, $miniPath);
                 $thumbnailer->makeThumbnail(self::MAX_WIDTH);
             } catch (\Exception $e) {
             }
         }
     } elseif ($ids = $input->getArgument('ids')) {
         $repo = $em->getRepository('EvrikaMainBundle:Publication');
         sleep(2);
         // ждем пока изображение появится на сервере
         foreach ($ids as $id) {
             $publication = $repo->find($id);
             if ($imgFile = $publication->getImageFile()) {
                 try {
                     $origPath = $webDir . $imgFile['path'];
                     $miniPath = str_replace('/publication/', '/publication-mini/', $origPath);
                     $thumbnailer = new Thumbnailer($origPath, $miniPath);
                     $thumbnailer->makeThumbnail(self::MAX_WIDTH);
                 } catch (\Exception $e) {
                 }
             }
         }
         $output->writeln("Resized ids: " . implode(', ', $ids));
     }
 }
Esempio n. 2
0
 /**
  * Редактирует информацию о компании
  *
  * @Route("/company-edit/{groupId}", name = "company_edit", defaults = {"groupId" = 0})
  * @Secure(roles = "ROLE_COMPANY")
  */
 public function editGroupInfoAction($groupId)
 {
     $em = $this->getDoctrine()->getManager();
     $group = $em->getRepository('EvrikaMainBundle:Company')->find($groupId);
     $form = $this->createFormBuilder($group)->add('title', null, array('label' => 'Название компании'))->add('body', null, array('label' => 'Описание', 'attr' => array('class' => 'ckeditor_less')))->add('phone', null, array('label' => 'Телефон'))->add('fax', null, array('label' => 'Факс'))->add('website', null, array('label' => 'Сайт'))->add('legalAddress', null, array('label' => 'Юридический адрес'))->add('postAddress', null, array('label' => 'Фактический адрес'))->add('contactPerson', null, array('label' => 'Контактное лицо'))->add('contactPersonPosition', null, array('label' => 'Дожность'))->add('imageFile', 'iphp_file', array('label' => 'Загрузить логотип', 'required' => false))->getForm();
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         if (isset($request->files->get('form')['imageFile']['file'])) {
             $logo = $request->files->get('form')['imageFile']['file'];
             $thumbnailer = new Thumbnailer($logo);
             $thumbnailer->makeThumbnail(160, 160);
         }
         $form->bind($request);
         if ($form->isValid()) {
             $em->persist($group);
             $em->flush();
             return $this->redirect($this->generateUrl('company_edit', array('groupId' => $groupId)));
         }
         return $this->redirect($this->generateUrl('company_info', array('groupId' => $groupId)));
     }
     return $this->render('EvrikaMainBundle:Auth:company_edit.html.twig', array('form' => $form->createView(), 'companyId' => $groupId));
 }
Esempio n. 3
0
 /**
  * Обрабатывает загрузку изображения через CKEditor. Выводится специальный javascript для CKEditor
  *
  * @Route("/upload-image-ckeditor", name = "upload_image_ckeditor")
  */
 public function uploadImageAction()
 {
     $file = $this->getRequest()->files->get('upload');
     $error = null;
     $filename = null;
     $directory = null;
     if ($file) {
         $thumbnailer = new Thumbnailer($file);
         $thumbnailer->setCondition('ifbigger');
         $thumbnailer->makeThumbnail(450);
         $directory = $this->container->getParameter('upload_dir') . '/ckeditor';
         $filename = md5(time()) . rand(100, 999);
         $file->move($directory, $filename);
     } else {
         $error = 'Файл не передан';
     }
     return $this->render('EvrikaMainBundle:Post:upload_image.html.twig', array('error' => $error, 'src' => '/upload/ckeditor/' . $filename));
 }
Esempio n. 4
0
 private function resizePublicationPreviewImage(PreUpdateEventArgs $args)
 {
     if ($args->hasChangedField('imageFile') && is_array($args->getEntity()->getImageFile())) {
         $publication = $args->getEntity();
         $thumbnailer = new Thumbnailer($this->container->getParameter('upload_dir') . '/publication' . $publication->getImageFile()['fileName']);
         $thumbnailer->makeThumbnail(300);
     }
 }