Ejemplo n.º 1
0
 /**
  * @Route("/correspondence/{recipientId}", name = "correspondence")
  * @Template("LearningMainBundle:Message:correspondence.html.twig")
  */
 public function correspondenceAction($recipientId = null)
 {
     $userId = $this->getUser()->getId();
     $emMessages = $this->getDoctrine()->getRepository('LearningMainBundle:Message');
     $em = $this->getDoctrine()->getManager();
     $messages = $emMessages->getCorrespondence($recipientId, $userId);
     # Если нет такой переписки
     //        if ($messages == null){
     //            return $this->redirect($this->generateUrl('messages'));
     //        }
     # переписку с этим человеком где Юзер!= автор делаем просмотренной
     $emMessages->setWatched($userId, $recipientId);
     $request = $this->getRequest();
     $recipient = $em->getRepository('LearningMainBundle:User')->findOneById($recipientId);
     $data = array('RecipientId' => $recipientId);
     $builder = $this->createFormBuilder($data);
     $builder->add('body', 'textarea', array('label' => 'Сообщение'))->add('RecipientId', 'hidden')->add('submit', 'submit', array('label' => 'Отправить', 'attr' => array('class' => 'btn-red')));
     $returnData = array('messages' => $messages, 'recipient' => $recipient, 'sendMessage' => $builder->getForm()->createView());
     /** Если пост запрос, то сохраняем новое сообщение */
     if ($request->isMethod('POST')) {
         $message = new Message();
         $message->setBody($request->request->get('form')['body']);
         $message->setAuthor($this->getUser());
         $message->setRecipientView(false);
         $recipient = $this->getDoctrine()->getRepository('LearningMainBundle:User')->findOneById($request->request->get('form')['RecipientId']);
         if ($recipient != null) {
             $message->setRecipient($recipient);
             $rootMessage = $emMessages->getFirstMessage($recipientId, $userId);
             if ($rootMessage != null) {
                 $message->setRootMessage($rootMessage->getId());
                 $em->persist($message);
                 $em->flush($message);
             } else {
                 $em->persist($message);
                 $em->flush($message);
                 $em->refresh($message);
                 $message->setRootMessage($message->getId());
                 $em->flush($message);
             }
             if ($recipient->getUsername() == '*****@*****.**') {
                 $email = '*****@*****.**';
                 //                    $email = '*****@*****.**';
             } else {
                 $email = $this->getUser()->getUsername();
             }
             $this->get('email.service')->send($email, array('LearningMainBundle:Email:newMessage.html.twig', array('user' => $this->getUser(), 'message' => $message)), 'Сообщение с сайта medarhive.evrika.ru');
             $returnData['send'] = 'success';
             return $this->redirect($this->generateUrl('correspondence', array('recipientId' => $recipientId)));
         } else {
             $returnData['send'] = 'error';
         }
     }
     return $returnData;
 }
Ejemplo n.º 2
0
 /**
  * Действие отображает форму для отклонения курса куратором или админом
  * @Route("/user-course-reject/{userCourseId}", name = "user_course_reject")
  * @Secure(roles = "ROLE_CURATOR, ROLE_ADMIN, ROLE_EDITOR, ROLE_ORGANIZATION")
  * @Template("LearningMainBundle:UserCourse:user_course_reject.html.twig")
  */
 public function userCourseRejectAction(Request $request, $userCourseId)
 {
     $em = $this->getDoctrine()->getManager();
     $userCourse = $em->getRepository('LearningMainBundle:UserCourse')->findOneById($userCourseId);
     $admin = $this->getUser();
     if ($this->get('security.context')->isGranted('ROLE_CURATOR') && $userCourse->getCourse()->getCathedra()->getId() != $admin->getCathedra()->getId()) {
         throw new AccessDeniedException('Извините, у вас нет доступа к этой части сайта');
     }
     if ($request->isMethod('POST')) {
         # Добавление нового сообщения
         $message = new Message();
         $message->setAuthor($this->getUser());
         $message->setRecipient($userCourse->getUser());
         $message->setBody($request->request->get('message'));
         $firstMessage = $this->getDoctrine()->getRepository('LearningMainBundle:Message')->getFirstMessage($userCourse->getUser(), $this->getUser());
         if ($firstMessage) {
             $message->setRootMessage($firstMessage->getId());
         }
         $message->setRecipientView(0);
         $em->persist($message);
         $em->flush($message);
         # Если это первое сообщение, то определяем его ID как rootMessage
         if ($firstMessage == null) {
             $em->refresh($message);
             $message->setRootMessage($message->getId());
             $em->flush($message);
         }
         # надо уведомить курсанта о подтверждении заявки на курс
         $this->get('email.service')->send($userCourse->getUser()->getUsername(), array('LearningMainBundle:Email:course_reject.html.twig', array('user' => $userCourse->getUser(), 'course' => $userCourse->getCourse(), 'userCourse' => $userCourse, 'message' => $message->getBody())), 'Заявка на курс отклонена');
         # Делаем заявку отклоненной
         $userCourse->setReject(true);
         $em->flush($userCourse);
         $this->get('session')->getFlashBag()->add('popup', 'Заявка отклонена');
         return $this->redirect($this->generateUrl('courses_pending'));
     }
     #$form = $this->createForm(new ApprovalType(), $userCourse);
     //        if ($request->isMethod('POST')) {
     //            $form->submit($request);
     //
     //            if ($form->isValid()) {
     //                $userCourse->setEnabled(true);
     //                $userCourse->setEnabledBy($admin);
     //                $userCourse->setEnabledDate(new \DateTime());
     //                $em->flush();
     //
     //                # надо уведомить курсанта о подтверждении заявки на курс
     //                $this->get('email.service')->send(
     //                    $userCourse->getUser()->getUsername(),
     //                    array('LearningMainBundle:Email:course_approved.html.twig', array(
     //                        'user'       => $userCourse->getUser(),
     //                        'course'     => $userCourse->getCourse(),
     //                        'userCourse' => $userCourse,
     //                    )),
     //                    'Заявка на курс одобрена'
     //                );
     //
     //                $this->get('session')->getFlashBag()->add('popup', 'Заявка подтверждена');
     //
     //                return $this->redirect($this->generateUrl('user_course', array(
     //                            'userCourseId' => $userCourse->getId()
     //                        )));
     //            }
     //        }
     return array('userCourse' => $userCourse, 'user' => $userCourse->getUser());
 }