original_string: public static function get_approved_contextlist_collection_for_collection(contextlist_collection $collection,
              \stdClass $foruser, int $type) : contextlist_collection {
  
          // Create the approved contextlist collection object.
          $approvedcollection = new contextlist_collection($collection->get_userid());
          $isconfigured = data_registry::defaults_set();
  
          foreach ($collection as $contextlist) {
              $contextids = [];
              foreach ($contextlist as $context) {
                  if ($isconfigured && self::DATAREQUEST_TYPE_DELETE == $type) {
                      // Data can only be deleted from it if the context is either expired, or unprotected.
                      // Note: We can only check whether a context is expired or unprotected if the site is configured and
                      // defaults are set appropriately. If they are not, we treat all contexts as though they are
                      // unprotected.
                      $purpose = static::get_effective_context_purpose($context);
                      if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
                          continue;
                      }
                  }
  
                  $contextids[] = $context->id;
              }
  
              // The data for the last component contextlist won't have been written yet, so write it now.
              if (!empty($contextids)) {
                  $approvedcollection->add_contextlist(
                          new approved_contextlist($foruser, $contextlist->get_component(), $contextids)
                      );
              }
          }
  
          return $approvedcollection;
      }
code: public static function get_approved_contextlist_collection_for_collection(contextlist_collection $collection,
              \stdClass $foruser, int $type) : contextlist_collection {
  
          // Create the approved contextlist collection object.
          $approvedcollection = new contextlist_collection($collection->get_userid());
          $isconfigured = data_registry::defaults_set();
  
          foreach ($collection as $contextlist) {
              $contextids = [];
              foreach ($contextlist as $context) {
                  if ($isconfigured && self::DATAREQUEST_TYPE_DELETE == $type) {
                      // Data can only be deleted from it if the context is either expired, or unprotected.
                      // Note: We can only check whether a context is expired or unprotected if the site is configured and
                      // defaults are set appropriately. If they are not, we treat all contexts as though they are
                      // unprotected.
                      $purpose = static::get_effective_context_purpose($context);
                      if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
                          continue;
                      }
                  }
  
                  $contextids[] = $context->id;
              }
  
              // The data for the last component contextlist won't have been written yet, so write it now.
              if (!empty($contextids)) {
                  $approvedcollection->add_contextlist(
                          new approved_contextlist($foruser, $contextlist->get_component(), $contextids)
                      );
              }
          }
  
          return $approvedcollection;
      }
code_tokens: public static function get_approved_contextlist_collection_for_collection ( contextlist_collection $ collection , \ stdClass $ foruser , int $ type ) : contextlist_collection { // Create the approved contextlist collection object. $ approvedcollection = new contextlist_collection ( $ collection -> get_userid ( ) ) ; $ isconfigured = data_registry :: defaults_set ( ) ; foreach ( $ collection as $ contextlist ) { $ contextids = [ ] ; foreach ( $ contextlist as $ context ) { if ( $ isconfigured && self :: DATAREQUEST_TYPE_DELETE == $ type ) { // Data can only be deleted from it if the context is either expired, or unprotected. // Note: We can only check whether a context is expired or unprotected if the site is configured and // defaults are set appropriately. If they are not, we treat all contexts as though they are // unprotected. $ purpose = static :: get_effective_context_purpose ( $ context ) ; if ( ! expired_contexts_manager :: is_context_expired_or_unprotected_for_user ( $ context , $ foruser ) ) { continue ; } } $ contextids [ ] = $ context -> id ; } // The data for the last component contextlist won't have been written yet, so write it now. if ( ! empty ( $ contextids ) ) { $ approvedcollection -> add_contextlist ( new approved_contextlist ( $ foruser , $ contextlist -> get_component ( ) , $ contextids ) ) ; } } return $ approvedcollection ; }
docstring: Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.
  
  @param   contextlist_collection  $collection The collection of unapproved contextlist objects.
  @param   \stdClass               $foruser The target user
  @param   int                     $type The purpose of the collection
  @return  contextlist_collection  The collection of approved_contextlist objects.
docstring_tokens: Finds all contextlists having at least one approved context and returns them as in a contextlist_collection .