public function getMyPaymentsCountNgAction() { $em = $this->getDoctrine()->getManager(); $response = new Response(json_encode(array("result" => Payment::getUserPaymentsCount($em, $this->getUser()->getId())))); $response->headers->set('Content-Type', 'application/json'); return $response; }
public static function import($em, $document) { $result = false; if ($document->isCSV()) { $url = $document->getPath(); $file = fopen($url, "r"); while (($data = fgetcsv($file, 8000, "\t")) !== FALSE) { $user = $em->getRepository("RenovateMainBundle:User")->findOneByUsername($data[5]); if ($user != NULL) { $payment = new Payment(); $payment->setUserid($user->getId()); $payment->setUser($user); $payment->setName($data[1]); $payment->setAmount($data[2]); $payment->setPersonalBalance($data[3]); $payment->setBuildingBalance($data[4]); $payment->setCreated(new \DateTime($data[0])); $em->persist($payment); $em->flush(); } } $result = true; } $document->unlink(); return $result; }