|
@@ -2,8 +2,15 @@
|
|
|
|
|
|
namespace StatsBundle\Controller\REST;
|
|
|
|
|
|
+use FOS\RestBundle\Controller\Annotations\QueryParam;
|
|
|
use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
+use FOS\RestBundle\Controller\Annotations\View;
|
|
|
+use FOS\RestBundle\Request\ParamFetcherInterface;
|
|
|
+use FOS\RestBundle\Util\Codes;
|
|
|
+use FOS\RestBundle\View\View as FOSView;
|
|
|
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
use StatsBundle\Form\OnuType;
|
|
|
+use StatsBundle\Entity\Onu;
|
|
|
use WebserviceBundle\Controller\RESTController;
|
|
|
|
|
|
/**
|
|
@@ -28,5 +35,36 @@ class OnuRESTController extends RESTController
|
|
|
{
|
|
|
return get_class(new OnuType());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @View(serializerEnableMaxDepthChecks=true)
|
|
|
+ *
|
|
|
+ * @param ParamFetcherInterface $paramFetcher
|
|
|
+ *
|
|
|
+ * @return Response
|
|
|
+ *
|
|
|
+ * @QueryParam(name="filters", nullable=true, array=true, description="Filter by fields. Must be an array ie. &filters[id]=3")
|
|
|
+ */
|
|
|
+ public function getShowUrlAction(ParamFetcherInterface $paramFetcher)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $url = '';
|
|
|
+ $filters = !is_null($paramFetcher->get('filters')) ? $paramFetcher->get('filters') : [];
|
|
|
+ if (isset($filters['ponSerialNumber'])) {
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $onu = $em->getRepository(Onu::class)
|
|
|
+ ->findOneByPonSerialNumber($filters['ponSerialNumber']);
|
|
|
+ if ($onu) {
|
|
|
+ $url = $this->generateUrl('admin_stats_onu_show', [
|
|
|
+ 'id' => $onu->getCustomId()
|
|
|
+ ], UrlGeneratorInterface::ABSOLUTE_URL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return compact('url');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|