| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | ), |
| 34 | 34 | array( |
| 35 | 35 | 'field' => 'date', |
| 36 | 36 | 'field_label' => __('Date', 'wpdirectorykit'), |
| 37 | - 'field_type' => 'DATE_READONLY', | |
| 37 | + 'field_type' => 'DATETIME_READONLY', | |
| 38 | 38 | 'rules' => '' |
| 39 | 39 | ), |
| 40 | 40 | array( |
| 41 | 41 | 'field' => 'message', |
| @@ -459,9 +459,42 @@ | ||
| 459 | 459 | /* remove */ |
| 460 | 460 | parent::delete($id); |
| 461 | 461 | |
| 462 | 462 | return true; |
| 463 | + } | |
| 464 | + | |
| 465 | + | |
| 466 | + public function total_unread($user_id=NULL) | |
| 467 | + { | |
| 468 | + $post_table = $this->db->prefix.'posts'; | |
| 469 | + | |
| 470 | + $this->db->select('COUNT(*) as total_count'); | |
| 471 | + | |
| 472 | + if(empty($user_id)) | |
| 473 | + { | |
| 474 | + $user_id = $this->current_user_id; | |
| 475 | + } | |
| 476 | + | |
| 477 | + $this->db->join($this->db->prefix.'wdk_messages_chat ON ('.$this->_table_name.'.idmessage = '.$this->db->prefix.'wdk_messages_chat.related_key AND chat_is_readed IS NULL AND `outgoing_msg_user_id`!= '.$user_id.')', NULL, 'LEFT'); | |
| 478 | + | |
| 479 | + $this->db->from($this->_table_name); | |
| 480 | + | |
| 481 | + $this->db->join($this->db->prefix.'wdk_listings ON '.$this->db->prefix.'wdk_listings.post_id = '.$this->_table_name.'.post_id', NULL, 'LEFT'); | |
| 482 | + $this->db->join($post_table.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID', NULL, 'LEFT'); | |
| 483 | + | |
| 484 | + $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_id.' OR user_id_sender = '.$user_id.' OR user_id_receiver = '.$user_id.' )'); | |
| 485 | + | |
| 486 | + $this->db->where('(('.$this->_table_name.'.is_readed IS NULL AND related_key IS NULL AND user_id_editor = '.$user_id.') OR ('.$this->_table_name.'.is_readed IS NOT NULL AND related_key IS NOT NULL))'); | |
| 487 | + | |
| 488 | + $query = $this->db->get(); | |
| 489 | + | |
| 490 | + $res = $this->db->results(); | |
| 491 | + | |
| 492 | + if(isset($res[0]->total_count)) | |
| 493 | + return $res[0]->total_count; | |
| 494 | + | |
| 495 | + return 0; | |
| 463 | 496 | } |
| 464 | 497 | |
| 465 | 498 | } |
| 466 | 499 | |
| 467 | 500 | ?> |