original_string: public static function export_conversations(int $userid, string $component, string $itemtype, \context $context,
                                                  array $subcontext = [], int $itemid = 0) {
          global $DB;
  
          // Search for conversations for this user in this area.
          $sql = "SELECT DISTINCT mc.*
                    FROM {message_conversations} mc
                    JOIN {message_conversation_members} mcm
                      ON (mcm.conversationid = mc.id AND mcm.userid = :userid)";
          $params = [
              'userid' => $userid
          ];
  
          // Get the conversations for the defined component and itemtype.
          if (!empty($component) && !empty($itemtype)) {
              $sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype";
              $params['component'] = $component;
              $params['itemtype'] = $itemtype;
              if (!empty($itemid)) {
                  $sql .= " AND mc.itemid = :itemid";
                  $params['itemid'] = $itemid;
              }
          } else {
              // Get all the conversations without any component and itemtype, so with null contextid.
              $sql .= " WHERE mc.contextid IS NULL";
          }
  
          if ($conversations = $DB->get_records_sql($sql, $params)) {
              // Export conversation messages.
              foreach ($conversations as $conversation) {
                  self::export_user_data_conversation_messages($userid, $conversation, $context, $subcontext);
              }
          }
      }
code: public static function export_conversations(int $userid, string $component, string $itemtype, \context $context,
                                                  array $subcontext = [], int $itemid = 0) {
          global $DB;
  
          // Search for conversations for this user in this area.
          $sql = "SELECT DISTINCT mc.*
                    FROM {message_conversations} mc
                    JOIN {message_conversation_members} mcm
                      ON (mcm.conversationid = mc.id AND mcm.userid = :userid)";
          $params = [
              'userid' => $userid
          ];
  
          // Get the conversations for the defined component and itemtype.
          if (!empty($component) && !empty($itemtype)) {
              $sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype";
              $params['component'] = $component;
              $params['itemtype'] = $itemtype;
              if (!empty($itemid)) {
                  $sql .= " AND mc.itemid = :itemid";
                  $params['itemid'] = $itemid;
              }
          } else {
              // Get all the conversations without any component and itemtype, so with null contextid.
              $sql .= " WHERE mc.contextid IS NULL";
          }
  
          if ($conversations = $DB->get_records_sql($sql, $params)) {
              // Export conversation messages.
              foreach ($conversations as $conversation) {
                  self::export_user_data_conversation_messages($userid, $conversation, $context, $subcontext);
              }
          }
      }
code_tokens: public static function export_conversations ( int $ userid , string $ component , string $ itemtype , \ context $ context , array $ subcontext = [ ] , int $ itemid = 0 ) { global $ DB ; // Search for conversations for this user in this area. $ sql = "SELECT DISTINCT mc.*
                    FROM {message_conversations} mc
                    JOIN {message_conversation_members} mcm
                      ON (mcm.conversationid = mc.id AND mcm.userid = :userid)" ; $ params = [ 'userid' => $ userid ] ; // Get the conversations for the defined component and itemtype. if ( ! empty ( $ component ) && ! empty ( $ itemtype ) ) { $ sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype" ; $ params [ 'component' ] = $ component ; $ params [ 'itemtype' ] = $ itemtype ; if ( ! empty ( $ itemid ) ) { $ sql .= " AND mc.itemid = :itemid" ; $ params [ 'itemid' ] = $ itemid ; } } else { // Get all the conversations without any component and itemtype, so with null contextid. $ sql .= " WHERE mc.contextid IS NULL" ; } if ( $ conversations = $ DB -> get_records_sql ( $ sql , $ params ) ) { // Export conversation messages. foreach ( $ conversations as $ conversation ) { self :: export_user_data_conversation_messages ( $ userid , $ conversation , $ context , $ subcontext ) ; } } }
docstring: Store all conversations which match the specified component, itemtype, and itemid.
  
  Conversations without context (for now, the private ones) are stored in '<$context> | Messages | <Other user id>'.
  Conversations with context are stored in '<$context> | Messages | <Conversation item type> | <Conversation name>'.
  
  @param   int         $userid The user whose information is to be exported.
  @param   string      $component The component to fetch data from.
  @param   string      $itemtype The itemtype that the data was exported in within the component.
  @param   \context    $context The context to export for.
  @param   array       $subcontext The sub-context in which to export this data.
  @param   int         $itemid Optional itemid associated with component.
docstring_tokens: Store all conversations which match the specified component itemtype and itemid .