Browse Source

enhanced `send_pm()`

- changed `$receiver_id` to `$receiver_ids`
 - sends multiple pms
 - returns array of receiver user ids with specific error message on failure or TRUE if message successfully sent
develop
REJack 9 years ago
parent
commit
1f1afbde0a
  1. 36
      application/libraries/Aauth.php

36
application/libraries/Aauth.php

@ -1873,26 +1873,34 @@ class Aauth {
* Send Private Message * Send Private Message
* Send a private message to another user * Send a private message to another user
* @param int $sender_id User id of private message sender * @param int $sender_id User id of private message sender
* @param int $receiver_id User id of private message receiver * @param int/array $receiver_ids Array of User ids of private message receiver OR User id as INT of a single receiver
* @param string $title Message title/subject * @param string $title Message title/subject
* @param string $message Message body/content * @param string $message Message body/content
* @return bool Send successful/failed * @return array/bool Array with User ID's as key and TRUE or a specific error message OR FALSE if sender doesn't exist
*/ */
public function send_pm( $sender_id, $receiver_id, $title, $message ){ public function send_pm( $sender_id, $receiver_ids, $title, $message ){
if ($this->config_vars['pm_encryption']){
if ( !is_numeric($receiver_id) OR $sender_id == $receiver_id ){ $this->CI->load->library('encrypt');
$this->error($this->CI->lang->line('aauth_error_self_pm')); $title = $this->CI->encrypt->encode($title);
return FALSE; $message = $this->CI->encrypt->encode($message);
} }
if (($this->is_banned($receiver_id) || !$this->user_exist_by_id($receiver_id)) || ($this->is_banned($sender_id) || !$this->user_exist_by_id($sender_id))){ if (($this->is_banned($sender_id) || !$this->user_exist_by_id($sender_id))){
$this->error($this->CI->lang->line('aauth_error_no_user')); $this->error($this->CI->lang->line('aauth_error_no_user'));
return FALSE; return FALSE;
} }
if (is_numeric($receiver_ids)) {
$receiver_ids = array($receiver_ids);
}
if ($this->config_vars['pm_encryption']){ $return_array = array();
$this->CI->load->library('encrypt'); foreach ($receiver_ids as $receiver_id) {
$title = $this->CI->encrypt->encode($title); if ($sender_id == $receiver_id ){
$message = $this->CI->encrypt->encode($message); $return_array[$receiver_id] = $this->CI->lang->line('aauth_error_self_pm');
continue;
}
if ($this->is_banned($receiver_id) || !$this->user_exist_by_id($receiver_id)){
$return_array[$receiver_id] = $this->CI->lang->line('aauth_error_no_user');
continue;
} }
$data = array( $data = array(
@ -1902,8 +1910,10 @@ class Aauth {
'message' => $message, 'message' => $message,
'date_sent' => date('Y-m-d H:i:s') 'date_sent' => date('Y-m-d H:i:s')
); );
$return_array[$receiver_id] = $this->aauth_db->insert( $this->config_vars['pms'], $data );
}
return $query = $this->aauth_db->insert( $this->config_vars['pms'], $data ); return $return_array;
} }
//tested //tested

Loading…
Cancel
Save