protected function _message_legend_items() { $action_css_classes = EEH_MSG_Template::get_message_action_icons(); $action_items = array(); foreach ($action_css_classes as $action_item => $action_details) { if ($action_item === 'see_notifications_for') { continue; } $action_items[$action_item] = array('class' => $action_details['css_class'], 'desc' => $action_details['label']); } /** @type array $status_items status legend setup*/ $status_items = array('sent_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')), 'idle_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')), 'failed_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')), 'resend_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')), 'incomplete_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')), 'retry_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'))); if (EEM_Message::debug()) { $status_items['debug_only_status'] = array('class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')); } return array_merge($action_items, $status_items); }
/** * Retrieve the EE_Message objects for the list table. * * @param int $perpage The number of items per page * @param string $view The view items are being retrieved for * @param bool $count Whether to just return a count or not. * @param bool $all Disregard any paging info (no limit on data returned). * @return int | EE_Message[] * @throws \EE_Error */ protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) { $current_page = isset($this->_req_data['paged']) && !empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; $per_page = isset($this->_req_data['perpage']) && !empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; $offset = ($current_page - 1) * $per_page; $limit = $all || $count ? null : array($offset, $per_page); $query_params = array('order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], 'limit' => $limit); /** * Any filters coming in from other routes? */ if (isset($this->_req_data['filterby'])) { $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); if (!$count) { $query_params['group_by'] = 'MSG_ID'; } } //view conditionals if ($view !== 'all' && $count && $all) { $query_params[0]['AND*view_conditional'] = array('STS_ID' => strtoupper($view)); } if (!$all && !empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { $query_params[0]['AND*view_conditional'] = array('STS_ID' => strtoupper($this->_req_data['status'])); } if (!$all && !empty($this->_req_data['s'])) { $search_string = '%' . $this->_req_data['s'] . '%'; $query_params[0]['OR'] = array('MSG_to' => array('LIKE', $search_string), 'MSG_from' => array('LIKE', $search_string), 'MSG_subject' => array('LIKE', $search_string), 'MSG_content' => array('LIKE', $search_string)); } //account for debug only status. We don't show Messages with the EEM_Message::status_debug_only to clients when //the messages system is in debug mode. //Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only //messages in the database. if (!EEM_Message::debug()) { $query_params[0]['AND*debug_only_conditional'] = array('STS_ID' => array('!=', EEM_Message::status_debug_only)); } //account for filters if (!$all && isset($this->_req_data['ee_messenger_filter_by']) && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected') { $query_params[0]['AND*messenger_filter'] = array('MSG_messenger' => $this->_req_data['ee_messenger_filter_by']); } if (!$all && !empty($this->_req_data['ee_message_type_filter_by']) && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected') { $query_params[0]['AND*message_type_filter'] = array('MSG_message_type' => $this->_req_data['ee_message_type_filter_by']); } if (!$all && !empty($this->_req_data['ee_context_filter_by']) && $this->_req_data['ee_context_filter_by'] !== 'none_selected') { $query_params[0]['AND*context_filter'] = array('MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by']))); } return $count ? EEM_Message::instance()->count($query_params, null, true) : EEM_Message::instance()->get_all($query_params); }
/** * This iterates through the provided queue and generates the EE_Message objects. * When iterating through the queue, the queued item that served as the base for generating other EE_Message objects * gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned for the * caller to decide what to do with it. * * @param bool $save Whether to save the EE_Message objects in the new queue or just return. * * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. */ public function generate($save = true) { //iterate through the messages in the queue, generate, and add to new queue. $this->_generation_queue->get_message_repository()->rewind(); while ($this->_generation_queue->get_message_repository()->valid()) { //reset "current" properties $this->_reset_current_properties(); /** @type EE_Message $msg */ $msg = $this->_generation_queue->get_message_repository()->current(); /** * need to get the next object and capture it for setting manually after deletes. The reason is that when * an object is removed from the repo then valid for the next object will fail. */ $this->_generation_queue->get_message_repository()->next(); $next_msg = $this->_generation_queue->get_message_repository()->current(); //restore pointer to current item $this->_generation_queue->get_message_repository()->set_current($msg); //skip and delete if the current $msg is NOT incomplete (queued for generation) if ($msg->STS_ID() !== EEM_Message::status_incomplete) { //we keep this item in the db just remove from the repo. $this->_generation_queue->get_message_repository()->remove($msg); //next item $this->_generation_queue->get_message_repository()->set_current($next_msg); continue; } if ($this->_verify()) { //let's get generating! $this->_generate(); } //don't persist debug_only messages if the messages system is not in debug mode. if ($msg->STS_ID() === EEM_Message::status_debug_only && !EEM_Message::debug()) { $this->_generation_queue->get_message_repository()->delete(); $this->_generation_queue->get_message_repository()->set_current($next_msg); continue; } //if there are error messages then let's set the status and the error message. if ($this->_error_msg) { //if the status is already debug only, then let's leave it at that. if ($msg->STS_ID() !== EEM_Message::status_debug_only) { $msg->set_STS_ID(EEM_Message::status_failed); } $msg->set_error_message(__('Message failed to generate for the following reasons: ') . "\n" . implode("\n", $this->_error_msg)); $msg->set_modified(time()); } else { //remove from db $this->_generation_queue->get_message_repository()->delete(); } //next item $this->_generation_queue->get_message_repository()->set_current($next_msg); } //generation queue is ALWAYS saved to record any errors in the generation process. $this->_generation_queue->save(); /** * save _ready_queue if flag set. * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This * means if a field was added that is not a valid database column. The EE_Message was already saved to the db * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is * irrelevant. */ if ($save) { $this->_ready_queue->save(); } //final reset of properties $this->_reset_current_properties(); return $this->_ready_queue; }