Ejemplo n.º 1
0
 public static function get_sent()
 {
     $per_page = mmg()->setting()->per_page;
     $paged = mmg()->get('mpaged', 1);
     $offset = ($paged - 1) * $per_page;
     $total_pages = ceil(self::count_all() / $per_page);
     mmg()->global['conversation_total_pages'] = $total_pages;
     $messages = MM_Message_Model::model()->find_by_attributes(array('send_from' => get_current_user_id()));
     $ids = array();
     foreach ($messages as $message) {
         $ids[] = $message->conversation_id;
     }
     $ids = array_unique(array_filter($ids));
     if (empty($ids)) {
         return array();
     }
     $model = new MM_Conversation_Model();
     global $wpdb;
     $sql = "SELECT conversation.id FROM " . $model->get_table() . " conversation\r\n                INNER JOIN " . MM_Message_Status_Model::model()->get_table() . " mstat ON mstat.conversation_id=conversation.id\r\n                WHERE mstat.status IN (" . implode(',', array(MM_Message_Status_Model::STATUS_READ, MM_Message_Status_Model::STATUS_UNREAD)) . ")\r\n                AND conversation.id IN (" . implode(',', $ids) . ") AND site_id=%d\r\n                GROUP BY conversation.id ORDER BY conversation.date_created DESC LIMIT %d,%d";
     $sql = $wpdb->prepare($sql, get_current_blog_id(), $offset, $per_page);
     $ids = $wpdb->get_col($sql);
     if (empty($ids)) {
         return array();
     }
     $models = $model->find_all_by_ids($ids, false, false, 'date_created DESC');
     return $models;
 }
 function _reply_message($conv_id, $message_id, $user_id, $model)
 {
     //load conversation
     $conversation = MM_Conversation_Model::model()->find($conv_id);
     $conversation->status = MM_Message_Status_Model::STATUS_UNREAD;
     //we will add new message to this conversation
     $conversation->save();
     //update users from this conversation, now save the message
     $m = new MM_Message_Model();
     $m->import($model->export());
     $m->send_to = $user_id;
     $m->conversation_id = $conversation->id;
     $m->status = MM_Message_Model::UNREAD;
     $mess = MM_Message_Model::model()->find($message_id);
     if (!empty($m->reply_to)) {
         if (!is_numeric($m->reply_to)) {
             wp_send_json(array('status' => 'fail', 'errors' => $model->get_errors()));
             exit;
         }
         $title = $m->subject;
         $description = $m->content;
         $price = $m->reply_to;
         $product_html = get_custom_order_button($title, $description, $price);
     }
     if (empty($m->subject)) {
         $m->subject = __("Re:", mmg()->domain) . ' ' . $mess->subject;
     }
     if (isset($product_html)) {
         $m->subject = __('You have new estimates!', 'artgorae');
         $m->content = __('You have new estimates!', 'artgorae') . '<br/><br/>' . $product_html;
     }
     $m->save();
     //update status for send to
     $status = MM_Message_Status_Model::model()->find_one_with_attributes(array('conversation_id' => $conversation->id, 'user_id' => $user_id));
     if (is_object($status)) {
         $status->status = MM_Message_Status_Model::STATUS_UNREAD;
         $status->save();
     }
     //update index
     $conversation->update_index($m->id);
     do_action('mm_message_sent', $m);
 }