Пример #1
0
 public function steps($json = true)
 {
     $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 steps');
         }
         //get necessary arguments
         $ts = $app->input->getString('ts');
         //get steps model
         $stepsModel = JModelLegacy::getInstance('Steps', 'CitybrandingModel', array('ignore_request' => true));
         //set states
         $stepsModel->setState('filter.state', 1);
         //$stepsModel->setState('filter.citybrandingapi.ordering', 'ordering');
         //$stepsModel->setState('filter.citybrandingapi.direction', 'ASC');
         if (!is_null($ts)) {
             $stepsModel->setState('filter.citybrandingapi.ts', $ts);
         }
         //handle unexpected warnings from model
         set_error_handler(array($this, 'exception_error_handler'));
         //get items and sanitize them
         $data = $stepsModel->getItems();
         restore_error_handler();
         $result = CitybrandingFrontendHelper::sanitizeSteps($data);
         if ($json) {
             echo new JResponseJson($result, 'Steps fetched successfully');
         } else {
             return $result;
         }
     } catch (Exception $e) {
         header("HTTP/1.0 202 Accepted");
         echo new JResponseJson($e);
     }
 }