original_string: public function process($data) {
          $bulk = new bulk_insert($this->item);
          // Bulk insert messages the data to be passed in
          // ie: for all grades of empty grades apply the specified value.
          if ($bulk->is_applied($data)) {
              $filter = $bulk->get_type($data);
              $insertvalue = $bulk->get_insert_value($data);
  
              $userid = $this->item->id;
              foreach ($this->items as $gradeitemid => $gradeitem) {
                  $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : '';
                  $field = "finalgrade_{$gradeitem->id}_{$this->itemid}";
                  if (isset($data->$field)) {
                      continue;
                  }
  
                  $oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}";
                  // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade.
                  if ($gradeitem->is_course_item() || ($filter != 'all' && !empty($data->$oldfinalgradefield))) {
                      if ($gradeitem->is_course_item()) {
                          // The course total should not be overridden.
                          unset($data->$field);
                          unset($data->oldfinalgradefield);
                          $oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}";
                          unset($data->$oldoverride);
                          $oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}";
                          unset($data->$oldfeedback);
                      }
                      continue;
                  }
                  $grade = grade_grade::fetch(array(
                      'itemid' => $gradeitemid,
                      'userid' => $userid
                  ));
  
                  $data->$field = empty($grade) ? $null : $grade->finalgrade;
                  $data->{"old$field"} = $data->$field;
              }
  
              foreach ($data as $varname => $value) {
                  if (preg_match('/^oldoverride_(\d+)_(\d+)/', $varname, $matches)) {
                      // If we've selected overriding all grades.
                      if ($filter == 'all') {
                          $override = "override_{$matches[1]}_{$matches[2]}";
                          $data->$override = '1';
                      }
                  }
                  if (!preg_match('/^finalgrade_(\d+)_(\d+)/', $varname, $matches)) {
                      continue;
                  }
  
                  $gradeitem = grade_item::fetch(array(
                      'courseid' => $this->courseid,
                      'id' => $matches[1]
                  ));
  
                  $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE);
  
                  $empties = (trim($value) === '' or ($isscale and $value == -1));
  
                  if ($filter == 'all' or $empties) {
                      $data->$varname = ($isscale and empty($insertvalue)) ?
                          -1 : $insertvalue;
                  }
              }
          }
          return parent::process($data);
      }
code: public function process($data) {
          $bulk = new bulk_insert($this->item);
          // Bulk insert messages the data to be passed in
          // ie: for all grades of empty grades apply the specified value.
          if ($bulk->is_applied($data)) {
              $filter = $bulk->get_type($data);
              $insertvalue = $bulk->get_insert_value($data);
  
              $userid = $this->item->id;
              foreach ($this->items as $gradeitemid => $gradeitem) {
                  $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : '';
                  $field = "finalgrade_{$gradeitem->id}_{$this->itemid}";
                  if (isset($data->$field)) {
                      continue;
                  }
  
                  $oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}";
                  // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade.
                  if ($gradeitem->is_course_item() || ($filter != 'all' && !empty($data->$oldfinalgradefield))) {
                      if ($gradeitem->is_course_item()) {
                          // The course total should not be overridden.
                          unset($data->$field);
                          unset($data->oldfinalgradefield);
                          $oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}";
                          unset($data->$oldoverride);
                          $oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}";
                          unset($data->$oldfeedback);
                      }
                      continue;
                  }
                  $grade = grade_grade::fetch(array(
                      'itemid' => $gradeitemid,
                      'userid' => $userid
                  ));
  
                  $data->$field = empty($grade) ? $null : $grade->finalgrade;
                  $data->{"old$field"} = $data->$field;
              }
  
              foreach ($data as $varname => $value) {
                  if (preg_match('/^oldoverride_(\d+)_(\d+)/', $varname, $matches)) {
                      // If we've selected overriding all grades.
                      if ($filter == 'all') {
                          $override = "override_{$matches[1]}_{$matches[2]}";
                          $data->$override = '1';
                      }
                  }
                  if (!preg_match('/^finalgrade_(\d+)_(\d+)/', $varname, $matches)) {
                      continue;
                  }
  
                  $gradeitem = grade_item::fetch(array(
                      'courseid' => $this->courseid,
                      'id' => $matches[1]
                  ));
  
                  $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE);
  
                  $empties = (trim($value) === '' or ($isscale and $value == -1));
  
                  if ($filter == 'all' or $empties) {
                      $data->$varname = ($isscale and empty($insertvalue)) ?
                          -1 : $insertvalue;
                  }
              }
          }
          return parent::process($data);
      }
code_tokens: public function process ( $ data ) { $ bulk = new bulk_insert ( $ this -> item ) ; // Bulk insert messages the data to be passed in // ie: for all grades of empty grades apply the specified value. if ( $ bulk -> is_applied ( $ data ) ) { $ filter = $ bulk -> get_type ( $ data ) ; $ insertvalue = $ bulk -> get_insert_value ( $ data ) ; $ userid = $ this -> item -> id ; foreach ( $ this -> items as $ gradeitemid => $ gradeitem ) { $ null = $ gradeitem -> gradetype == GRADE_TYPE_SCALE ? - 1 : '' ; $ field = "finalgrade_{$gradeitem->id}_{$this->itemid}" ; if ( isset ( $ data -> $ field ) ) { continue ; } $ oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}" ; // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade. if ( $ gradeitem -> is_course_item ( ) || ( $ filter != 'all' && ! empty ( $ data -> $ oldfinalgradefield ) ) ) { if ( $ gradeitem -> is_course_item ( ) ) { // The course total should not be overridden. unset ( $ data -> $ field ) ; unset ( $ data -> oldfinalgradefield ) ; $ oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}" ; unset ( $ data -> $ oldoverride ) ; $ oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}" ; unset ( $ data -> $ oldfeedback ) ; } continue ; } $ grade = grade_grade :: fetch ( array ( 'itemid' => $ gradeitemid , 'userid' => $ userid ) ) ; $ data -> $ field = empty ( $ grade ) ? $ null : $ grade -> finalgrade ; $ data -> { "old$field" } = $ data -> $ field ; } foreach ( $ data as $ varname => $ value ) { if ( preg_match ( '/^oldoverride_(\d+)_(\d+)/' , $ varname , $ matches ) ) { // If we've selected overriding all grades. if ( $ filter == 'all' ) { $ override = "override_{$matches[1]}_{$matches[2]}" ; $ data -> $ override = '1' ; } } if ( ! preg_match ( '/^finalgrade_(\d+)_(\d+)/' , $ varname , $ matches ) ) { continue ; } $ gradeitem = grade_item :: fetch ( array ( 'courseid' => $ this -> courseid , 'id' => $ matches [ 1 ] ) ) ; $ isscale = ( $ gradeitem -> gradetype == GRADE_TYPE_SCALE ) ; $ empties = ( trim ( $ value ) === '' or ( $ isscale and $ value == - 1 ) ) ; if ( $ filter == 'all' or $ empties ) { $ data -> $ varname = ( $ isscale and empty ( $ insertvalue ) ) ? - 1 : $ insertvalue ; } } } return parent :: process ( $ data ) ; }
docstring: Process the data from the form.
  
  @param array $data
  @return array of warnings
docstring_tokens: Process the data from the form .