/**
  * @Route("/item/add")
  * @Template()
  */
 public function addAction(Request $request)
 {
     $user = $this->getUser();
     $item = new Item();
     $item->setCreatedBy($user);
     $form = $this->createForm(new ItemType(), $item);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($item);
         $em->flush();
         $this->addFlash('notice', 'Item added');
         return $this->redirectToRoute('app_app_index');
     }
     return array('form' => $form->createView());
 }
 /**
  * Test add and remove for userRequests
  */
 public function testAddRemoveActionLog()
 {
     $item = new Item();
     $user = new User();
     $this->assertEquals(0, $item->getUserRequests()->count());
     $item->setCreatedBy($user)->addUserRequest(new ItemRequest());
     $this->assertEquals(1, $item->getUserRequests()->count());
     $userRequest = $item->getUserRequests()->first();
     $item->removeUserRequest($userRequest);
     $this->assertEquals(0, $item->getUserRequests()->count());
 }
Example #3
0
 /**
  * Add item
  *
  * @param Item $item Item
  *
  * @return $this
  */
 public function addItem(Item $item)
 {
     $this->items->add($item->setCreatedBy($this));
     return $this;
 }