示例#1
0
 /**
  * @ApiDoc(
  *     statusCodes={
  *         204="Returned when successful",
  *         403="Returned when the user is not authorized",
  *         404="Returned when the contact does not exist on the client",
  *     },
  *     resource=true,
  *     description="Delete a contact",
  *     authentication=true,
  * )
  *
  * @param Entity\Client  $client
  * @param Entity\Contact $contact
  *
  * @Rest\Delete(path="/client/{clientId}/contact/{contactId}")
  *
  * @ParamConverter("client", class="CSBillClientBundle:Client", options={"id" : "clientId"})
  * @ParamConverter("contact", class="CSBillClientBundle:Contact", options={"id" : "contactId"})
  *
  * @return Response
  */
 public function deleteContactAction(Entity\Client $client, Entity\Contact $contact)
 {
     if (!$client->getContacts()->contains($contact)) {
         throw $this->createNotFoundException();
     }
     return $this->deleteEntity($contact);
 }
示例#2
0
 /**
  * @param Client $client
  * @param array  $originalContacts
  * @param array  $originalContactsDetails
  */
 private function removeClientContacts(Client $client, array $originalContacts, array $originalContactsDetails)
 {
     $entityManager = $this->getEm();
     foreach ($client->getContacts() as $originalContact) {
         foreach ($originalContacts as $key => $toDel) {
             if ($toDel->getId() === $originalContact->getId()) {
                 unset($originalContacts[$key]);
             }
         }
     }
     foreach ($originalContacts as $contact) {
         $client->removeContact($contact);
         $entityManager->remove($contact);
     }
     unset($contact, $key, $toDel);
     foreach ($client->getContacts() as $contact) {
         if (null === $contact->getId()) {
             continue;
         }
         foreach ($contact->getAdditionalDetails() as $originalContactDetail) {
             foreach ($originalContactsDetails[$contact->getId()] as $key => $toDel) {
                 if ($toDel->getId() === $originalContactDetail->getId()) {
                     unset($originalContactsDetails[$contact->getId()][$key]);
                 }
             }
         }
         foreach ($originalContactsDetails[$contact->getId()] as $contactDetail) {
             $entityManager->remove($contactDetail);
             $contact->removeAdditionalDetail($contactDetail);
         }
     }
 }