original_string: public static function create_acceptances_user_created(\core\event\user_created $event) {
          global $USER, $CFG, $DB;
  
          // Do nothing if not set as the site policies handler.
          if (empty($CFG->sitepolicyhandler) || $CFG->sitepolicyhandler !== 'tool_policy') {
              return;
          }
  
          $userid = $event->objectid;
          $lang = current_language();
          $user = $event->get_record_snapshot('user', $userid);
          // Do nothing if the user has not accepted the current policies.
          if (!$user->policyagreed) {
              return;
          }
  
          // Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway).
          $cache = \cache::make('core', 'presignup');
          $cache->delete('tool_policy_userpolicyagreed');
          $cache->delete('tool_policy_viewedpolicies');
          $cache->delete('tool_policy_policyversionidsagreed');
  
          // Mark all compulsory policies as implicitly accepted during the signup.
          if ($policyversions = static::list_current_versions(policy_version::AUDIENCE_LOGGEDIN)) {
              $acceptances = array();
              $now = time();
              foreach ($policyversions as $policyversion) {
                  if ($policyversion->optional == policy_version::AGREEMENT_OPTIONAL) {
                      continue;
                  }
                  $acceptances[] = array(
                      'policyversionid' => $policyversion->id,
                      'userid' => $userid,
                      'status' => 1,
                      'lang' => $lang,
                      'usermodified' => isset($USER->id) ? $USER->id : 0,
                      'timecreated' => $now,
                      'timemodified' => $now,
                  );
              }
              $DB->insert_records('tool_policy_acceptances', $acceptances);
          }
  
          static::update_policyagreed($userid);
      }
code: public static function create_acceptances_user_created(\core\event\user_created $event) {
          global $USER, $CFG, $DB;
  
          // Do nothing if not set as the site policies handler.
          if (empty($CFG->sitepolicyhandler) || $CFG->sitepolicyhandler !== 'tool_policy') {
              return;
          }
  
          $userid = $event->objectid;
          $lang = current_language();
          $user = $event->get_record_snapshot('user', $userid);
          // Do nothing if the user has not accepted the current policies.
          if (!$user->policyagreed) {
              return;
          }
  
          // Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway).
          $cache = \cache::make('core', 'presignup');
          $cache->delete('tool_policy_userpolicyagreed');
          $cache->delete('tool_policy_viewedpolicies');
          $cache->delete('tool_policy_policyversionidsagreed');
  
          // Mark all compulsory policies as implicitly accepted during the signup.
          if ($policyversions = static::list_current_versions(policy_version::AUDIENCE_LOGGEDIN)) {
              $acceptances = array();
              $now = time();
              foreach ($policyversions as $policyversion) {
                  if ($policyversion->optional == policy_version::AGREEMENT_OPTIONAL) {
                      continue;
                  }
                  $acceptances[] = array(
                      'policyversionid' => $policyversion->id,
                      'userid' => $userid,
                      'status' => 1,
                      'lang' => $lang,
                      'usermodified' => isset($USER->id) ? $USER->id : 0,
                      'timecreated' => $now,
                      'timemodified' => $now,
                  );
              }
              $DB->insert_records('tool_policy_acceptances', $acceptances);
          }
  
          static::update_policyagreed($userid);
      }
code_tokens: public static function create_acceptances_user_created ( \ core \ event \ user_created $ event ) { global $ USER , $ CFG , $ DB ; // Do nothing if not set as the site policies handler. if ( empty ( $ CFG -> sitepolicyhandler ) || $ CFG -> sitepolicyhandler !== 'tool_policy' ) { return ; } $ userid = $ event -> objectid ; $ lang = current_language ( ) ; $ user = $ event -> get_record_snapshot ( 'user' , $ userid ) ; // Do nothing if the user has not accepted the current policies. if ( ! $ user -> policyagreed ) { return ; } // Cleanup our bits in the presignup cache (we can not rely on them at this stage any more anyway). $ cache = \ cache :: make ( 'core' , 'presignup' ) ; $ cache -> delete ( 'tool_policy_userpolicyagreed' ) ; $ cache -> delete ( 'tool_policy_viewedpolicies' ) ; $ cache -> delete ( 'tool_policy_policyversionidsagreed' ) ; // Mark all compulsory policies as implicitly accepted during the signup. if ( $ policyversions = static :: list_current_versions ( policy_version :: AUDIENCE_LOGGEDIN ) ) { $ acceptances = array ( ) ; $ now = time ( ) ; foreach ( $ policyversions as $ policyversion ) { if ( $ policyversion -> optional == policy_version :: AGREEMENT_OPTIONAL ) { continue ; } $ acceptances [ ] = array ( 'policyversionid' => $ policyversion -> id , 'userid' => $ userid , 'status' => 1 , 'lang' => $ lang , 'usermodified' => isset ( $ USER -> id ) ? $ USER -> id : 0 , 'timecreated' => $ now , 'timemodified' => $ now , ) ; } $ DB -> insert_records ( 'tool_policy_acceptances' , $ acceptances ) ; } static :: update_policyagreed ( $ userid ) ; }
docstring: Create user policy acceptances when the user is created.
  
  @param \core\event\user_created $event
docstring_tokens: Create user policy acceptances when the user is created .