1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace FTTHBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Response;
- use FTTHBundle\Entity\ONU;
- use FTTHBundle\Entity\PreSale;
- use WebserviceBundle\Form\Type\RemoteClientType;
- use MapBundle\Form\Type\RemoteMapType;
- use FOS\RestBundle\Controller\Annotations\RouteResource;
- /**
- * CaptivePortal controller.
- */
- class CaptivePortalController extends Controller
- {
- public function portalAction(Request $request)
- {
- $client = $request->query->get('client');
- $psn = $request->query->get('psn');
- $preSale = $request->query->get('preSale');
- $preSales = $errors = array();
- $result = false;
- if(!is_null($client) && !is_null($psn)) {
- $em = $this->get("doctrine.orm.entity_manager");
- $preSales = $em->getRepository(PreSale::class)->findBy(array('clientId' => $client));
- $onu = $em->getRepository(ONU::class)->findOneBy(array('ponSerialNumber' => $psn));
-
- if(empty($preSales)) $errors[] = "We don't register a pending installation to this client.";
- if(is_null($onu)) $errors[] = "ONU doesn't exist.";
- if(!is_null($preSale) && !is_null($onu)) {
- $sale = $em->getRepository(PreSale::class)->findOneById($preSale);
- if($sale) {
- $this->updateOnu($sale->getClientId(), $sale->getProfile(), $onu, $sale->getAddress());
- $onu = $em->getRepository(ONU::class)->findOneBy(array('ponSerialNumber' => $psn));
- if($onu->getClientId() == $sale->getClientId() && $onu->getProfile() == $sale->getProfile()) {
- $result = true;
- $em->remove($sale);
- $em->flush();
- }
- }
- }
- }
- return $this->render('FTTHBundle:Portal:index.html.twig', array(
- 'result' => $result,
- 'errors' => $errors,
- 'preSales' => $preSales,
- 'client' => $client,
- 'psn' => $psn
- ));
- }
- private function updateOnu($clientId, $profile, $onu, $address) {
- $onu->setClientId($clientId);
- $onu->setProfile($profile);
- $em = $this->get("doctrine.orm.entity_manager");
- $em->persist($onu);
- $em->flush();
-
- }
- }
|