original_string: public static function get_context_instance_customdata(\context $context) {
  
          $persistent = \tool_dataprivacy\context_instance::get_record_by_contextid($context->id, false);
          if (!$persistent) {
              $persistent = new \tool_dataprivacy\context_instance();
              $persistent->set('contextid', $context->id);
          }
  
          $purposes = [];
          foreach (api::get_purposes() as $purpose) {
              $purposes[$purpose->get('id')] = $purpose;
          }
          $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options($purposes);
          $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options(api::get_categories());
  
          $customdata = [
              'context' => $context,
              'subjectscope' => data_registry::get_subject_scope($context),
              'contextname' => $context->get_context_name(),
              'persistent' => $persistent,
              'purposes' => $purposeoptions,
              'categories' => $categoryoptions,
          ];
  
          $effectivepurpose = api::get_effective_context_purpose($context);
          if ($effectivepurpose) {
  
              $customdata['currentretentionperiod'] = self::get_retention_display_text($effectivepurpose, $context->contextlevel,
                  $context);
  
              $customdata['purposeretentionperiods'] = [];
              foreach (array_keys($purposeoptions) as $optionvalue) {
  
                  if (isset($purposes[$optionvalue])) {
                      $purpose = $purposes[$optionvalue];
                  } else {
                      // Get the effective purpose if $optionvalue would be the selected value.
                      $purpose = api::get_effective_context_purpose($context, $optionvalue);
                  }
  
                  $retentionperiod = self::get_retention_display_text(
                      $purpose,
                      $context->contextlevel,
                      $context
                  );
                  $customdata['purposeretentionperiods'][$optionvalue] = $retentionperiod;
              }
          }
  
          return $customdata;
      }
code: public static function get_context_instance_customdata(\context $context) {
  
          $persistent = \tool_dataprivacy\context_instance::get_record_by_contextid($context->id, false);
          if (!$persistent) {
              $persistent = new \tool_dataprivacy\context_instance();
              $persistent->set('contextid', $context->id);
          }
  
          $purposes = [];
          foreach (api::get_purposes() as $purpose) {
              $purposes[$purpose->get('id')] = $purpose;
          }
          $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options($purposes);
          $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options(api::get_categories());
  
          $customdata = [
              'context' => $context,
              'subjectscope' => data_registry::get_subject_scope($context),
              'contextname' => $context->get_context_name(),
              'persistent' => $persistent,
              'purposes' => $purposeoptions,
              'categories' => $categoryoptions,
          ];
  
          $effectivepurpose = api::get_effective_context_purpose($context);
          if ($effectivepurpose) {
  
              $customdata['currentretentionperiod'] = self::get_retention_display_text($effectivepurpose, $context->contextlevel,
                  $context);
  
              $customdata['purposeretentionperiods'] = [];
              foreach (array_keys($purposeoptions) as $optionvalue) {
  
                  if (isset($purposes[$optionvalue])) {
                      $purpose = $purposes[$optionvalue];
                  } else {
                      // Get the effective purpose if $optionvalue would be the selected value.
                      $purpose = api::get_effective_context_purpose($context, $optionvalue);
                  }
  
                  $retentionperiod = self::get_retention_display_text(
                      $purpose,
                      $context->contextlevel,
                      $context
                  );
                  $customdata['purposeretentionperiods'][$optionvalue] = $retentionperiod;
              }
          }
  
          return $customdata;
      }
code_tokens: public static function get_context_instance_customdata ( \ context $ context ) { $ persistent = \ tool_dataprivacy \ context_instance :: get_record_by_contextid ( $ context -> id , false ) ; if ( ! $ persistent ) { $ persistent = new \ tool_dataprivacy \ context_instance ( ) ; $ persistent -> set ( 'contextid' , $ context -> id ) ; } $ purposes = [ ] ; foreach ( api :: get_purposes ( ) as $ purpose ) { $ purposes [ $ purpose -> get ( 'id' ) ] = $ purpose ; } $ purposeoptions = \ tool_dataprivacy \ output \ data_registry_page :: purpose_options ( $ purposes ) ; $ categoryoptions = \ tool_dataprivacy \ output \ data_registry_page :: category_options ( api :: get_categories ( ) ) ; $ customdata = [ 'context' => $ context , 'subjectscope' => data_registry :: get_subject_scope ( $ context ) , 'contextname' => $ context -> get_context_name ( ) , 'persistent' => $ persistent , 'purposes' => $ purposeoptions , 'categories' => $ categoryoptions , ] ; $ effectivepurpose = api :: get_effective_context_purpose ( $ context ) ; if ( $ effectivepurpose ) { $ customdata [ 'currentretentionperiod' ] = self :: get_retention_display_text ( $ effectivepurpose , $ context -> contextlevel , $ context ) ; $ customdata [ 'purposeretentionperiods' ] = [ ] ; foreach ( array_keys ( $ purposeoptions ) as $ optionvalue ) { if ( isset ( $ purposes [ $ optionvalue ] ) ) { $ purpose = $ purposes [ $ optionvalue ] ; } else { // Get the effective purpose if $optionvalue would be the selected value. $ purpose = api :: get_effective_context_purpose ( $ context , $ optionvalue ) ; } $ retentionperiod = self :: get_retention_display_text ( $ purpose , $ context -> contextlevel , $ context ) ; $ customdata [ 'purposeretentionperiods' ] [ $ optionvalue ] = $ retentionperiod ; } } return $ customdata ; }
docstring: Returns the customdata array for the provided context instance.
  
  @param \context $context
  @return array
docstring_tokens: Returns the customdata array for the provided context instance .