public function showSendAlertByOptions($alert, $return = false) { $types_array = \Alert_model::getTypeOptions('scorecard'); $alert->options_array = unserialize($alert->options); $returnResult = false; $date = !empty($alert->options_array['selected_date']['selected_date']) ? $alert->options_array['selected_date']['selected_date'] : date('Y-m-d'); $date = is_array($date) && !empty($date[0]) ? $date[0] : date('Y-m-d'); if (in_array($alert->type, $types_array) && $alert->type !== 'out_of_stock') { $this->applySearchCriteria($alert); if ($alert->type == 'executive_summary') { $date_old = date('Y-m-d', strtotime($date . ' -1 week')); $this->setDateOld($date); } else { $this->setDateOld($date); } $this->setDateNew($date); if ($this->hasBrands() || $this->hasKeywords()) { $returnResult = $this->sendSingle($alert, $return, true); } } elseif ($alert->type === 'content_health') { $returnResult = $this->sendSingle($alert, $return, true); } elseif ($alert->type === 'out_of_stock') { $this->applySearchCriteria($alert); $this->setDateNew($date); $returnResult = $this->sendSingle($alert, $return, true); } return $returnResult; }
/** * Return alert edit form with data * @return json * @author Pavel Klyagin */ public function edit() { $this->load->model('ranking_model'); $this->load->model('alert_model'); $this->lang->load('alert'); $alert_id = $this->input->post('id'); $user_id = $this->ion_auth->get_user_id(); $brands_selected = array(); $all_checked_brand_checkboxes = array(); $errors = array(); if ($alert_id && $user_id) { $types = array(); if ($types = $this->input->post('type')) { $types = is_array($types) ? $types : explode('|', $types); } if ($this->ion_auth->is_admin()) { $data = $this->alert_model->getAlertByIdAndUserId($alert_id, null); } else { $data = $this->alert_model->getAlertByIdAndUserId($alert_id, $user_id); } if ($data) { if (isset($data->options)) { $options = unserialize($data->options); if (isset($options['rank_brand']) && isset($options['rank_brand']['rank_brand'])) { $brands_selected = $options['rank_brand']['rank_brand']; } if (isset($options['rank_brand']) && isset($options['rank_brand']['all_checked_brand_checkboxes'])) { $all_checked_brand_checkboxes = $options['rank_brand']['all_checked_brand_checkboxes']; } $brands_selected = Ranking_model::getBrandIdsFromSelectedGroups($brands_selected, $all_checked_brand_checkboxes); } // get alert associated data (sites, brands, keywords), format it for output $data->associated = array(); if (isset($options['rank_site'], $options['rank_site']['rank_site_text'])) { $data->associated['sites'] = $options['rank_site']['rank_site_text']; } if (isset($options['rank_brand'], $options['rank_brand']['rank_brand_text'])) { $data->associated['brands_text'] = $options['rank_brand']['rank_brand_text']; } if (isset($options['rank_term'], $options['rank_term']['all_checked_checkboxes']) && is_array($options['rank_term']['all_checked_checkboxes'])) { $data->associated['keywords'] = array(); foreach ($options['rank_term']['all_checked_checkboxes'] as $checked_checkbox) { if (isset($checked_checkbox['selected_keywords_array']) && is_array($checked_checkbox['selected_keywords_array'])) { $data->associated['keywords'] = array_merge($data->associated['keywords'], $checked_checkbox['selected_keywords_array']); } } $data->associated['keywords'] = array_map('trim', array_values($data->associated['keywords'])); } $data->associated = array_filter($data->associated); } else { $errors[] = 'Wrong Alert ID: ' . $alert_id; } $user = $this->ion_auth->get_user_data(); $this->_checkUserInRecipientsList(); $user_email = ''; if (!empty($user['email'])) { $user_email = $user['email']; } $alert_recipients = $this->_getRecipientsListByRole(); $alert_recipients_groups = $this->_getRecipientGroupsListByRole(); $selected_recipients = $this->alert_model->getRecipientsByAlertId($alert_id); $selected_recipients_ids = array(); if (!empty($selected_recipients)) { foreach ($selected_recipients as $recipient) { $selected_recipients_ids[] = $recipient->id; } } $selectedGroups = []; $selectedGroupsArray = $this->alert_model->getGroupsByAlertId($alert_id); foreach ($selectedGroupsArray as $group) { $selectedGroups[] = $group->group_id; } $this->output->set_content_type('application/json')->set_output(json_encode(array('result' => !empty($data) ? 1 : 0, 'errors' => $errors, 'html' => $this->load->view('alert/add-form-new', array('brand_options' => Alert_model::getBrandsOptions($brands_selected), 'edit_mode' => true, 'data' => $data, 'type_options' => Alert_model::getTypeOptions('scorecard'), 'frequency_options' => Alert_model::getFrequencyOptions(true), 'weekday_options' => Alert_model::getWeekdaysOptions(), 'monthday_options' => Alert_model::getMonthDaysOptions(), 'hour_options' => $this->alert_model->getHoursOptions(), 'hourly_options' => $this->alert_model->getHourlyOptions(), 'user_email' => $user_email, 'alert_recipients' => $alert_recipients, 'selectedGroups' => $selectedGroups, 'alert_recipients_groups' => $alert_recipients_groups, 'selected_recipients_ids' => $selected_recipients_ids), true)))); } }