예제 #1
0
 /**
  * 
  * @Route("/admin/category/edit/{id}", name="admin_category_edit")
  */
 public function editAction(Request $request, $id)
 {
     $category = $this->getDoctrineRepo('AppBundle:Category')->find($id);
     if (!$category) {
         throw $this->createNotFoundException('No category found for id ' . $id);
     }
     $form = $this->createFormBuilder($category)->add('id', 'hidden')->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 256)))))->add('slug', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 256)), new Regex(array('pattern' => '/^[a-z][-a-z0-9]*$/', 'htmlPattern' => '/^[a-z][-a-z0-9]*$/', 'message' => 'This is not a valid slug')))))->add('position', 'integer', array('required' => false, 'constraints' => array(new Type(array('type' => 'integer')))))->getForm();
     //when the form is posted this method prefills entity with data from form
     $form->handleRequest($request);
     if ($form->isValid()) {
         //check if there is file
         $file = $request->files->get('upl');
         $em = $this->getDoctrine()->getManager();
         if ($file != null && $file->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($category, $this->getParameter('image_storage_dir'));
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%scategory\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'category' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $file->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($destFilename);
             $img->setExtension($file->getClientOriginalExtension());
             $img->setOriginalPath($file->getClientOriginalName());
             $img->setPath('category');
             $em->persist($img);
             $em->flush();
             $category->setImage($img);
         }
         // save to db
         $em->persist($category);
         $em->flush();
         return $this->redirectToRoute("admin_category_list");
     }
     return $this->render('admin/category/edit.html.twig', array('form' => $form->createView(), 'category' => $category));
 }
예제 #2
0
 public function getUrlPath()
 {
     $slug = Utils::slugify($this->getName());
     return sprintf("%s/%s", $this->getUfid(), $slug);
 }
 /**
  * @Route("talent/response/{id}", name="talent-response")
  */
 public function responseAction(Request $request, $id)
 {
     $inq = $this->getDoctrineRepo('AppBundle:TalentInquiry')->find($id);
     $eq = $inq->getTalent();
     // security check
     if ($this->getUser()->getId() !== $eq->getUser()->getId()) {
         return new Response('', Response::HTTP_FORBIDDEN);
     }
     // sanity check
     if ($inq->getAccepted() !== null) {
         // already responded
         return new Response('', Response::HTTP_FORBIDDEN);
     }
     if ($request->getMethod() === "POST") {
         $acc = intval($request->request->get('accept'));
         $msg = $request->request->get('message');
         $inq->setAccepted($acc);
         $inq->setResponse($msg);
         if ($acc > 0) {
             $inq->setUuid(Utils::getUuid());
         }
         $em = $this->getDoctrine()->getManager();
         $em->flush();
         // send email
         //<editor-fold>
         $provider = $eq->getUser();
         if ($inq->getUser() !== null) {
             $email = $inq->getUser()->getEmail();
         } else {
             $email = $inq->getEmail();
         }
         $url = null;
         if ($acc > 0) {
             $url = $request->getSchemeAndHttpHost() . $this->generateUrl('talent-confirmation', array('uuid' => $inq->getUuid()));
         }
         $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname'));
         $emailHtml = $this->renderView('Emails\\talent\\mail_to_user_confirm_offer_accepted.html.twig', array('mailer_app_url_prefix' => $this->getParameter('mailer_app_url_prefix'), 'provider' => $provider, 'inquiry' => $inq, 'talent' => $eq, 'url' => $url));
         $message = Swift_Message::newInstance()->setSubject('Du hast soeben eine Anfrage erhalten')->setFrom($from)->setTo($email)->setBody($emailHtml, 'text/html');
         $this->get('mailer')->send($message);
         //</editor-fold>
         return $this->redirectToRoute('dashboard');
     }
     return $this->render('talent-booking/response.html.twig', array('talent' => $eq, 'inquiry' => $inq));
 }
예제 #4
0
 /**
  * @Route("equipment-image", name="equipment-image")
  */
 public function equipmentImage(Request $request)
 {
     $file = $request->files->get('upl');
     if ($file->isValid()) {
         $session = $request->getSession();
         $eqFiles = $session->get('EquipmentAddFileArray');
         if (count($eqFiles) < 3) {
             $uuid = Utils::getUuid();
             $path = $this->getParameter('image_storage_dir') . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
             $name = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $fullPath = $path . $name;
             $f = $file->move($path, $name);
             $ef = array($uuid, $file->getClientOriginalName(), strtolower($file->getClientOriginalExtension()), $fullPath);
             array_push($eqFiles, $ef);
             $session->set('EquipmentAddFileArray', $eqFiles);
         }
     }
     return new Response($status = Response::HTTP_OK);
 }
 /**
  * 
  * @Route("/admin/testimonials/edit/{id}", name="admin_testimonials_edit")
  */
 public function editAction(Request $request, $id)
 {
     $testimonial = $this->getDoctrineRepo('AppBundle:Testimonial')->find($id);
     if (!$testimonial) {
         throw $this->createNotFoundException('No $testimonial found for id ' . $id);
     }
     $form = $this->createFormBuilder($testimonial)->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('id', 'hidden')->add('description', 'textarea', array('constraints' => array(new NotBlank(), new Length(array('max' => 500)))))->add('place', 'text', array('constraints' => array(new NotBlank())))->add('age', 'integer', array('required' => true, 'constraints' => array(new Type(array('type' => 'integer')))))->add('position', 'integer', array('required' => false, 'constraints' => array(new Type(array('type' => 'integer')))))->getForm();
     //when the form is posted this method prefills entity with data from form
     $form->handleRequest($request);
     if ($form->isValid()) {
         //check if there is file
         $file = $request->files->get('upl');
         $em = $this->getDoctrine()->getManager();
         if ($file != null && $file->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($testimonial, $this->getParameter('image_storage_dir'));
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%sblog\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'testimonials' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $file->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($file->getClientOriginalName());
             $img->setExtension($file->getClientOriginalExtension());
             $img->setPath('testimonials');
             $em->persist($img);
             $em->flush();
             $testimonial->setImage($img);
         }
         $em->persist($testimonial);
         $em->flush();
         return $this->redirectToRoute("admin_testimonials_list");
     }
     return $this->render('admin/testimonials/edit.html.twig', array('form' => $form->createView(), 'testimonial' => $testimonial));
 }
예제 #6
0
 public function getUrlPath()
 {
     $s = Utils::slugify($this->getName());
     return "{$this->id}/{$s}";
 }
예제 #7
0
<?php

namespace AppBundle\Utils;

use Cocur\Slugify\Slugify;
class Utils
{
    private static $slugifier;
    static function init()
    {
        self::$slugifier = new Slugify();
    }
    public static function getUuid()
    {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    }
    public static function slugify($s)
    {
        return self::$slugifier->slugify($s);
    }
}
Utils::init();
예제 #8
0
 protected function sendRateReminders(DateTime $datetime)
 {
     // users
     $this->logger->debug('sending RATE reminders for USERS');
     $es = $this->em->getRepository('AppBundle:EquipmentBooking')->getAllForRateUserReminder($datetime);
     $ts = $this->em->getRepository('AppBundle:TalentBooking')->getAllForRateUserReminder($datetime);
     $bookings = array_merge($es, $ts);
     foreach ($bookings as $bk) {
         try {
             $inq = $bk->getInquiry();
             if (get_class($bk) === 'AppBundle\\Entity\\EquipmentBooking') {
                 $eq = $inq->getEquipment();
                 $tmpl = 'Emails\\mail_to_user_rate_provider.html.twig';
                 $route = 'rate-equipment';
             } else {
                 $eq = $inq->getTalent();
                 $tmpl = 'Emails\\talent\\mail_to_user_rate_provider.html.twig';
                 $route = 'talent-rate-talent';
             }
             $provider = $eq->getUser();
             $uuid = Utils::getUuid();
             if ($inq->getUser() !== null) {
                 $email = $inq->getUser()->getEmail();
             } else {
                 $email = $inq->getEmail();
             }
             $url = $this->appUrlPrefix . $this->router->generate($route, array('uuid' => $uuid));
             $emailHtml = $this->templating->render($tmpl, array('mailer_app_url_prefix' => $this->appUrlPrefix, 'inquiry' => $inq, 'provider' => $provider, 'item' => $eq, 'url' => $url));
             $message = Swift_Message::newInstance()->setSubject('Du hast soeben eine Anfrage erhalten')->setFrom($this->from)->setTo($email)->setBody($emailHtml, 'text/html');
             $this->mailer->send($message);
             $bk->setNoticeRateUserAt(new DateTime());
             if (get_class($bk) === 'AppBundle\\Entity\\EquipmentBooking') {
                 $bk->setRateEquipmentUuid($uuid);
             } else {
                 $bk->setRateTalentUuid($uuid);
             }
             $this->em->flush();
             $msg = sprintf("\t%s, from-date: %s", $email, $inq->getFromAt()->format("Y-m-d H:i:s"));
             $this->logger->debug($msg);
         } catch (Exception $e) {
             $msg = sprintf("\t%s, FAILED", $email);
             $this->logger->error($msg);
             $this->logger->error($e->getTraceAsString());
         }
     }
     // providers
     $this->logger->debug('sending RATE reminders for PROVIDERS');
     $es = $this->em->getRepository('AppBundle:EquipmentBooking')->getAllForRateProviderReminder($datetime);
     $ts = $this->em->getRepository('AppBundle:TalentBooking')->getAllForRateProviderReminder($datetime);
     $bookings = array_merge($es, $ts);
     foreach ($bookings as $bk) {
         try {
             $inq = $bk->getInquiry();
             if (get_class($bk) === 'AppBundle\\Entity\\EquipmentBooking') {
                 $eq = $inq->getEquipment();
                 $tmpl = 'Emails\\mail_to_provider_rate_user.html.twig';
                 $route = 'rate-user';
             } else {
                 $eq = $inq->getTalent();
                 $tmpl = 'Emails\\talent\\mail_to_provider_rate_user.html.twig';
                 $route = 'talent-rate-user';
             }
             $provider = $eq->getUser();
             $uuid = Utils::getUuid();
             $url = $this->appUrlPrefix . $this->router->generate($route, array('uuid' => $uuid));
             $email = $provider->getEmail();
             $emailHtml = $this->templating->render($tmpl, array('mailer_app_url_prefix' => $this->appUrlPrefix, 'provider' => $provider, 'inquiry' => $inq, 'url' => $url));
             $message = Swift_Message::newInstance()->setSubject('Du hast soeben eine Anfrage erhalten')->setFrom($this->from)->setTo($email)->setBody($emailHtml, 'text/html');
             $this->mailer->send($message);
             $bk->setNoticeRateProviderAt(new DateTime());
             $bk->setRateUserUuid($uuid);
             $this->em->flush();
             $msg = sprintf("\t%s, from-date: %s", $email, $inq->getFromAt()->format("Y-m-d H:i:s"));
             $this->logger->debug($msg);
         } catch (Exception $e) {
             $msg = sprintf("\t%s, FAILED", $email);
             $this->logger->error($msg);
             $this->logger->error($e->getTraceAsString());
         }
     }
 }