/** * retrieves an array with messages that form one threat in that each message * was a reply to the next one in line, everything starting with $replyto as * the id of the first message. <br/> * returns an empty array, if no message can be found - e.g. if all messages * have been deleted by user $usr<br/> * Only messages are returned that are not yet deleted. If a message in a thread * was deleted (also if only by this user), the thread is no longer followed from * there on * * 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/> * ) * * @param int $msgid the id of the message * @param int $usr * @return array */ function get_message_thread_mr($msgid, $usr = null) { global $USER; if (null === $usr) { $usr = $USER->get('id'); } $message = get_message_mr($usr, $msgid); if (null !== $message && !empty($message->parent)) { $subthread = get_message_thread_mr($message->parent); if (null !== $subthread && sizeof($subthread) > 0) { return array_merge($subthread, array($message)); } } if (null === $message) { return null; } return array($message); }
$users[] = $userrelid; } else { $SESSION->add_info_msg(get_string('removeduserfromlist', 'module.multirecipientnotification')); } } if ($USER->get('id') !== $message->fromid) { $deleted = get_field('usr', 'deleted', 'id', $message->fromid); if ($deleted === '0' && can_send_message($USER->to_stdclass(), $message->fromid) && $USER->id != $message->fromid) { $users[] = $message->fromid; } else { $SESSION->add_info_msg(get_string('removeduserfromlist', 'module.multirecipientnotification')); } } } // OK, now it is safe to fetch the whole thread. $messages = get_message_thread_mr($replytoid); if (!is_array($messages) || count($messages) <= 0) { throw new AccessDeniedException(); } // there may be deleted users as sender or other recipients, so we format // all users here to not link to deleted users or the logged in user. Also // count deleted users and wrap them up in one span at the end foreach ($messages as $oldmessage) { $fromusr = get_user($oldmessage->fromid); if ($USER->get('id') === $oldmessage->fromid || $fromusr->deleted) { $oldmessage->fromusrlink = null; } else { $oldmessage->fromusrlink = profile_url($oldmessage->fromid); } if ($fromusr->deleted) { $oldmessage->fromusrname = get_string('deleteduser');