Пример #1
0
 /**
  * @Route("/create", name="freedom_group_create")
  * @Template()
  */
 public function createAction()
 {
     $group = new Groups();
     $form = $this->createForm(new GroupsCreateType(), $group);
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $group->setUser($this->getUser());
             $userbelonggroup = new Userbelonggroup();
             $userbelonggroup->setUser($this->getUser());
             $userbelonggroup->setRole(1);
             $userbelonggroup->setAccepted(true);
             $userbelonggroup->setGroup($group);
             $group->addUserbelonggroups($userbelonggroup);
             $em = $this->getDoctrine()->getManager();
             $em->persist($group);
             $em->flush();
             return $this->redirect($this->generateUrl('freedom_group_details', array('id' => $group->getId())));
         }
     }
     return array('form' => $form->createView());
 }
Пример #2
0
 /**
  * Create a Belong Group entity.
  *
  * @View(statusCode=201, serializerEnableMaxDepthChecks=true)
  *
  * @param Request $request
  * @param $group
  *
  * @return Response
  *
  */
 public function postUserbelonggroupsAction(Request $request, Groups $group)
 {
     try {
         $em = $this->getDoctrine()->getManager();
         $userbelonggroup = new Userbelonggroup();
         $userbelonggroup->setUser($this->getUser());
         $userbelonggroup->setGroup($group);
         $userbelonggroup->setRole(2);
         if ($group->getPrivate() == false) {
             $userbelonggroup->setAccepted(true);
         }
         $entity = $em->getRepository('FreedomUserBundle:Userbelonggroup')->findOneBy(array('user' => $this->getUser(), 'group' => $group));
         if ($entity == null) {
             // if ($form->isValid()) {
             $em->persist($userbelonggroup);
             $em->flush();
             if ($group->getPrivate() == false) {
                 // return $userbelonggroup;
                 return array('type' => 'success', 'alert' => 'alert-success', 'message' => 'You are now part of the group!', 'data' => $userbelonggroup);
             } else {
                 return array('type' => 'private', 'alert' => 'alert-success', 'message' => 'Your request has been sent to the owner of the group!');
             }
             // }
         }
         // return FOSView::create(array('errors' => 'Already exist'), Codes::HTTP_INTERNAL_SERVER_ERROR);
         return array('type' => 'warning', 'alert' => 'alert-warning', 'message' => 'You already requested for this group');
     } catch (\Exception $e) {
         return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
     }
 }