Beispiel #1
0
 /**
  * Add a new contact to a client.
  *
  * @param Request $request
  * @param Client  $client
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addcontactAction(Request $request, Client $client)
 {
     if (!$request->isXmlHttpRequest()) {
         throw $this->createNotFoundException();
     }
     $contact = new Contact();
     $contact->setClient($client);
     $form = $this->createForm(ContactType::class, $contact, ['allow_delete' => false]);
     $response = [];
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->save($contact);
         $response = ['status' => 'success', 'contact' => $contact];
         return $this->serializeResponse($response);
     } else {
         $response['status'] = 'failure';
     }
     $content = $this->renderView('CSBillClientBundle:Ajax:contact_add.html.twig', ['form' => $form->createView(), 'client' => $client]);
     $response['content'] = $content;
     return $this->json($response);
 }
Beispiel #2
0
 /**
  * Add contact.
  *
  * @param Contact $contact
  *
  * @return Client
  */
 public function addContact(Contact $contact)
 {
     $this->contacts[] = $contact;
     $contact->setClient($this);
     return $this;
 }
Beispiel #3
0
 /**
  * @ApiDoc(
  *     statusCodes={
  *         200="Returned when successful",
  *         400="Returned when the validation fails",
  *         403="Returned when the user is not authorized",
  *     },
  *     resource=true,
  *     description="Update a contact",
  *     input="CSBill\ClientBundle\Form\Contact",
  *     output={
  *         "class"="CSBill\ClientBundle\Entity\Contact",
  *         "groups"={"api"}
  *     },
  *     authentication=true,
  * )
  *
  * @param Request        $request
  * @param Entity\Client  $client
  * @param Entity\Contact $contact
  *
  * @ParamConverter("client", class="CSBillClientBundle:Client", options={"id" : "clientId"})
  * @ParamConverter("contact", class="CSBillClientBundle:Contact", options={"id" : "contactId"})
  *
  * @Rest\Patch(path="/client/{clientId}/contact/{contactId}")
  *
  * @return Response
  */
 public function updateContactAction(Request $request, Entity\Client $client, Entity\Contact $contact)
 {
     $contact->setClient($client);
     return $this->manageForm($request, 'contact', $contact);
 }