original_string: public static function get_self_conversation(
          int $userid,
          int $messagelimit = 0,
          int $messageoffset = 0,
          bool $newestmessagesfirst = true
      ) {
          global $CFG;
  
          // All the standard BL checks.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          $params = [
              'userid' => $userid,
              'messagelimit' => $messagelimit,
              'messageoffset' => $messageoffset,
              'newestmessagesfirst' => $newestmessagesfirst
          ];
          self::validate_parameters(self::get_self_conversation_parameters(), $params);
  
          $systemcontext = context_system::instance();
          self::validate_context($systemcontext);
  
          $conversation = \core_message\api::get_self_conversation($params['userid']);
  
          if ($conversation) {
              $conversation = \core_message\api::get_conversation(
                  $params['userid'],
                  $conversation->id,
                  false,
                  false,
                  0,
                  0,
                  $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');
          }
      }
code: public static function get_self_conversation(
          int $userid,
          int $messagelimit = 0,
          int $messageoffset = 0,
          bool $newestmessagesfirst = true
      ) {
          global $CFG;
  
          // All the standard BL checks.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          $params = [
              'userid' => $userid,
              'messagelimit' => $messagelimit,
              'messageoffset' => $messageoffset,
              'newestmessagesfirst' => $newestmessagesfirst
          ];
          self::validate_parameters(self::get_self_conversation_parameters(), $params);
  
          $systemcontext = context_system::instance();
          self::validate_context($systemcontext);
  
          $conversation = \core_message\api::get_self_conversation($params['userid']);
  
          if ($conversation) {
              $conversation = \core_message\api::get_conversation(
                  $params['userid'],
                  $conversation->id,
                  false,
                  false,
                  0,
                  0,
                  $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');
          }
      }
code_tokens: public static function get_self_conversation ( int $ userid , int $ messagelimit = 0 , int $ messageoffset = 0 , bool $ newestmessagesfirst = true ) { global $ CFG ; // All the standard BL checks. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } $ params = [ 'userid' => $ userid , 'messagelimit' => $ messagelimit , 'messageoffset' => $ messageoffset , 'newestmessagesfirst' => $ newestmessagesfirst ] ; self :: validate_parameters ( self :: get_self_conversation_parameters ( ) , $ params ) ; $ systemcontext = context_system :: instance ( ) ; self :: validate_context ( $ systemcontext ) ; $ conversation = \ core_message \ api :: get_self_conversation ( $ params [ 'userid' ] ) ; if ( $ conversation ) { $ conversation = \ core_message \ api :: get_conversation ( $ params [ 'userid' ] , $ conversation -> id , false , false , 0 , 0 , $ 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' ) ; } }
docstring: Get a single self-conversation.
  
  @param int $userid The user id to get the self-conversation for
  @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.
  @since Moodle 3.7
docstring_tokens: Get a single self - conversation .