Exemplo n.º 1
0
 /**
  * deletes a users messages, when a user is deleted
  *
  * @param type $event
  * @param type $user
  */
 public static function eventlistener_on_deleteuser($event, $user)
 {
     if ('deleteuser' !== $event) {
         return;
     }
     $userid = $user['id'];
     db_begin();
     $recievedmessageids = get_message_ids_mr($userid, 'recipient', null, null, null);
     if (count($recievedmessageids) > 0) {
         delete_messages_mr($recievedmessageids, $userid);
     }
     $sentmessageids = get_message_ids_mr($userid, 'sender', null, null, 100);
     if (count($sentmessageids) > 0) {
         delete_messages_mr($sentmessageids, $userid);
     }
     db_commit();
 }
Exemplo n.º 2
0
/**
 *
 * retrieves the messages for user $usr (or logged in user as default). To
 * view the messages the user has sent, use $role='sender'. Type should always
 * be 2 (usermessage). Limit and offset can be used for paginated views
 * <br/>
 * example result:                          <br/>
 * array (                                  <br/>
 *   0 =>                                   <br/>
 *   stdClass::__set_state(array(           <br/>
 *      'id' => '23',                       <br/>
 *      'type' => '2',                      <br/>
 *      'ctime' => '2013-09-12 10:12:26',   <br/>
 *      'subject' => 'some subject',        <br/>
 *      'message' => 'some body',           <br/>
 *      'parent' => NULL,                   <br/>
 *      'userids' =>                        <br/>
 *     array (                              <br/>
 *       0 => '1',                          <br/>
 *       1 => '2',                          <br/>
 *     ),                                   <br/>
 *      'fromid' => '1',                    <br/>
 *   ))                                     <br/>
 * )                                        <br/>
 *
 * @param int $usr the id of the user
 * @param string $role the role can be <b>sender</b> or <b>recipient</b>
 * @param int $type so far it's always <b>2</b> for usermessage
 * @param string $sortby should be <b>null</b> or <b>ctime ASC</b> or <b>ctime DESC</b>
 * @param int $limit limits the number of results - for paginations for example
 * @param int $offset offset of the first row to return
 * @return array
 */
function get_messages_mr($usr = null, $role = 'recipient', $type = null, $sortby = null, $limit = 20, $offset = 0)
{
    $messageids = get_message_ids_mr($usr, $role, $type, $sortby, $limit, $offset);
    if (null === $usr) {
        global $USER;
        $usr = $USER->get('id');
    }
    foreach ($messageids as $msgid) {
        $msg = get_message_mr($usr, $msgid);
        if (null !== $msg) {
            $messages[] = $msg;
        }
    }
    return $messages;
}