示例#1
0
 /**
  * Sending report alerts
  * @return void
  * @author Pavel Klyagin
  */
 public function send_alerts()
 {
     $this->enableComposerAutoloader();
     $alert_id = $this->uri->segment(3);
     $date_from = $this->uri->segment(4);
     $date_to = $this->uri->segment(5);
     $alert = new CAnalytics\Module\Alert\Alert($alert_id, $date_from, $date_to);
     $alert->sendActual();
 }
示例#2
0
 /**
  * @return array
  */
 private function getAlertsData()
 {
     $this->load->model('alert_model');
     $this->load->model('ranking_model');
     $actualAlerts = $this->alert_model->getAlertsFromDashboard($this->ion_auth->get_user_id());
     $result = array();
     foreach ($actualAlerts as $alert) {
         $options = \Alert_model::extractSearchCriteria($alert->options);
         $date = $this->ranking_model->getMostRecentDateWithDataForAlert($options, $alert->type);
         $alertData = array();
         if (!empty($date)) {
             $currentDate = new \DateTime($date);
             $currentAlert = new CAnalytics\Module\Alert\Alert($alert->id, $currentDate->format('Y-m-d'));
             if ($data = $currentAlert->sendSingle($alert, true, false, true)) {
                 $alertData = $data;
             }
         }
         $result[] = array('id' => $alert->id, 'type' => $alert->type, 'dashboard_position' => $alert->dashboard_position, 'results' => $alertData);
     }
     $not_alert_positions = $this->get_dashboard_position();
     if (!empty($not_alert_positions)) {
         $result = array_merge($result, $not_alert_positions);
         usort($result, array($this, 'sort_array_by_position'));
     }
     return $result;
 }
示例#3
0
 public function createAlertPreviewSend()
 {
     $this->load->model('alert_model');
     $this->enableComposerAutoloader();
     $mode = $this->input->get('mode');
     $alertId = $this->input->get('alertId');
     $selectionId = $this->input->get('selectionId');
     $recipients = $this->input->get('recipients_emails');
     $recipientGroups = $this->input->get('recipients_groups');
     $form = array();
     parse_str($this->input->get('form'), $form);
     $type = !empty($form['f']['type']) ? $form['f']['type'] : false;
     if (!empty($recipientGroups)) {
         if (empty($recipients)) {
             $recipients = [];
         }
         foreach ($recipientGroups as $groupId) {
             $emails = $this->alert_model->getEmailsByGroupId($groupId);
             foreach ($emails as $itmObj) {
                 $recipients[] = $itmObj->email;
             }
         }
         $recipients = array_unique($recipients);
     }
     if (empty($recipients)) {
         return $this->jsonResponse(array('error' => true, 'message' => 'Please add at least one recipient to this alert.'));
     }
     if (empty($type) || empty($mode) || empty($selectionId) && empty($alertId)) {
         return $this->jsonResponse(array('error' => true, 'message' => 'Bad Request'));
     }
     $options = array();
     if (!empty($alertId)) {
         $alert = $this->alert_model->getAlertByIdAndUserId($alertId, $this->ion_auth->get_user_id());
         if (empty($alert) || empty($alert->options)) {
             return $this->jsonResponse(array('error' => true, 'message' => 'Alert not found'));
         }
         $options = $alert->options;
     } else {
         if ($selectionId) {
             $this->load->model('settings_model');
             $settings = $this->settings_model->get_value($this->ion_auth->get_user_id(), 'user_recent_query_setting');
             if (empty($settings) || empty($settings[$selectionId])) {
                 return $this->jsonResponse(array('error' => true, 'message' => 'Alert not found'));
             }
             $options = serialize($settings[$selectionId]);
         }
     }
     $alert = new stdClass();
     $alert->type = $type;
     $alert->name = !empty($form['f']['name']) ? $form['f']['name'] : '';
     $alert->options = $options;
     $alert->last_sent = date('Y-m-d');
     $alert->recipients = $recipients;
     $alertHelper = new CAnalytics\Module\Alert\Alert();
     if ('preview' == $mode) {
         $result = $alertHelper->showSendAlertByOptions($alert, true);
         if (empty($result)) {
             return $this->jsonResponse(array('error' => true, 'message' => 'No results'));
         } else {
             return $this->jsonResponse(array('error' => false, 'html' => $result));
         }
     } else {
         if ('send' == $mode) {
             $result = $alertHelper->showSendAlertByOptions($alert);
             return $this->jsonResponse(array('error' => false, 'message' => 'Alert Was Sent.'));
         }
     }
 }