/** * @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; }
/** * Check whether alert is valid to compose report * @author stom */ public function isValid($alert, &$error = false) { if (empty($alert->options)) { $error && ($error = 'No options'); return false; } if (empty($alert->options_extracted) || !is_array($alert->options_extracted)) { $alert->options_extracted = \Alert_model::extractSearchCriteria($alert->options); } if (!empty($alert->options_extracted['rank_term']) && is_array($alert->options_extracted['rank_term'])) { $search_terms = $this->getRankingModel()->get_('search_terms', array('id' => $alert->options_extracted['rank_term'])); if (empty($search_terms)) { $error && ($error = 'No valid (existing) search terms'); return false; } } else { if (empty($alert->options_extracted['product_list'])) { $error && ($error = 'No search terms or product list attached'); return false; } } return true; }