Exemple #1
0
 public function intervals()
 {
     $result = null;
     $app = JFactory::getApplication();
     try {
         self::validateRequest();
         if ($app->input->getMethod() != 'GET') {
             throw new Exception('You cannot use other method than GET to fetch intervals');
         }
         //get necessary arguments
         $by_step = $app->input->getString('by_step', null);
         $by_category = $app->input->getString('by_category', null);
         $by_step = $by_step === 'true';
         $by_category = $by_category === 'true';
         $ts = $app->input->getString('ts', null);
         $prior_to = $app->input->getString('prior_to', null);
         if (!is_null($ts) && !ImcFrontendHelper::isValidTimeStamp($ts)) {
             throw new Exception('Invalid timestamp ts');
         }
         if (!is_null($prior_to) && !ImcFrontendHelper::isValidTimeStamp($prior_to)) {
             throw new Exception('Invalid timestamp prior_to');
         }
         //get date from ts
         if (!is_null($ts)) {
             $ts = gmdate('Y-m-d H:i:s', $ts);
         }
         if (!is_null($prior_to)) {
             $prior_to = gmdate('Y-m-d H:i:s', $prior_to);
         }
         //handle unexpected warnings
         set_error_handler(array($this, 'exception_error_handler'));
         $result = ImcFrontendHelper::intervals($by_step, $by_category, $ts, $prior_to);
         restore_error_handler();
         echo new JResponseJson($result, 'Intervals fetched successfully');
     } catch (Exception $e) {
         header("HTTP/1.0 202 Accepted");
         echo new JResponseJson($e);
     }
 }