/** * @Route("/clients/save", name="_admin_clients_save") * @Security("is_granted('ROLE_SELLER')") * @Template() */ public function saveClientAction() { $request = $this->get('request'); if (!$this->get('request')->isXmlHttpRequest()) { // Is the request an ajax one? return new Response("<b>Not an ajax call!!!" . "</b>"); } $logger = $this->get('logger'); try { $id = $request->get('id'); $fullName = $request->get('fullName'); $address = $request->get('address'); $phone = $request->get('phone'); $email = $request->get('email'); $cellPhone = $request->get('cellPhone'); $extraInformation = $request->get('extraInformation'); $em = $this->getDoctrine()->getManager(); $client = new Client(); if ($id != 0) { $client = $em->getRepository('Tech506CallServiceBundle:Client')->find($id); } else { $client = $em->getRepository('Tech506CallServiceBundle:Client')->findClient($phone, $cellPhone, $email); if (!isset($client)) { $client = new Client(); } } $client->setAddress($address); $client->setEmail($email); $client->setFullName($fullName); $client->setCellPhone($cellPhone); $client->setPhone($phone); $client->setExtraInformation($extraInformation); $em->persist($client); $em->flush(); return new Response(json_encode(array('error' => false, 'msg' => "Cliente guardado correctamente", 'id' => $client->getId()))); } catch (Exception $e) { $info = toString($e); $logger->err('Seller::getUsersList [' . $info . "]"); return new Response(json_encode(array('error' => true, 'message' => $info))); } }
private function getRelatedClient($request) { $client = null; $clientId = $request->get('clientId'); $phone = $request->get('phone'); $email = $request->get('email'); $cellPhone = $request->get('cellPhone'); if ($clientId == 0) { //No client found yet, try to find and create if not exists $client = $this->em->getRepository('Tech506CallServiceBundle:Client')->findClient($phone, $cellPhone, $email); } else { $client = $this->em->getRepository('Tech506CallServiceBundle:Client')->find($clientId); } if (!isset($client)) { $client = new Client(); } $client->setPhone($phone); $client->setCellPhone($cellPhone); $client->setEmail($email); $client->setFullName($request->get('fullName')); $client->setExtraInformation($request->get('extraInformation')); $client->setAddress(""); $this->em->persist($client); $this->em->flush($client); return $client; }