public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, int $type = null, bool $favourites = null,
            bool $mergeself = false) {
        global $CFG, $USER;

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

        $params = array(
            'userid' => $userid,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum,
            'type' => $type,
            'favourites' => $favourites,
            'mergeself' => $mergeself
        );
        $params = self::validate_parameters(self::get_conversations_parameters(), $params);

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

        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        $conversations = \core_message\api::get_conversations(
            $params['userid'],
            $params['limitfrom'],
            $params['limitnum'],
            $params['type'],
            $params['favourites'],
            $params['mergeself']
        );

        return (object) ['conversations' => $conversations];
    }
public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, int $type = null, bool $favourites = null,
            bool $mergeself = false) {
        global $CFG, $USER;

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

        $params = array(
            'userid' => $userid,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum,
            'type' => $type,
            'favourites' => $favourites,
            'mergeself' => $mergeself
        );
        $params = self::validate_parameters(self::get_conversations_parameters(), $params);

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

        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        $conversations = \core_message\api::get_conversations(
            $params['userid'],
            $params['limitfrom'],
            $params['limitnum'],
            $params['type'],
            $params['favourites'],
            $params['mergeself']
        );

        return (object) ['conversations' => $conversations];
    }
public static function get_conversations ( $ userid , $ limitfrom = 0 , $ limitnum = 0 , int $ type = null , bool $ favourites = null , bool $ mergeself = false ) { global $ CFG , $ USER ; // All the standard BL checks. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } $ params = array ( 'userid' => $ userid , 'limitfrom' => $ limitfrom , 'limitnum' => $ limitnum , 'type' => $ type , 'favourites' => $ favourites , 'mergeself' => $ mergeself ) ; $ params = self :: validate_parameters ( self :: get_conversations_parameters ( ) , $ params ) ; $ systemcontext = context_system :: instance ( ) ; self :: validate_context ( $ systemcontext ) ; if ( ( $ USER -> id != $ params [ 'userid' ] ) && ! has_capability ( 'moodle/site:readallmessages' , $ systemcontext ) ) { throw new moodle_exception ( 'You do not have permission to perform this action.' ) ; } $ conversations = \ core_message \ api :: get_conversations ( $ params [ 'userid' ] , $ params [ 'limitfrom' ] , $ params [ 'limitnum' ] , $ params [ 'type' ] , $ params [ 'favourites' ] , $ params [ 'mergeself' ] ) ; return ( object ) [ 'conversations' => $ conversations ] ; }
Get the list of conversations for the user.

@param int $userid The id of the user who is performing the search
@param int $limitfrom
@param int $limitnum
@param int|null $type
@param bool|null $favourites
@param bool $mergeself whether to include self-conversations (true) or ONLY private conversations (false)
when private conversations are requested.
@return stdClass
@throws \moodle_exception if the messaging feature is disabled on the site.
@since 3.2
Get the list of conversations for the user .