| @@ -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', |
| @@ -220,13 +220,13 @@ | ||
| 220 | 220 | if( $user_check || (!is_null($user_id) && !empty($user_id) ) ) |
| 221 | 221 | { |
| 222 | 222 | if(!is_null($user_id) && !empty($user_id)) |
| 223 | 223 | { |
| 224 | - $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_id.' OR user_id_sender = '.$user_id.' )'); | |
| 224 | + $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.' )'); | |
| 225 | 225 | } |
| 226 | 226 | elseif($this->current_user_id) |
| 227 | 227 | { |
| 228 | - $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '. $this->current_user_id.' OR user_id_sender = '. $this->current_user_id.' )'); | |
| 228 | + $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '. $this->current_user_id.' OR user_id_sender = '. $this->current_user_id.' OR user_id_receiver = '. $this->current_user_id.' )'); | |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | $query = $this->db->get(); |
| @@ -276,13 +276,13 @@ | ||
| 276 | 276 | if( $user_check || (!is_null($user_id) && !empty($user_id) ) ) |
| 277 | 277 | { |
| 278 | 278 | if(!is_null($user_id) && !empty($user_id)) |
| 279 | 279 | { |
| 280 | - $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_id.' OR user_id_sender = '.$user_id.' )'); | |
| 280 | + $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.' )'); | |
| 281 | 281 | } |
| 282 | 282 | elseif($this->current_user_id) |
| 283 | 283 | { |
| 284 | - $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '. $this->current_user_id.' OR user_id_sender = '. $this->current_user_id.' )'); | |
| 284 | + $this->db->where('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '. $this->current_user_id.' OR user_id_sender = '. $this->current_user_id.' OR user_id_receiver = '. $this->current_user_id.' )'); | |
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | if(!empty($order_by)){ |
| @@ -400,9 +400,9 @@ | ||
| 400 | 400 | |
| 401 | 401 | if(wmvc_show_data('user_id_receiver', $row) == $user_id || wmvc_show_data('user_id_editor', $row) == $user_id ) |
| 402 | 402 | return true; |
| 403 | 403 | |
| 404 | - if(wmvc_user_in_role('administrator')) return true; | |
| 404 | + if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) return true; | |
| 405 | 405 | |
| 406 | 406 | return false; |
| 407 | 407 | } |
| 408 | 408 | |
| @@ -423,9 +423,9 @@ | ||
| 423 | 423 | if(wmvc_show_data('user_id_receiver', $row) == $user_id || wmvc_show_data('user_id_editor', $row) == $user_id ) |
| 424 | 424 | return true; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - if(wmvc_user_in_role('administrator')) return true; | |
| 427 | + if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) return true; | |
| 428 | 428 | |
| 429 | 429 | return false; |
| 430 | 430 | } |
| 431 | 431 | |
| @@ -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 | ?> |