So I have created a session variable inside my edit action to prevent it from sending an email to the assigned supervisor every time the order is edited.
It seems that this works good, but instead I want it to send the mail once in a half hour to lower the amount of mails sent if a user keeps editing it in a short period of time. I also want to send a mail regardless of the half hour if the supervisor changes in the edit.
This is what I have so far;
public function editAction($id)
{
$request = $this->getRequest();
$session = $request->getSession();
$order = $em->getRepository('Order')->find($id);
$sessionName = $order . 'MailerSession';
//do some extra stuff...
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($order);
$em->flush();
if (false === $session->has($sessionName)) {
$this->get('bss.pmod.mailer')
->sendApprovalEmailMessage($object, $object->getFirstApprover(), 'first.approval.template');
}
$sessionData = array('order' => $order, 'supervisorId' => $order->getFirstApprover(), 'time' => new \DateTime(date('Y-m-d H:i:s')));
$session->set($sessionName, $sessionData);
return $this->redirectToRoute('show', array('id' => $order->getId()));
}
}
It seems like it's working by not sending a mail again in the same session. (Please don't hesitate to mention if something is still wrong by that part.)
But I have added the supervisorId and current dateTime in the sessionData, but how can I use it to prevent emails to be sent to the same supervisor in a half hour from the edit, and still send an email to a new assigned supervisor even it is still within the half hour?
I don't yet understand sessions this well. I'm a student doing Symfony and php now for about 4 months and it is the first time I need to implement a session?
Any help please?