original_string: public static function export_context_data(\core_privacy\local\request\contextlist_collection $contextlistcollection) {
          global $DB;
  
          $coursecontextids = $DB->get_records_menu('context', ['contextlevel' => CONTEXT_COURSE], '', 'id, instanceid');
          $courseids = [];
          foreach ($contextlistcollection as $component) {
              foreach ($component->get_contexts() as $context) {
                  // All course contexts have been accounted for, so skip all checks.
                  if (empty($coursecontextids)) {
                      break;
                  }
                  // Only course, module, and block contexts are checked.
                  if (in_array($context->contextlevel, [CONTEXT_USER, CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
                      continue;
                  }
                  // If the context is a course, then we just add it without the need to check context path.
                  if ($context->contextlevel == CONTEXT_COURSE) {
                      $courseids[$context->id] = $context->instanceid;
                      unset($coursecontextids[$context->id]);
                      continue;
                  }
                  // Otherwise, we need to check all the course context paths, to see if this context is a descendant.
                  foreach ($coursecontextids as $contextid => $instanceid) {
                      if (stripos($context->path, '/' . $contextid . '/') !== false) {
                          $courseids[$contextid] = $instanceid;
                          unset($coursecontextids[$contextid]);
                      }
                  }
              }
          }
          if (empty($courseids)) {
              return;
          }
  
          // Export general data for these contexts.
          list($sql, $params) = $DB->get_in_or_equal($courseids);
          $sql = 'id ' . $sql;
          $coursedata = $DB->get_records_select('course', $sql, $params);
  
          foreach ($coursedata as $course) {
              $context = \context_course::instance($course->id);
              $courseformat = $course->format !== 'site' ? get_string('pluginname', 'format_' . $course->format) : get_string('site');
              $data = (object) [
                  'fullname' => $course->fullname,
                  'shortname' => $course->shortname,
                  'idnumber' => $course->idnumber,
                  'summary' => writer::with_context($context)->rewrite_pluginfile_urls([], 'course', 'summary', 0,
                                                                                       format_string($course->summary)),
                  'format' => $courseformat,
                  'startdate' => transform::datetime($course->startdate),
                  'enddate' => transform::datetime($course->enddate)
              ];
              writer::with_context($context)
                      ->export_area_files([], 'course', 'summary', 0)
                      ->export_area_files([], 'course', 'overviewfiles', 0)
                      ->export_data([], $data);
          }
      }
code: public static function export_context_data(\core_privacy\local\request\contextlist_collection $contextlistcollection) {
          global $DB;
  
          $coursecontextids = $DB->get_records_menu('context', ['contextlevel' => CONTEXT_COURSE], '', 'id, instanceid');
          $courseids = [];
          foreach ($contextlistcollection as $component) {
              foreach ($component->get_contexts() as $context) {
                  // All course contexts have been accounted for, so skip all checks.
                  if (empty($coursecontextids)) {
                      break;
                  }
                  // Only course, module, and block contexts are checked.
                  if (in_array($context->contextlevel, [CONTEXT_USER, CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
                      continue;
                  }
                  // If the context is a course, then we just add it without the need to check context path.
                  if ($context->contextlevel == CONTEXT_COURSE) {
                      $courseids[$context->id] = $context->instanceid;
                      unset($coursecontextids[$context->id]);
                      continue;
                  }
                  // Otherwise, we need to check all the course context paths, to see if this context is a descendant.
                  foreach ($coursecontextids as $contextid => $instanceid) {
                      if (stripos($context->path, '/' . $contextid . '/') !== false) {
                          $courseids[$contextid] = $instanceid;
                          unset($coursecontextids[$contextid]);
                      }
                  }
              }
          }
          if (empty($courseids)) {
              return;
          }
  
          // Export general data for these contexts.
          list($sql, $params) = $DB->get_in_or_equal($courseids);
          $sql = 'id ' . $sql;
          $coursedata = $DB->get_records_select('course', $sql, $params);
  
          foreach ($coursedata as $course) {
              $context = \context_course::instance($course->id);
              $courseformat = $course->format !== 'site' ? get_string('pluginname', 'format_' . $course->format) : get_string('site');
              $data = (object) [
                  'fullname' => $course->fullname,
                  'shortname' => $course->shortname,
                  'idnumber' => $course->idnumber,
                  'summary' => writer::with_context($context)->rewrite_pluginfile_urls([], 'course', 'summary', 0,
                                                                                       format_string($course->summary)),
                  'format' => $courseformat,
                  'startdate' => transform::datetime($course->startdate),
                  'enddate' => transform::datetime($course->enddate)
              ];
              writer::with_context($context)
                      ->export_area_files([], 'course', 'summary', 0)
                      ->export_area_files([], 'course', 'overviewfiles', 0)
                      ->export_data([], $data);
          }
      }
code_tokens: public static function export_context_data ( \ core_privacy \ local \ request \ contextlist_collection $ contextlistcollection ) { global $ DB ; $ coursecontextids = $ DB -> get_records_menu ( 'context' , [ 'contextlevel' => CONTEXT_COURSE ] , '' , 'id, instanceid' ) ; $ courseids = [ ] ; foreach ( $ contextlistcollection as $ component ) { foreach ( $ component -> get_contexts ( ) as $ context ) { // All course contexts have been accounted for, so skip all checks. if ( empty ( $ coursecontextids ) ) { break ; } // Only course, module, and block contexts are checked. if ( in_array ( $ context -> contextlevel , [ CONTEXT_USER , CONTEXT_SYSTEM , CONTEXT_COURSECAT ] ) ) { continue ; } // If the context is a course, then we just add it without the need to check context path. if ( $ context -> contextlevel == CONTEXT_COURSE ) { $ courseids [ $ context -> id ] = $ context -> instanceid ; unset ( $ coursecontextids [ $ context -> id ] ) ; continue ; } // Otherwise, we need to check all the course context paths, to see if this context is a descendant. foreach ( $ coursecontextids as $ contextid => $ instanceid ) { if ( stripos ( $ context -> path , '/' . $ contextid . '/' ) !== false ) { $ courseids [ $ contextid ] = $ instanceid ; unset ( $ coursecontextids [ $ contextid ] ) ; } } } } if ( empty ( $ courseids ) ) { return ; } // Export general data for these contexts. list ( $ sql , $ params ) = $ DB -> get_in_or_equal ( $ courseids ) ; $ sql = 'id ' . $ sql ; $ coursedata = $ DB -> get_records_select ( 'course' , $ sql , $ params ) ; foreach ( $ coursedata as $ course ) { $ context = \ context_course :: instance ( $ course -> id ) ; $ courseformat = $ course -> format !== 'site' ? get_string ( 'pluginname' , 'format_' . $ course -> format ) : get_string ( 'site' ) ; $ data = ( object ) [ 'fullname' => $ course -> fullname , 'shortname' => $ course -> shortname , 'idnumber' => $ course -> idnumber , 'summary' => writer :: with_context ( $ context ) -> rewrite_pluginfile_urls ( [ ] , 'course' , 'summary' , 0 , format_string ( $ course -> summary ) ) , 'format' => $ courseformat , 'startdate' => transform :: datetime ( $ course -> startdate ) , 'enddate' => transform :: datetime ( $ course -> enddate ) ] ; writer :: with_context ( $ context ) -> export_area_files ( [ ] , 'course' , 'summary' , 0 ) -> export_area_files ( [ ] , 'course' , 'overviewfiles' , 0 ) -> export_data ( [ ] , $ data ) ; } }
docstring: Give the component a chance to include any contextual information deemed relevant to any child contexts which are
  exporting personal data.
  
  By giving the component access to the full list of contexts being exported across all components, it can determine whether a
  descendant context is being exported, and decide whether to add relevant contextual information about itself. Having access
  to the full list of contexts being exported is what makes this component a context aware provider.
  
  E.g.
  If, during the core export process, a course module is included in the contextlist_collection but the course containing the
  module is not (perhaps there's no longer a user enrolment), then the course should include general contextual information in
  the export so we know basic details about which course the module belongs to. This method allows the course to make that
  decision, based on the existence of any decendant module contexts in the collection.
  
  @param \core_privacy\local\request\contextlist_collection $contextlistcollection
docstring_tokens: Give the component a chance to include any contextual information deemed relevant to any child contexts which are exporting personal data .