original_string: public function update_definition(stdClass $definition, $usermodified = null) {
          global $DB, $USER;
  
          if (is_null($usermodified)) {
              $usermodified = $USER->id;
          }
  
          if (!empty($this->definition->id)) {
              // prepare a record to be updated
              $record = new stdClass();
              // populate it with scalar values from the passed definition structure
              foreach ($definition as $prop => $val) {
                  if (is_array($val) or is_object($val)) {
                      // probably plugin's data
                      continue;
                  }
                  $record->{$prop} = $val;
              }
              // make sure we do not override some crucial values by accident
              if (!empty($record->id) and $record->id != $this->definition->id) {
                  throw new coding_exception('Attempting to update other definition record.');
              }
              $record->id = $this->definition->id;
              unset($record->areaid);
              unset($record->method);
              unset($record->timecreated);
              // set the modification flags
              $record->timemodified = time();
              $record->usermodified = $usermodified;
  
              $DB->update_record('grading_definitions', $record);
  
          } else if ($this->definition === false) {
              // prepare a record to be inserted
              $record = new stdClass();
              // populate it with scalar values from the passed definition structure
              foreach ($definition as $prop => $val) {
                  if (is_array($val) or is_object($val)) {
                      // probably plugin's data
                      continue;
                  }
                  $record->{$prop} = $val;
              }
              // make sure we do not override some crucial values by accident
              if (!empty($record->id)) {
                  throw new coding_exception('Attempting to create a new record while there is already one existing.');
              }
              unset($record->id);
              $record->areaid       = $this->areaid;
              $record->method       = $this->get_method_name();
              $record->timecreated  = time();
              $record->usercreated  = $usermodified;
              $record->timemodified = $record->timecreated;
              $record->usermodified = $record->usercreated;
              if (empty($record->status)) {
                  $record->status = self::DEFINITION_STATUS_DRAFT;
              }
              if (empty($record->descriptionformat)) {
                  $record->descriptionformat = FORMAT_MOODLE; // field can not be empty
              }
  
              $DB->insert_record('grading_definitions', $record);
  
          } else {
              throw new coding_exception('Unknown status of the cached definition record.');
          }
      }
code: public function update_definition(stdClass $definition, $usermodified = null) {
          global $DB, $USER;
  
          if (is_null($usermodified)) {
              $usermodified = $USER->id;
          }
  
          if (!empty($this->definition->id)) {
              // prepare a record to be updated
              $record = new stdClass();
              // populate it with scalar values from the passed definition structure
              foreach ($definition as $prop => $val) {
                  if (is_array($val) or is_object($val)) {
                      // probably plugin's data
                      continue;
                  }
                  $record->{$prop} = $val;
              }
              // make sure we do not override some crucial values by accident
              if (!empty($record->id) and $record->id != $this->definition->id) {
                  throw new coding_exception('Attempting to update other definition record.');
              }
              $record->id = $this->definition->id;
              unset($record->areaid);
              unset($record->method);
              unset($record->timecreated);
              // set the modification flags
              $record->timemodified = time();
              $record->usermodified = $usermodified;
  
              $DB->update_record('grading_definitions', $record);
  
          } else if ($this->definition === false) {
              // prepare a record to be inserted
              $record = new stdClass();
              // populate it with scalar values from the passed definition structure
              foreach ($definition as $prop => $val) {
                  if (is_array($val) or is_object($val)) {
                      // probably plugin's data
                      continue;
                  }
                  $record->{$prop} = $val;
              }
              // make sure we do not override some crucial values by accident
              if (!empty($record->id)) {
                  throw new coding_exception('Attempting to create a new record while there is already one existing.');
              }
              unset($record->id);
              $record->areaid       = $this->areaid;
              $record->method       = $this->get_method_name();
              $record->timecreated  = time();
              $record->usercreated  = $usermodified;
              $record->timemodified = $record->timecreated;
              $record->usermodified = $record->usercreated;
              if (empty($record->status)) {
                  $record->status = self::DEFINITION_STATUS_DRAFT;
              }
              if (empty($record->descriptionformat)) {
                  $record->descriptionformat = FORMAT_MOODLE; // field can not be empty
              }
  
              $DB->insert_record('grading_definitions', $record);
  
          } else {
              throw new coding_exception('Unknown status of the cached definition record.');
          }
      }
code_tokens: public function update_definition ( stdClass $ definition , $ usermodified = null ) { global $ DB , $ USER ; if ( is_null ( $ usermodified ) ) { $ usermodified = $ USER -> id ; } if ( ! empty ( $ this -> definition -> id ) ) { // prepare a record to be updated $ record = new stdClass ( ) ; // populate it with scalar values from the passed definition structure foreach ( $ definition as $ prop => $ val ) { if ( is_array ( $ val ) or is_object ( $ val ) ) { // probably plugin's data continue ; } $ record -> { $ prop } = $ val ; } // make sure we do not override some crucial values by accident if ( ! empty ( $ record -> id ) and $ record -> id != $ this -> definition -> id ) { throw new coding_exception ( 'Attempting to update other definition record.' ) ; } $ record -> id = $ this -> definition -> id ; unset ( $ record -> areaid ) ; unset ( $ record -> method ) ; unset ( $ record -> timecreated ) ; // set the modification flags $ record -> timemodified = time ( ) ; $ record -> usermodified = $ usermodified ; $ DB -> update_record ( 'grading_definitions' , $ record ) ; } else if ( $ this -> definition === false ) { // prepare a record to be inserted $ record = new stdClass ( ) ; // populate it with scalar values from the passed definition structure foreach ( $ definition as $ prop => $ val ) { if ( is_array ( $ val ) or is_object ( $ val ) ) { // probably plugin's data continue ; } $ record -> { $ prop } = $ val ; } // make sure we do not override some crucial values by accident if ( ! empty ( $ record -> id ) ) { throw new coding_exception ( 'Attempting to create a new record while there is already one existing.' ) ; } unset ( $ record -> id ) ; $ record -> areaid = $ this -> areaid ; $ record -> method = $ this -> get_method_name ( ) ; $ record -> timecreated = time ( ) ; $ record -> usercreated = $ usermodified ; $ record -> timemodified = $ record -> timecreated ; $ record -> usermodified = $ record -> usercreated ; if ( empty ( $ record -> status ) ) { $ record -> status = self :: DEFINITION_STATUS_DRAFT ; } if ( empty ( $ record -> descriptionformat ) ) { $ record -> descriptionformat = FORMAT_MOODLE ; // field can not be empty } $ DB -> insert_record ( 'grading_definitions' , $ record ) ; } else { throw new coding_exception ( 'Unknown status of the cached definition record.' ) ; } }
docstring: Saves the defintion data into the database
  
  The implementation in this base class stores the common data into the record
  into the {grading_definition} table. The plugins are likely to extend this
  and save their data into own tables, too.
  
  @param stdClass $definition data containing values for the {grading_definition} table
  @param int|null $usermodified optional userid of the author of the definition, defaults to the current user
docstring_tokens: Saves the defintion data into the database