original_string: public static function set_contextlevel($record) {
          global $DB;
  
          if ($record->contextlevel != CONTEXT_SYSTEM && $record->contextlevel != CONTEXT_USER) {
              throw new \coding_exception('Only context system and context user can set a contextlevel ' .
                  'purpose and retention');
          }
  
          if ($contextlevel = contextlevel::get_record_by_contextlevel($record->contextlevel, false)) {
              // Update.
              $contextlevel->from_record($record);
          } else {
              // Add.
              $contextlevel = new contextlevel(0, $record);
          }
          $contextlevel->save();
  
          // We sync with their defaults as we removed these options from the defaults page.
          $classname = \context_helper::get_class_for_level($record->contextlevel);
          list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname);
          set_config($purposevar, $record->purposeid, 'tool_dataprivacy');
          set_config($categoryvar, $record->categoryid, 'tool_dataprivacy');
  
          return $contextlevel;
      }
code: public static function set_contextlevel($record) {
          global $DB;
  
          if ($record->contextlevel != CONTEXT_SYSTEM && $record->contextlevel != CONTEXT_USER) {
              throw new \coding_exception('Only context system and context user can set a contextlevel ' .
                  'purpose and retention');
          }
  
          if ($contextlevel = contextlevel::get_record_by_contextlevel($record->contextlevel, false)) {
              // Update.
              $contextlevel->from_record($record);
          } else {
              // Add.
              $contextlevel = new contextlevel(0, $record);
          }
          $contextlevel->save();
  
          // We sync with their defaults as we removed these options from the defaults page.
          $classname = \context_helper::get_class_for_level($record->contextlevel);
          list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname);
          set_config($purposevar, $record->purposeid, 'tool_dataprivacy');
          set_config($categoryvar, $record->categoryid, 'tool_dataprivacy');
  
          return $contextlevel;
      }
code_tokens: public static function set_contextlevel ( $ record ) { global $ DB ; if ( $ record -> contextlevel != CONTEXT_SYSTEM && $ record -> contextlevel != CONTEXT_USER ) { throw new \ coding_exception ( 'Only context system and context user can set a contextlevel ' . 'purpose and retention' ) ; } if ( $ contextlevel = contextlevel :: get_record_by_contextlevel ( $ record -> contextlevel , false ) ) { // Update. $ contextlevel -> from_record ( $ record ) ; } else { // Add. $ contextlevel = new contextlevel ( 0 , $ record ) ; } $ contextlevel -> save ( ) ; // We sync with their defaults as we removed these options from the defaults page. $ classname = \ context_helper :: get_class_for_level ( $ record -> contextlevel ) ; list ( $ purposevar , $ categoryvar ) = data_registry :: var_names_from_context ( $ classname ) ; set_config ( $ purposevar , $ record -> purposeid , 'tool_dataprivacy' ) ; set_config ( $ categoryvar , $ record -> categoryid , 'tool_dataprivacy' ) ; return $ contextlevel ; }
docstring: Sets the context level purpose and category.
  
  @throws \coding_exception
  @param \stdClass $record
  @return contextlevel
docstring_tokens: Sets the context level purpose and category .