partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

StatisticController.php (2254B)


      1 <?php
      2 
      3 namespace PartKeepr\StatisticBundle\Controller;
      4 
      5 use FOS\RestBundle\Controller\Annotations\QueryParam;
      6 use FOS\RestBundle\Controller\Annotations\View;
      7 use FOS\RestBundle\Controller\FOSRestController;
      8 use FOS\RestBundle\Request\ParamFetcher;
      9 use Sensio\Bundle\FrameworkExtraBundle\Configuration as Routing;
     10 
     11 class StatisticController extends FOSRestController
     12 {
     13     /**
     14      * Returns the current system statistics.
     15      *
     16      * @Routing\Route("/api/statistics/current", defaults={"method" = "get","_format" = "json"})
     17      * @View()
     18      *
     19      * @return array
     20      */
     21     public function getCurrentStatisticAction()
     22     {
     23         $statisticService = $this->get('partkeepr.statistic.service');
     24 
     25         $aData = [];
     26         $aData['partCount'] = $statisticService->getPartCount();
     27         $aData['partCategoryCount'] = $statisticService->getPartCategoryCount();
     28         $aData['totalPrice'] = $statisticService->getTotalPrice();
     29         $aData['averagePrice'] = $statisticService->getAveragePrice();
     30         $aData['partsWithPrice'] = $statisticService->getPartCount(true);
     31         $aData['partsWithoutPrice'] = $aData['partCount'] - $aData['partsWithPrice'];
     32         $aData['units'] = $statisticService->getUnitCounts();
     33 
     34         return $aData;
     35     }
     36 
     37     /**
     38      * Returns the sampled statistics for a given period.
     39      *
     40      * @QueryParam(name="start")
     41      * @QueryParam(name="end")
     42      * @Routing\Route("/api/statistics/sampled", defaults={"method" = "get","_format" = "json"})
     43      * @View()
     44      *
     45      * @param ParamFetcher $paramFetcher
     46      *
     47      * @return array
     48      */
     49     public function getSampledStatisticAction(ParamFetcher $paramFetcher)
     50     {
     51         $start = new \DateTime($paramFetcher->get('start'));
     52         $end = new \DateTime($paramFetcher->get('end'));
     53 
     54         return $this->get('partkeepr.statistic.service')->getSampledStatistics($start, $end);
     55     }
     56 
     57     /**
     58      * Returns the range in which statistics are available.
     59      *
     60      * @Routing\Route("/api/statistics/range", defaults={"method" = "get","_format" = "json"})
     61      * @View()
     62      *
     63      * @return array
     64      */
     65     public function getStatisticRangeAction()
     66     {
     67         return $this->get('partkeepr.statistic.service')->getStatisticRange();
     68     }
     69 }