original_string: public static function delete_data_for_user(approved_contextlist $contextlist) {
          global $DB;
  
          if (empty($contextlist->count())) {
              return;
          }
  
          $userid = $contextlist->get_user()->id;
          foreach ($contextlist->get_contexts() as $context) {
              if ($context instanceof \context_course) {
                  $select = "itemid = :itemid AND userid = :userid AND type = :type";
                  $params = [
                      'userid' => $userid,
                      'itemid' => $context->instanceid,
                      'type' => \backup::TYPE_1COURSE
                  ];
  
                  $DB->delete_records_select('backup_controllers', $select, $params);
  
                  $params = [
                      'userid' => $userid,
                      'course' => $context->instanceid,
                      'type' => \backup::TYPE_1SECTION
                  ];
                  $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)";
                  $select = $sectionsql . " AND userid = :userid AND type = :type";
                  $DB->delete_records_select('backup_controllers', $select, $params);
              }
              if ($context instanceof \context_module) {
                  list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
                  $select = "itemid = :itemid AND userid = :userid AND type = :type";
                  $params = [
                      'itemid' => $context->instanceid,
                      'userid' => $userid,
                      'type' => \backup::TYPE_1ACTIVITY
                  ];
  
                  $DB->delete_records_select('backup_controllers', $select, $params);
              }
  
          }
      }
code: public static function delete_data_for_user(approved_contextlist $contextlist) {
          global $DB;
  
          if (empty($contextlist->count())) {
              return;
          }
  
          $userid = $contextlist->get_user()->id;
          foreach ($contextlist->get_contexts() as $context) {
              if ($context instanceof \context_course) {
                  $select = "itemid = :itemid AND userid = :userid AND type = :type";
                  $params = [
                      'userid' => $userid,
                      'itemid' => $context->instanceid,
                      'type' => \backup::TYPE_1COURSE
                  ];
  
                  $DB->delete_records_select('backup_controllers', $select, $params);
  
                  $params = [
                      'userid' => $userid,
                      'course' => $context->instanceid,
                      'type' => \backup::TYPE_1SECTION
                  ];
                  $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)";
                  $select = $sectionsql . " AND userid = :userid AND type = :type";
                  $DB->delete_records_select('backup_controllers', $select, $params);
              }
              if ($context instanceof \context_module) {
                  list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
                  $select = "itemid = :itemid AND userid = :userid AND type = :type";
                  $params = [
                      'itemid' => $context->instanceid,
                      'userid' => $userid,
                      'type' => \backup::TYPE_1ACTIVITY
                  ];
  
                  $DB->delete_records_select('backup_controllers', $select, $params);
              }
  
          }
      }
code_tokens: public static function delete_data_for_user ( approved_contextlist $ contextlist ) { global $ DB ; if ( empty ( $ contextlist -> count ( ) ) ) { return ; } $ userid = $ contextlist -> get_user ( ) -> id ; foreach ( $ contextlist -> get_contexts ( ) as $ context ) { if ( $ context instanceof \ context_course ) { $ select = "itemid = :itemid AND userid = :userid AND type = :type" ; $ params = [ 'userid' => $ userid , 'itemid' => $ context -> instanceid , 'type' => \ backup :: TYPE_1COURSE ] ; $ DB -> delete_records_select ( 'backup_controllers' , $ select , $ params ) ; $ params = [ 'userid' => $ userid , 'course' => $ context -> instanceid , 'type' => \ backup :: TYPE_1SECTION ] ; $ sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)" ; $ select = $ sectionsql . " AND userid = :userid AND type = :type" ; $ DB -> delete_records_select ( 'backup_controllers' , $ select , $ params ) ; } if ( $ context instanceof \ context_module ) { list ( $ usersql , $ userparams ) = $ DB -> get_in_or_equal ( $ userlist -> get_userids ( ) , SQL_PARAMS_NAMED ) ; $ select = "itemid = :itemid AND userid = :userid AND type = :type" ; $ params = [ 'itemid' => $ context -> instanceid , 'userid' => $ userid , 'type' => \ backup :: TYPE_1ACTIVITY ] ; $ DB -> delete_records_select ( 'backup_controllers' , $ select , $ params ) ; } } }
docstring: Delete all user data for the specified user, in the specified contexts.
  Only dealing with the specific context - not it's child contexts.
  
  @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
docstring_tokens: Delete all user data for the specified user in the specified contexts . Only dealing with the specific context - not it s child contexts .