public function activateTariffPrivateNgAction($tariff_id) { $em = $this->getDoctrine()->getManager(); $response = new Response(json_encode(array("result" => Tariff::activateTariffPrivateById($em, $tariff_id)))); $response->headers->set('Content-Type', 'application/json'); return $response; }
public static function activateTariffPrivateById($em, $id) { $em->getConnection()->beginTransaction(); try { $newTariff = $em->getRepository("RenovateMainBundle:Tariff")->find($id); $tariffs = Tariff::getTariffs($em, array('parentid' => 'true', 'userid' => $newTariff->getUserid(), 'active' => '1')); foreach ($tariffs as $tariff) { $tariff->cleanTariff($em); $em->remove($tariff); $em->flush(); } $newTariff->setActive(TRUE); $newTariff->setActivated(new \DateTime()); $em->persist($newTariff); $em->flush(); $em->getConnection()->commit(); return true; } catch (Exception $e) { $em->getConnection()->rollback(); throw $e; } }