123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace FTTHBundle\Controller;
- use FTTHBundle\Entity\ONU;
- use FTTHBundle\Form\ONUType;
- use FOS\RestBundle\Controller\Annotations\RouteResource;
- use FOS\RestBundle\Controller\Annotations\View;
- use FOS\RestBundle\Util\Codes;
- use FOS\RestBundle\View\View as FOSView;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use WebserviceBundle\Controller\RESTController;
- use FOS\RestBundle\Controller\Annotations\Patch;
- /**
- * ONU controller.
- * @RouteResource("ONU")
- */
- class ONURESTController extends RESTController
- {
- /**
- * @return string Retorna el nombre de la Entity de trabajo.
- */
- public function getRepository()
- {
- return 'FTTHBundle:ONU';
- }
- /**
- * @return string Retorna el tipo de la clase.
- */
- public function getFormEntityType()
- {
- return get_class(new ONUType());
- }
- // /**
- // * Create a ONU entity.
- // *
- // * @View(statusCode=201, serializerEnableMaxDepthChecks=true)
- // *
- // * @param Request $request
- // *
- // * @return Response
- // *
- // */
- // public function postAction(Request $request)
- // {
- // $entity = new ONU();
- // $form = $this->createForm(get_class(new ONUType()), $entity, array("method" => $request->getMethod()));
- // $this->removeExtraFields($request, $form);
- // $form->handleRequest($request);
- //
- // if ($form->isValid()) {
- // $em = $this->getDoctrine()->getManager();
- // $em->persist($entity);
- // $em->flush();
- //
- // return $entity;
- // }
- //
- // return FOSView::create(array('errors' => $form->getErrors()), Codes::HTTP_INTERNAL_SERVER_ERROR);
- // }
- //
- // /**
- // * Update a ONU entity.
- // *
- // * @View(serializerEnableMaxDepthChecks=true)
- // *
- // * @param Request $request
- // * @param $entity
- // *
- // * @return Response
- // */
- // public function putAction(Request $request, ONU $entity)
- // {
- // try {
- // $em = $this->getDoctrine()->getManager();
- // $request->setMethod('PATCH'); //Treat all PUTs as PATCH
- // $form = $this->createForm(get_class(new ONUType()), $entity, array("method" => $request->getMethod()));
- // $this->removeExtraFields($request, $form);
- // $form->handleRequest($request);
- // if ($form->isValid()) {
- // $em->flush();
- //
- // return $entity;
- // }
- //
- // return FOSView::create(array('errors' => $form->getErrors()), Codes::HTTP_INTERNAL_SERVER_ERROR);
- // } catch (\Exception $e) {
- // return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
- // }
- // }
- //
- // /**
- // * Partial Update to a ONU entity.
- // *
- // * @View(serializerEnableMaxDepthChecks=true)
- // *
- // * @param Request $request
- // * @param $entity
- // *
- // * @return Response
- // */
- // public function patchAction(Request $request, ONU $entity)
- // {
- // return $this->putAction($request, $entity);
- // }
- //
- // /**
- // * Delete a ONU entity.
- // *
- // * @View(statusCode=204)
- // *
- // * @param Request $request
- // * @param $entity
- // *
- // * @return Response
- // */
- // public function deleteAction(Request $request, ONU $entity)
- // {
- // try {
- // $em = $this->getDoctrine()->getManager();
- // $em->remove($entity);
- // $em->flush();
- //
- // return null;
- // } catch (\Exception $e) {
- // return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
- // }
- // }
- /**
- * PATCH Route annotation.
- * @Patch("/onus/apply/{id}/{workflow}/{transition}")
- * @View(statusCode=201, serializerEnableMaxDepthChecks=true)
- *
- * @param Request $request
- * @param $entity
- * @param $transition
- * @param $workflow
- *
- * @return Response
- */
- public function applyAction(Request $request, ONU $entity, String $workflow, String $transition)
- {
- try {
- $wr = $this->container->get("workflow.registry");
- $wf = $wr->get($entity, $workflow);
- $newState = $wf->apply($entity, $transition);
- $em = $this->container->get("doctrine.orm.entity_manager");
- $validator = $this->container->get('validator');
- $errors = $validator->validate($entity);
- if (count($errors) > 0) {
- $errorsString = (string) $errors;
- return FOSView::create($errorsString, Codes::HTTP_INTERNAL_SERVER_ERROR);
- }else{
- $entity->setAdministrativeState("suspend");
- $em->persist($entity);
- $em->flush($entity);
- return $entity;
- }
- } catch (\Exception $e) {
- return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
- }
- }
- }
|