protected function get_users_messages_for_conversation(int $conversationid, int $userid) : moodle_recordset {
        global $DB;

        $usernamefields = \user_picture::fields('u');
        $sql = "SELECT $usernamefields, m.*
                  FROM {messages} m
                  JOIN {user} u
                    ON u.id = m.useridfrom
                  JOIN {message_email_messages} mem
                    ON mem.messageid = m.id
                 WHERE mem.useridto = ?
                   AND mem.conversationid = ?
                   AND mem.id <= ?";

        return $DB->get_recordset_sql($sql, [$userid, $conversationid, $this->maxid]);
    }
protected function get_users_messages_for_conversation(int $conversationid, int $userid) : moodle_recordset {
        global $DB;

        $usernamefields = \user_picture::fields('u');
        $sql = "SELECT $usernamefields, m.*
                  FROM {messages} m
                  JOIN {user} u
                    ON u.id = m.useridfrom
                  JOIN {message_email_messages} mem
                    ON mem.messageid = m.id
                 WHERE mem.useridto = ?
                   AND mem.conversationid = ?
                   AND mem.id <= ?";

        return $DB->get_recordset_sql($sql, [$userid, $conversationid, $this->maxid]);
    }
protected function get_users_messages_for_conversation ( int $ conversationid , int $ userid ) : moodle_recordset { global $ DB ; $ usernamefields = \ user_picture :: fields ( 'u' ) ; $ sql = "SELECT $usernamefields, m.*
                  FROM {messages} m
                  JOIN {user} u
                    ON u.id = m.useridfrom
                  JOIN {message_email_messages} mem
                    ON mem.messageid = m.id
                 WHERE mem.useridto = ?
                   AND mem.conversationid = ?
                   AND mem.id <= ?" ; return $ DB -> get_recordset_sql ( $ sql , [ $ userid , $ conversationid , $ this -> maxid ] ) ; }
Returns the messages to send to a user for a given conversation

@param int $conversationid
@param int $userid
@return moodle_recordset A moodle_recordset instance.
Returns the messages to send to a user for a given conversation