/** * @Route("/provider/equipment-add-1/{subcategoryId}", name="equipment-add-1") */ public function equipmentAdd1Action(Request $request, $subcategoryId) { // build form //<editor-fold> $form = $this->createFormBuilder()->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 256)))))->add('price', 'number', array('constraints' => array(new NotBlank(), new Range(array('min' => 0)))))->add('deposit', 'number', array('constraints' => array(new NotBlank(), new Range(array('min' => 0)))))->add('value', 'number', array('constraints' => array(new NotBlank(), new Range(array('min' => 0)))))->add('priceBuy', 'number', array('required' => false, 'constraints' => array(new Range(array('min' => 0)))))->add('invoice', 'checkbox', array('required' => false))->add('industrial', 'checkbox', array('required' => false))->getForm(); //</editor-fold> $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); // get subcategory $subcat = $this->getDoctrineRepo('AppBundle:Subcategory')->find($subcategoryId); $user = $this->getUser(); // map fields, TODO: consider moving to Equipment's method //<editor-fold> map fields $eq = new Equipment(); $eq->setName($data['name']); $eq->setUser($user); $eq->setSubcategory($subcat); $eq->setPrice($data['price']); $eq->setValue($data['value']); $eq->setDeposit($data['deposit']); $eq->setPriceBuy($data['priceBuy']); $eq->setInvoice($data['invoice']); $eq->setIndustrial($data['industrial']); //</editor-fold> // save to db $em = $this->getDoctrine()->getManager(); $em->persist($eq); $em->flush(); $session = $request->getSession(); $session->set('EquipmentEditId', $eq->getId()); return $this->redirectToRoute('equipment-edit-2', array('id' => $eq->getId())); } return $this->render('provider\\equipment_edit_step1.html.twig', array('form' => $form->createView())); }
public function sendNewModifiedEquipmentInfoMessage(Request $request, Equipment $eq) { $to = $this->getParameter('admin_email'); $template = 'Emails/Equipment/new_modified_item.html.twig'; $url = $request->getSchemeAndHttpHost() . $this->generateUrl('admin_equipment_moderate', array('id' => $eq->getId())); $emailHtml = $this->renderView($template, array('equipment' => $eq, 'mailer_app_url_prefix' => $this->getParameter('mailer_app_url_prefix'), 'url' => $url)); $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname')); $message = Swift_Message::newInstance()->setSubject('New/modified equipment notification.')->setFrom($from)->setTo($to)->setBody($emailHtml, 'text/html'); $this->get('mailer')->send($message); }
public function sendApprovedRejectedInfoMessage(Request $request, Equipment $eq, $reason) { $template = 'Emails/admin/item_approved.html.twig'; if ($eq->getStatus() == Equipment::STATUS_REJECTED) { $template = 'Emails/admin/item_rejected.html.twig'; } $userLink = $request->getSchemeAndHttpHost() . $this->generateUrl('dashboard'); $eqLink = $request->getSchemeAndHttpHost() . $this->generateUrl('catchall', array('content' => $eq->getUrlPath())); $emailHtml = $this->renderView($template, array('item' => $eq, 'mailer_app_url_prefix' => $this->getParameter('mailer_app_url_prefix'), 'reason' => $reason, 'userLink' => $userLink, 'status_approved' => Equipment::STATUS_APPROVED, 'status_rejected' => Equipment::STATUS_REJECTED, 'itemLink' => $eqLink)); $subject = $eq->getStatus() == Equipment::STATUS_APPROVED ? "Dein Angebot wurde akzeptiert" : "Dein Angebot nicht akzeptiert wurde"; $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname')); $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($eq->getUser()->getEmail())->setBody($emailHtml, 'text/html'); $this->get('mailer')->send($message); }