Skip to content

Commit

Permalink
enhanced get_pm()
Browse files Browse the repository at this point in the history
 - added `$user_id` argument between `$pm_id ` & `$set_as_true`
 - changed `set_as_true` to set read date only if user_id is equal to receiver's id
  • Loading branch information
REJack committed May 28, 2016
1 parent 46308eb commit 483ed60
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions application/libraries/Aauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -1932,22 +1932,32 @@ public function list_pms($limit=5, $offset=0, $receiver_id = FALSE, $sender_id=F
* Get Private Message
* Get private message by id
* @param int $pm_id Private message id to be returned
* @param int $user_id User ID of Sender or Receiver
* @param bool $set_as_read Whether or not to mark message as read
* @return object Private message
*/
public function get_pm($pm_id, $set_as_read = TRUE){
public function get_pm($pm_id, $user_id = NULL, $set_as_read = TRUE){
if(!$user_id){
$user_id = $this->CI->session->userdata('id');
}

$query = $this->aauth_db->where('id', $pm_id);
$query = $this->aauth_db->where('receiver_id', $user_id);
$query = $this->aauth_db->or_where('sender_id', $user_id);
$query = $this->aauth_db->get( $this->config_vars['pms'] );

if ($query->num_rows() < 1) {
$this->error( $this->CI->lang->line('aauth_error_no_pm') );
return FALSE;
}

if ($set_as_read) $this->set_as_read_pm($pm_id);
$result = $query->row();

return $query->row();
if ($user_id == $result->receiver_id && $set_as_read){
$this->set_as_read_pm($pm_id);
}

return $result;
}

//tested
Expand Down

0 comments on commit 483ed60

Please sign in to comment.