Exemple #1
0
 private function generateEmail(Client $client)
 {
     $domains = ['foo', 'bar', 'youla', 'boolus', 'lovesy', 'kool', 'ool', 'yahcafe', 'hillo'];
     $tdls = ['.com', '.biz', '.org', '.ca', '.fr', '.de'];
     $firstName = $client->getFirstName();
     $lastName = $client->getLastName();
     $part1 = strtolower($firstName . '.' . $lastName);
     $domain = $domains[array_rand($domains, 1)];
     $tdl = $tdls[array_rand($tdls, 1)];
     $email = $part1 . '@' . $domain . $tdl;
     $client->setEmail($email);
     return $client;
 }
 /**
  * This method will update a client
  *
  * @ApiDoc(
  *  section="Clients",
  *  resource=true,
  *  description="This method will update a client",
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized",
  *      404={
  *        "Returned when the posts are not found"
  *      }
  * }
  * )
  * @Extra\Route("/{id}")
  * @Extra\Method({"PUT"})
  * @ParamConverter("client", class="JdhmApi\Entity\Client")
  * @Rest\View()
  */
 public function updateClientAction(Client $client, Request $request)
 {
     $em = $this->get('doctrine')->getManager();
     $content = json_decode($request->getContent(), true);
     if (!$content) {
         throw new HttpException("No json data in body", 405);
     }
     $client->setFirstName($content['firstName']);
     $client->setLastName($content['lastName']);
     $client->setEmail($content['email']);
     if (array_key_exists('dateOfBirth', $content) && !empty($content['dateOfBirth'])) {
         $date = \DateTime::createFromFormat('d/m/Y', $content['dateOfBirth']);
         $client->setDateOfBirth($date);
     }
     $em->persist($client);
     $em->flush();
     return ['data' => $client];
 }