public function checkUserEmailNgAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $response = new Response(json_encode(array("result" => User::checkUserEmail($em, $request->query->all()))));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 public static function addTariffPrivate($em, \Renovate\MainBundle\Entity\User $user, $parameters)
 {
     $em->getConnection()->beginTransaction();
     try {
         $tariffParent = $em->getRepository("RenovateMainBundle:Tariff")->find($parameters->id);
         $tariff = new Tariff();
         $tariff->setParentid($tariffParent->getId());
         $tariff->setUserid($user->getId());
         $tariff->setUser($user);
         $name = $parameters->edited == true ? $tariffParent->getName() . '+' : $tariffParent->getName();
         $tariff->setName($name);
         $tariff->setActive(FALSE);
         $tariff->setDiscount($tariffParent->getDiscount());
         $tariff->setSquaring($parameters->squaring);
         $tariff->setPayment(0);
         $tariff->setCreated(new \DateTime());
         $em->persist($tariff);
         $em->flush();
         $role = $em->getRepository("RenovateMainBundle:Role")->find($parameters->clientRole->id);
         $price = $tariff->calculatePrice($em, $role, $parameters->services);
         $tariffPrice = new TariffPrice();
         $tariffPrice->setTariffid($tariff->getId());
         $tariffPrice->setTariff($tariff);
         $tariffPrice->setRoleid($role->getId());
         $tariffPrice->setRole($role);
         $tariffPrice->setValue($price);
         $em->persist($tariffPrice);
         $em->flush();
         $tariff->setPayment($price * $tariff->getSquaring());
         $em->persist($tariff);
         $em->flush();
         $tariff->createTariffServices($em, $parameters);
         $em->getConnection()->commit();
         return $tariff;
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
 }
Example #3
0
 public static function addUser($em, $ef, $parameters)
 {
     $user = new User();
     $user->setUsername($parameters->username);
     $encoder = $ef->getEncoder($user);
     $password = $encoder->encodePassword($parameters->password, $user->getSalt());
     $user->setPassword($password);
     $user->setName($parameters->name);
     $user->setSurname($parameters->surname);
     $user->setPatronymic($parameters->patronymic);
     $user->setEmail($parameters->email);
     $user->setMobilephone($parameters->mobilephone);
     $user->setAddress($parameters->address);
     $user->setRegistered(new \DateTime());
     if (isset($parameters->adminUnit)) {
         $user->setAdminUnit($parameters->adminUnit);
     }
     if (isset($parameters->owner)) {
         $user->setOwner($parameters->owner);
     }
     if (isset($parameters->comments)) {
         $user->setComments($parameters->comments);
     }
     foreach ($parameters->rolesIds as $role_id) {
         $role = $em->getRepository("RenovateMainBundle:Role")->find($role_id);
         $role->addUser($user);
         $user->addRole($role);
         $em->persist($role);
     }
     $em->persist($user);
     $em->flush();
     return $user;
 }