original_string: public function process_course_completion_criteria($data) {
          global $DB;
  
          $data = (object)$data;
          $data->course = $this->get_courseid();
  
          // Apply the date offset to the time end field
          $data->timeend = $this->apply_date_offset($data->timeend);
  
          // Map the role from the criteria
          if (isset($data->role) && $data->role != '') {
              // Newer backups should include roleshortname, which makes this much easier.
              if (!empty($data->roleshortname)) {
                  $roleinstanceid = $DB->get_field('role', 'id', array('shortname' => $data->roleshortname));
                  if (!$roleinstanceid) {
                      $this->log(
                          'Could not match the role shortname in course_completion_criteria, so skipping',
                          backup::LOG_DEBUG
                      );
                      return;
                  }
                  $data->role = $roleinstanceid;
              } else {
                  $data->role = $this->get_mappingid('role', $data->role);
              }
  
              // Check we have an id, otherwise it causes all sorts of bugs.
              if (!$data->role) {
                  $this->log(
                      'Could not match role in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          }
  
          // If the completion criteria is for a module we need to map the module instance
          // to the new module id.
          if (!empty($data->moduleinstance) && !empty($data->module)) {
              $data->moduleinstance = $this->get_mappingid('course_module', $data->moduleinstance);
              if (empty($data->moduleinstance)) {
                  $this->log(
                      'Could not match the module instance in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          } else {
              $data->module = null;
              $data->moduleinstance = null;
          }
  
          // We backup the course shortname rather than the ID so that we can match back to the course
          if (!empty($data->courseinstanceshortname)) {
              $courseinstanceid = $DB->get_field('course', 'id', array('shortname'=>$data->courseinstanceshortname));
              if (!$courseinstanceid) {
                  $this->log(
                      'Could not match the course instance in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          } else {
              $courseinstanceid = null;
          }
          $data->courseinstance = $courseinstanceid;
  
          $params = array(
              'course'         => $data->course,
              'criteriatype'   => $data->criteriatype,
              'enrolperiod'    => $data->enrolperiod,
              'courseinstance' => $data->courseinstance,
              'module'         => $data->module,
              'moduleinstance' => $data->moduleinstance,
              'timeend'        => $data->timeend,
              'gradepass'      => $data->gradepass,
              'role'           => $data->role
          );
          $newid = $DB->insert_record('course_completion_criteria', $params);
          $this->set_mapping('course_completion_criteria', $data->id, $newid);
      }
code: public function process_course_completion_criteria($data) {
          global $DB;
  
          $data = (object)$data;
          $data->course = $this->get_courseid();
  
          // Apply the date offset to the time end field
          $data->timeend = $this->apply_date_offset($data->timeend);
  
          // Map the role from the criteria
          if (isset($data->role) && $data->role != '') {
              // Newer backups should include roleshortname, which makes this much easier.
              if (!empty($data->roleshortname)) {
                  $roleinstanceid = $DB->get_field('role', 'id', array('shortname' => $data->roleshortname));
                  if (!$roleinstanceid) {
                      $this->log(
                          'Could not match the role shortname in course_completion_criteria, so skipping',
                          backup::LOG_DEBUG
                      );
                      return;
                  }
                  $data->role = $roleinstanceid;
              } else {
                  $data->role = $this->get_mappingid('role', $data->role);
              }
  
              // Check we have an id, otherwise it causes all sorts of bugs.
              if (!$data->role) {
                  $this->log(
                      'Could not match role in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          }
  
          // If the completion criteria is for a module we need to map the module instance
          // to the new module id.
          if (!empty($data->moduleinstance) && !empty($data->module)) {
              $data->moduleinstance = $this->get_mappingid('course_module', $data->moduleinstance);
              if (empty($data->moduleinstance)) {
                  $this->log(
                      'Could not match the module instance in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          } else {
              $data->module = null;
              $data->moduleinstance = null;
          }
  
          // We backup the course shortname rather than the ID so that we can match back to the course
          if (!empty($data->courseinstanceshortname)) {
              $courseinstanceid = $DB->get_field('course', 'id', array('shortname'=>$data->courseinstanceshortname));
              if (!$courseinstanceid) {
                  $this->log(
                      'Could not match the course instance in course_completion_criteria, so skipping',
                      backup::LOG_DEBUG
                  );
                  return;
              }
          } else {
              $courseinstanceid = null;
          }
          $data->courseinstance = $courseinstanceid;
  
          $params = array(
              'course'         => $data->course,
              'criteriatype'   => $data->criteriatype,
              'enrolperiod'    => $data->enrolperiod,
              'courseinstance' => $data->courseinstance,
              'module'         => $data->module,
              'moduleinstance' => $data->moduleinstance,
              'timeend'        => $data->timeend,
              'gradepass'      => $data->gradepass,
              'role'           => $data->role
          );
          $newid = $DB->insert_record('course_completion_criteria', $params);
          $this->set_mapping('course_completion_criteria', $data->id, $newid);
      }
code_tokens: public function process_course_completion_criteria ( $ data ) { global $ DB ; $ data = ( object ) $ data ; $ data -> course = $ this -> get_courseid ( ) ; // Apply the date offset to the time end field $ data -> timeend = $ this -> apply_date_offset ( $ data -> timeend ) ; // Map the role from the criteria if ( isset ( $ data -> role ) && $ data -> role != '' ) { // Newer backups should include roleshortname, which makes this much easier. if ( ! empty ( $ data -> roleshortname ) ) { $ roleinstanceid = $ DB -> get_field ( 'role' , 'id' , array ( 'shortname' => $ data -> roleshortname ) ) ; if ( ! $ roleinstanceid ) { $ this -> log ( 'Could not match the role shortname in course_completion_criteria, so skipping' , backup :: LOG_DEBUG ) ; return ; } $ data -> role = $ roleinstanceid ; } else { $ data -> role = $ this -> get_mappingid ( 'role' , $ data -> role ) ; } // Check we have an id, otherwise it causes all sorts of bugs. if ( ! $ data -> role ) { $ this -> log ( 'Could not match role in course_completion_criteria, so skipping' , backup :: LOG_DEBUG ) ; return ; } } // If the completion criteria is for a module we need to map the module instance // to the new module id. if ( ! empty ( $ data -> moduleinstance ) && ! empty ( $ data -> module ) ) { $ data -> moduleinstance = $ this -> get_mappingid ( 'course_module' , $ data -> moduleinstance ) ; if ( empty ( $ data -> moduleinstance ) ) { $ this -> log ( 'Could not match the module instance in course_completion_criteria, so skipping' , backup :: LOG_DEBUG ) ; return ; } } else { $ data -> module = null ; $ data -> moduleinstance = null ; } // We backup the course shortname rather than the ID so that we can match back to the course if ( ! empty ( $ data -> courseinstanceshortname ) ) { $ courseinstanceid = $ DB -> get_field ( 'course' , 'id' , array ( 'shortname' => $ data -> courseinstanceshortname ) ) ; if ( ! $ courseinstanceid ) { $ this -> log ( 'Could not match the course instance in course_completion_criteria, so skipping' , backup :: LOG_DEBUG ) ; return ; } } else { $ courseinstanceid = null ; } $ data -> courseinstance = $ courseinstanceid ; $ params = array ( 'course' => $ data -> course , 'criteriatype' => $ data -> criteriatype , 'enrolperiod' => $ data -> enrolperiod , 'courseinstance' => $ data -> courseinstance , 'module' => $ data -> module , 'moduleinstance' => $ data -> moduleinstance , 'timeend' => $ data -> timeend , 'gradepass' => $ data -> gradepass , 'role' => $ data -> role ) ; $ newid = $ DB -> insert_record ( 'course_completion_criteria' , $ params ) ; $ this -> set_mapping ( 'course_completion_criteria' , $ data -> id , $ newid ) ; }
docstring: Process course completion criteria
  
  @global moodle_database $DB
  @param stdClass $data
docstring_tokens: Process course completion criteria