original_string: public static function create_conversation(int $type, array $userids, string $name = null,
              int $enabled = self::MESSAGE_CONVERSATION_ENABLED, string $component = null,
              string $itemtype = null, int $itemid = null, int $contextid = null) {
  
          global $DB;
  
          $validtypes = [
              self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
              self::MESSAGE_CONVERSATION_TYPE_GROUP,
              self::MESSAGE_CONVERSATION_TYPE_SELF
          ];
  
          if (!in_array($type, $validtypes)) {
              throw new \moodle_exception('An invalid conversation type was specified.');
          }
  
          // Sanity check.
          if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
              if (count($userids) > 2) {
                  throw new \moodle_exception('An individual conversation can not have more than two users.');
              }
              if ($userids[0] == $userids[1]) {
                  throw new \moodle_exception('Trying to create an individual conversation instead of a self conversation.');
              }
          } else if ($type == self::MESSAGE_CONVERSATION_TYPE_SELF) {
              if (count($userids) != 1) {
                  throw new \moodle_exception('A self conversation can not have more than one user.');
              }
          }
  
          $conversation = new \stdClass();
          $conversation->type = $type;
          $conversation->name = $name;
          $conversation->convhash = null;
          if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL || $type == self::MESSAGE_CONVERSATION_TYPE_SELF) {
              $conversation->convhash = helper::get_conversation_hash($userids);
          }
          $conversation->component = $component;
          $conversation->itemtype = $itemtype;
          $conversation->itemid = $itemid;
          $conversation->contextid = $contextid;
          $conversation->enabled = $enabled;
          $conversation->timecreated = time();
          $conversation->timemodified = $conversation->timecreated;
          $conversation->id = $DB->insert_record('message_conversations', $conversation);
  
          // Add users to this conversation.
          $arrmembers = [];
          foreach ($userids as $userid) {
              $member = new \stdClass();
              $member->conversationid = $conversation->id;
              $member->userid = $userid;
              $member->timecreated = time();
              $member->id = $DB->insert_record('message_conversation_members', $member);
  
              $arrmembers[] = $member;
          }
  
          $conversation->members = $arrmembers;
  
          return $conversation;
      }
code: public static function create_conversation(int $type, array $userids, string $name = null,
              int $enabled = self::MESSAGE_CONVERSATION_ENABLED, string $component = null,
              string $itemtype = null, int $itemid = null, int $contextid = null) {
  
          global $DB;
  
          $validtypes = [
              self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
              self::MESSAGE_CONVERSATION_TYPE_GROUP,
              self::MESSAGE_CONVERSATION_TYPE_SELF
          ];
  
          if (!in_array($type, $validtypes)) {
              throw new \moodle_exception('An invalid conversation type was specified.');
          }
  
          // Sanity check.
          if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
              if (count($userids) > 2) {
                  throw new \moodle_exception('An individual conversation can not have more than two users.');
              }
              if ($userids[0] == $userids[1]) {
                  throw new \moodle_exception('Trying to create an individual conversation instead of a self conversation.');
              }
          } else if ($type == self::MESSAGE_CONVERSATION_TYPE_SELF) {
              if (count($userids) != 1) {
                  throw new \moodle_exception('A self conversation can not have more than one user.');
              }
          }
  
          $conversation = new \stdClass();
          $conversation->type = $type;
          $conversation->name = $name;
          $conversation->convhash = null;
          if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL || $type == self::MESSAGE_CONVERSATION_TYPE_SELF) {
              $conversation->convhash = helper::get_conversation_hash($userids);
          }
          $conversation->component = $component;
          $conversation->itemtype = $itemtype;
          $conversation->itemid = $itemid;
          $conversation->contextid = $contextid;
          $conversation->enabled = $enabled;
          $conversation->timecreated = time();
          $conversation->timemodified = $conversation->timecreated;
          $conversation->id = $DB->insert_record('message_conversations', $conversation);
  
          // Add users to this conversation.
          $arrmembers = [];
          foreach ($userids as $userid) {
              $member = new \stdClass();
              $member->conversationid = $conversation->id;
              $member->userid = $userid;
              $member->timecreated = time();
              $member->id = $DB->insert_record('message_conversation_members', $member);
  
              $arrmembers[] = $member;
          }
  
          $conversation->members = $arrmembers;
  
          return $conversation;
      }
code_tokens: public static function create_conversation ( int $ type , array $ userids , string $ name = null , int $ enabled = self :: MESSAGE_CONVERSATION_ENABLED , string $ component = null , string $ itemtype = null , int $ itemid = null , int $ contextid = null ) { global $ DB ; $ validtypes = [ self :: MESSAGE_CONVERSATION_TYPE_INDIVIDUAL , self :: MESSAGE_CONVERSATION_TYPE_GROUP , self :: MESSAGE_CONVERSATION_TYPE_SELF ] ; if ( ! in_array ( $ type , $ validtypes ) ) { throw new \ moodle_exception ( 'An invalid conversation type was specified.' ) ; } // Sanity check. if ( $ type == self :: MESSAGE_CONVERSATION_TYPE_INDIVIDUAL ) { if ( count ( $ userids ) > 2 ) { throw new \ moodle_exception ( 'An individual conversation can not have more than two users.' ) ; } if ( $ userids [ 0 ] == $ userids [ 1 ] ) { throw new \ moodle_exception ( 'Trying to create an individual conversation instead of a self conversation.' ) ; } } else if ( $ type == self :: MESSAGE_CONVERSATION_TYPE_SELF ) { if ( count ( $ userids ) != 1 ) { throw new \ moodle_exception ( 'A self conversation can not have more than one user.' ) ; } } $ conversation = new \ stdClass ( ) ; $ conversation -> type = $ type ; $ conversation -> name = $ name ; $ conversation -> convhash = null ; if ( $ type == self :: MESSAGE_CONVERSATION_TYPE_INDIVIDUAL || $ type == self :: MESSAGE_CONVERSATION_TYPE_SELF ) { $ conversation -> convhash = helper :: get_conversation_hash ( $ userids ) ; } $ conversation -> component = $ component ; $ conversation -> itemtype = $ itemtype ; $ conversation -> itemid = $ itemid ; $ conversation -> contextid = $ contextid ; $ conversation -> enabled = $ enabled ; $ conversation -> timecreated = time ( ) ; $ conversation -> timemodified = $ conversation -> timecreated ; $ conversation -> id = $ DB -> insert_record ( 'message_conversations' , $ conversation ) ; // Add users to this conversation. $ arrmembers = [ ] ; foreach ( $ userids as $ userid ) { $ member = new \ stdClass ( ) ; $ member -> conversationid = $ conversation -> id ; $ member -> userid = $ userid ; $ member -> timecreated = time ( ) ; $ member -> id = $ DB -> insert_record ( 'message_conversation_members' , $ member ) ; $ arrmembers [ ] = $ member ; } $ conversation -> members = $ arrmembers ; return $ conversation ; }
docstring: Creates a conversation with selected users and messages.
  
  @param int $type The type of conversation
  @param int[] $userids The array of users to add to the conversation
  @param string|null $name The name of the conversation
  @param int $enabled Determines if the conversation is created enabled or disabled
  @param string|null $component Defines the Moodle component which the conversation belongs to, if any
  @param string|null $itemtype Defines the type of the component
  @param int|null $itemid The id of the component
  @param int|null $contextid The id of the context
  @return \stdClass
docstring_tokens: Creates a conversation with selected users and messages .