public function detailAction() { $id = $this->_params('id'); $calendar = $this->getServiceLocator()->get('rdvMapper')->getById($id); $form = new Contact(['dates' => [], 'times' => []]); $data = $calendar->toArray(); $data['full-date'] = $calendar->getDate()->format('d/m/Y H:i'); $date = Date::translate($calendar->getDate()->format('l d M Y \\à H\\h')); $form->setData($data); $request = $this->getRequest(); if ($request->isPost()) { $formValidator = new AdminContactValidator(); $form->setInputFilter($formValidator->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); try { $googleApi = $this->getServiceLocator()->get('calendar'); $requestDate = \DateTime::createFromFormat('d/m/Y H:i', $data['full-date'], new \DateTimeZone('Europe/Paris')); $event = new \Google_Service_Calendar_Event(array('summary' => $data['firstname'] . ' ' . $data['lastname'] . ' - ' . $data['phone'], 'description' => $data['comment'], 'start' => array('dateTime' => $requestDate->format(\Datetime::ATOM), 'timeZone' => 'Europe/Paris'), 'end' => array('dateTime' => $requestDate->modify('+ 1 hour')->format(\Datetime::ATOM), 'timeZone' => 'Europe/Paris'))); $calendarId = '*****@*****.**'; $event = $googleApi->events->insert($calendarId, $event); if (isset($data['email'])) { // Emailing $mail = new Mail($this->getServiceLocator()->get('mail')); $mail->addFrom('*****@*****.**'); $mail->addBcc($data['email']); $mail->setSubject('[osteo-defour.fr] Rendez-vous du - ' . \App\Services\Date::translate($requestDate->format('l d F Y \\à H:i')) . ' confirmé'); $mail->setTemplate(Mail::TEMPLATE_CONFIRMATION, ['firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'phone' => $data['phone'], 'email' => $data['email'], 'comment' => $data['comment'], 'date' => \App\Services\Date::translate($requestDate->format('l d F Y \\à H:i')), 'baseUrl' => '']); $mail->send(); $message = '<i class="fa fa-envelope"></i> Un email de confirmation a été envoyé au patient'; $this->getServiceLocator()->get('rdvMapper')->delete($id); } else { $message = '<i class="fa fa-exclamation-triangle"></i> Une confirmation téléphonique s\'impose'; $this->getServiceLocator()->get('rdvMapper')->fromArray(['id' => $calendar->id, 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'phone' => $data['phone'], 'email' => $data['email'], 'comment' => $data['comment'], 'date' => $requestDate->format('Y-m-d H:i:s'), 'status' => Rdv::STATUS_NEED_CONFIRM])->save(); } $this->flashMessenger()->addMessage('<p>Rendez-vous ajouté au calendrier !</p> <p>' . $message . '</p> '); } catch (Exception $e) { $this->flashMessenger()->addErrorMessage('<p>Un problème est survenu lors de l\'ajout au calendrier</p> '); } $this->redirect()->toRoute('App/admin'); } } return new ViewModel(array('date' => $date, 'form' => $form, 'calendar' => $calendar)); }
public function indexAction() { $calendar = $this->getServiceLocator()->get('calendar'); $config = $this->getServiceLocator()->get('config'); // build Dates $dates = [0 => 'Date']; $date = new \DateTime('now'); for ($i = 1; $i < 10; $i++) { $date = $date->modify('next monday'); $dates[$date->format('Ymd')] = \App\Services\Date::translate($date->format('l d F Y')); $date = $date->modify('next tuesday'); $dates[$date->format('Ymd')] = \App\Services\Date::translate($date->format('l d F Y')); } // build time $formData = ['dates' => $dates, 'times' => [0 => 'Heure', 9 => '9h00', 10 => '10h00', 11 => '11h00', 12 => '12h00', 13 => '13h00', 14 => '14h00', 15 => '15h00', 16 => '16h00', 17 => '17h00', 18 => '18h00', 19 => '19h00', 20 => '20h00']]; $form = new Contact($formData); $request = $this->getRequest(); if ($request->isPost()) { $formValidator = new ContactValidator($request->getPost()->toArray()); $form->setInputFilter($formValidator->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $date = \Datetime::createFromFormat('Ymd H', $data['date'] . ' ' . $data['time']); // save RDV in DB $rdvMapper = $this->getServiceLocator()->get('rdvMapper'); $rdv = $rdvMapper->fromArray(['email' => $data['email'], 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'status' => 0, 'date' => $date->format('Y-m-d H:i:s'), 'phone' => $data['phone'], 'comment' => $data['comment']])->save(); // Emailing $mail = new Mail($this->getServiceLocator()->get('mail')); $mail->addFrom($config['mail']['address']); $mail->addBcc($config['mail']['bcc']); $mail->setSubject('[osteo-defour.fr] Demande de RDV - ' . $data['firstname'] . ' ' . $data['lastname']); $mail->setTemplate(Mail::TEMPLATE_RDV, ['id' => $rdv->id, 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'phone' => $data['phone'], 'email' => $data['email'], 'comment' => $data['comment'], 'date' => \App\Services\Date::translate($date->format('l d F Y \\à H:i')), 'baseUrl' => $config['baseUrl']]); $mail->send(); $this->flashMessenger()->addMessage('<p>Demande de rendez-vous prise en compte.</p> <p>Nous vous confirmerons ce rendez-vous dans les plus brefs délais.</p> '); $this->redirect()->toRoute('App/default'); } else { $inputErrors = array_keys($form->getMessages()); foreach ($inputErrors as $input) { $form->get($input)->setAttribute('class', 'form-control has-error'); } } } return new ViewModel(['form' => $form]); }