public static function get_conversation_between_users(
        int $userid,
        int $otheruserid,
        bool $includecontactrequests = false,
        bool $includeprivacyinfo = false,
        int $memberlimit = 0,
        int $memberoffset = 0,
        int $messagelimit = 0,
        int $messageoffset = 0,
        bool $newestmessagesfirst = true
    ) {
        global $CFG, $DB, $USER;

        // All the standard BL checks.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $params = [
            'userid' => $userid,
            'otheruserid' => $otheruserid,
            'includecontactrequests' => $includecontactrequests,
            'includeprivacyinfo' => $includeprivacyinfo,
            'memberlimit' => $memberlimit,
            'memberoffset' => $memberoffset,
            'messagelimit' => $messagelimit,
            'messageoffset' => $messageoffset,
            'newestmessagesfirst' => $newestmessagesfirst
        ];
        self::validate_parameters(self::get_conversation_between_users_parameters(), $params);

        $systemcontext = context_system::instance();
        self::validate_context($systemcontext);

        $conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']]);
        $conversation = null;

        if ($conversationid) {
            $conversation = \core_message\api::get_conversation(
                $params['userid'],
                $conversationid,
                $params['includecontactrequests'],
                $params['includeprivacyinfo'],
                $params['memberlimit'],
                $params['memberoffset'],
                $params['messagelimit'],
                $params['messageoffset'],
                $params['newestmessagesfirst']
            );
        }

        if ($conversation) {
            return $conversation;
        } else {
            // We have to throw an exception here because the external functions annoyingly
            // don't accept null to be returned for a single structure.
            throw new \moodle_exception('errorconversationdoesnotexist', 'message');
        }
    }
public static function get_conversation_between_users(
        int $userid,
        int $otheruserid,
        bool $includecontactrequests = false,
        bool $includeprivacyinfo = false,
        int $memberlimit = 0,
        int $memberoffset = 0,
        int $messagelimit = 0,
        int $messageoffset = 0,
        bool $newestmessagesfirst = true
    ) {
        global $CFG, $DB, $USER;

        // All the standard BL checks.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $params = [
            'userid' => $userid,
            'otheruserid' => $otheruserid,
            'includecontactrequests' => $includecontactrequests,
            'includeprivacyinfo' => $includeprivacyinfo,
            'memberlimit' => $memberlimit,
            'memberoffset' => $memberoffset,
            'messagelimit' => $messagelimit,
            'messageoffset' => $messageoffset,
            'newestmessagesfirst' => $newestmessagesfirst
        ];
        self::validate_parameters(self::get_conversation_between_users_parameters(), $params);

        $systemcontext = context_system::instance();
        self::validate_context($systemcontext);

        $conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']]);
        $conversation = null;

        if ($conversationid) {
            $conversation = \core_message\api::get_conversation(
                $params['userid'],
                $conversationid,
                $params['includecontactrequests'],
                $params['includeprivacyinfo'],
                $params['memberlimit'],
                $params['memberoffset'],
                $params['messagelimit'],
                $params['messageoffset'],
                $params['newestmessagesfirst']
            );
        }

        if ($conversation) {
            return $conversation;
        } else {
            // We have to throw an exception here because the external functions annoyingly
            // don't accept null to be returned for a single structure.
            throw new \moodle_exception('errorconversationdoesnotexist', 'message');
        }
    }
public static function get_conversation_between_users ( int $ userid , int $ otheruserid , bool $ includecontactrequests = false , bool $ includeprivacyinfo = false , int $ memberlimit = 0 , int $ memberoffset = 0 , int $ messagelimit = 0 , int $ messageoffset = 0 , bool $ newestmessagesfirst = true ) { global $ CFG , $ DB , $ USER ; // All the standard BL checks. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } $ params = [ 'userid' => $ userid , 'otheruserid' => $ otheruserid , 'includecontactrequests' => $ includecontactrequests , 'includeprivacyinfo' => $ includeprivacyinfo , 'memberlimit' => $ memberlimit , 'memberoffset' => $ memberoffset , 'messagelimit' => $ messagelimit , 'messageoffset' => $ messageoffset , 'newestmessagesfirst' => $ newestmessagesfirst ] ; self :: validate_parameters ( self :: get_conversation_between_users_parameters ( ) , $ params ) ; $ systemcontext = context_system :: instance ( ) ; self :: validate_context ( $ systemcontext ) ; $ conversationid = \ core_message \ api :: get_conversation_between_users ( [ $ params [ 'userid' ] , $ params [ 'otheruserid' ] ] ) ; $ conversation = null ; if ( $ conversationid ) { $ conversation = \ core_message \ api :: get_conversation ( $ params [ 'userid' ] , $ conversationid , $ params [ 'includecontactrequests' ] , $ params [ 'includeprivacyinfo' ] , $ params [ 'memberlimit' ] , $ params [ 'memberoffset' ] , $ params [ 'messagelimit' ] , $ params [ 'messageoffset' ] , $ params [ 'newestmessagesfirst' ] ) ; } if ( $ conversation ) { return $ conversation ; } else { // We have to throw an exception here because the external functions annoyingly // don't accept null to be returned for a single structure. throw new \ moodle_exception ( 'errorconversationdoesnotexist' , 'message' ) ; } }
Get a single conversation between users.

@param int $userid The user id to get the conversation for
@param int $otheruserid The other user id
@param bool $includecontactrequests Should contact requests be included between members
@param bool $includeprivacyinfo Should privacy info be included between members
@param int $memberlimit Limit number of members to load
@param int $memberoffset Offset members by this amount
@param int $messagelimit Limit number of messages to load
@param int $messageoffset Offset the messages
@param bool $newestmessagesfirst Order messages by newest first
@return stdClass
@throws \moodle_exception if the messaging feature is disabled on the site.
Get a single conversation between users .