public function sendAction() { $entityManager = $this->getEntityManager(); //sender $from = $this->zfcUserAuthentication()->getIdentity(); //message form $form = new MessageForm($entityManager); //message entity $messages = new Messages(); //receiver entity $tos = (array) $_POST['to']; $subject = $_POST['subject']; $message = $_POST['message']; // var_dump($tos);die; //persist to message $messages->setFrom($from); $messages->setSubject($subject); $messages->setMessage($message); $entityManager->persist($messages); $entityManager->flush(); //persist to receiver $receiver = $entityManager->getRepository('EduUser\\Entity\\User')->findBy(array('id' => $tos)); /// var_dump($receiver);die; foreach ($receiver as $to) { $this->sendMessage($messages, $to); } $this->flashMessenger()->addSuccessMessage('Message Sent Successfully!'); return $this->redirect()->toRoute('messages', array('controller' => 'messages', 'action' => 'inbox')); return new ViewModel(); }
public function teachersAction() { $entityManager = $this->getEntityManager(); //get the current session $session = $this->getServiceLocator()->get('Admin\\Service\\SettingsService')->getCurrentSession()->getId(); //get the current user id $from = $this->zfcUserAuthentication()->getIdentity(); //get the current user class $class = $entityManager->getRepository('Admin\\Entity\\Student')->findOneby(array('user' => $from->getId())); $currentclass = $class->getCurrentClass()->getId(); //get all the teachers in the user current class in current session $class = $entityManager->getRepository('Admin\\Entity\\Teacher')->findBy(array('session' => $session, 'class' => $currentclass)); if ($this->getRequest()->isPost()) { //sender $from = $this->zfcUserAuthentication()->getIdentity(); //message entity $messages = new Messages(); $tos = (array) $_POST['to']; $subject = $_POST['subject']; $message = $_POST['message']; // var_dump($tos);die; //persist to message $messages->setFrom($from); $messages->setSubject($subject); $messages->setMessage($message); $entityManager->persist($messages); $entityManager->flush(); //persist to receiver $receiver = $entityManager->getRepository('EduUser\\Entity\\User')->findBy(array('id' => $tos)); /// var_dump($receiver);die; foreach ($receiver as $to) { $this->sendMessage($messages, $to); } $this->flashMessenger()->addSuccessMessage('Message Sent Successfully!'); return $this->redirect()->toRoute('studentspm', array('controller' => 'studentspm', 'action' => 'inbox')); } return new ViewModel(array('class' => $class)); }