Beispiel #1
0
 /**
  * Creates new events
  *
  * @param  mixed $data Request data
  * @return mixed
  */
 public function create($data)
 {
     $configName = $this->params()->fromRoute('configName');
     $widgetId = $this->params()->fromRoute('widgetId');
     try {
         $dashboardManager = new DashboardManager($configName, $this->serviceLocator);
         $widget = $dashboardManager->getWidget($widgetId);
         if (!$widget instanceof MessagesWidget) {
             $this->getResponse()->setStatusCode(400);
             $response = array('status' => '400', 'message' => 'Posting content to a widget is only available for EventsWidget objects');
             return new JsonModel($response);
         }
         $dao = $widget->getDao();
         if (!$dao instanceof EventsDao) {
             $this->getResponse()->setStatusCode(400);
             $response = array('status' => '400', 'message' => 'Selected EventsWidget needs to use EventsDao');
             return new JsonModel($response);
         }
         $widget->getDao()->addEvent($data['type'], $configName, $widgetId, $data);
     } catch (\Exception $e) {
         $this->getResponse()->setStatusCode(400);
         $response = array('status' => '400', 'message' => $e->getMessage());
         return new JsonModel($response);
     }
     return $this->getResponse()->setStatusCode(201);
 }
 /**
  * Return current data for widgets
  *
  * @param  string $widgetId widget's id
  * @return \Zend\View\Model\JsonModel
  */
 public function get($widgetId)
 {
     $responseData = null;
     $configName = $this->params()->fromRoute('configName');
     $dashboardManager = new DashboardManager($configName, $this->serviceLocator, $widgetId);
     /* @var AbstractWidget $widget */
     $widget = $dashboardManager->getWidget($widgetId);
     try {
         $responseData = $widget->fetchData();
         $result = new JsonModel(array('data' => $responseData, 'hash' => $widget->getResponseHash(), 'updateTime' => gmdate("H:i")));
     } catch (\Exception $e) {
         $this->getResponse()->setStatusCode(400);
         $result = new JsonModel(array('error' => array('message' => $e->getMessage(), 'type' => $e->getCode()), 'data' => '', 'hash' => $widget->getResponseHash(), 'updateTime' => gmdate("H:i")));
     }
     return $result;
 }