original_string: private function setup_sortitemid() {
  
          global $SESSION;
  
          if (!isset($SESSION->gradeuserreport)) {
              $SESSION->gradeuserreport = new stdClass();
          }
  
          if ($this->sortitemid) {
              if (!isset($SESSION->gradeuserreport->sort)) {
                  if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                      $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                  } else {
                      $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                  }
              } else {
                  // this is the first sort, i.e. by last name
                  if (!isset($SESSION->gradeuserreport->sortitemid)) {
                      if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      }
                  } else if ($SESSION->gradeuserreport->sortitemid == $this->sortitemid) {
                      // same as last sort
                      if ($SESSION->gradeuserreport->sort == 'ASC') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      }
                  } else {
                      if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      }
                  }
              }
              $SESSION->gradeuserreport->sortitemid = $this->sortitemid;
          } else {
              // not requesting sort, use last setting (for paging)
  
              if (isset($SESSION->gradeuserreport->sortitemid)) {
                  $this->sortitemid = $SESSION->gradeuserreport->sortitemid;
              } else {
                  $this->sortitemid = 'lastname';
              }
  
              if (isset($SESSION->gradeuserreport->sort)) {
                  $this->sortorder = $SESSION->gradeuserreport->sort;
              } else {
                  $this->sortorder = 'ASC';
              }
          }
      }
code: private function setup_sortitemid() {
  
          global $SESSION;
  
          if (!isset($SESSION->gradeuserreport)) {
              $SESSION->gradeuserreport = new stdClass();
          }
  
          if ($this->sortitemid) {
              if (!isset($SESSION->gradeuserreport->sort)) {
                  if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                      $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                  } else {
                      $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                  }
              } else {
                  // this is the first sort, i.e. by last name
                  if (!isset($SESSION->gradeuserreport->sortitemid)) {
                      if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      }
                  } else if ($SESSION->gradeuserreport->sortitemid == $this->sortitemid) {
                      // same as last sort
                      if ($SESSION->gradeuserreport->sort == 'ASC') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      }
                  } else {
                      if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
                      } else {
                          $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
                      }
                  }
              }
              $SESSION->gradeuserreport->sortitemid = $this->sortitemid;
          } else {
              // not requesting sort, use last setting (for paging)
  
              if (isset($SESSION->gradeuserreport->sortitemid)) {
                  $this->sortitemid = $SESSION->gradeuserreport->sortitemid;
              } else {
                  $this->sortitemid = 'lastname';
              }
  
              if (isset($SESSION->gradeuserreport->sort)) {
                  $this->sortorder = $SESSION->gradeuserreport->sort;
              } else {
                  $this->sortorder = 'ASC';
              }
          }
      }
code_tokens: private function setup_sortitemid ( ) { global $ SESSION ; if ( ! isset ( $ SESSION -> gradeuserreport ) ) { $ SESSION -> gradeuserreport = new stdClass ( ) ; } if ( $ this -> sortitemid ) { if ( ! isset ( $ SESSION -> gradeuserreport -> sort ) ) { if ( $ this -> sortitemid == 'firstname' || $ this -> sortitemid == 'lastname' ) { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'ASC' ; } else { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'DESC' ; } } else { // this is the first sort, i.e. by last name if ( ! isset ( $ SESSION -> gradeuserreport -> sortitemid ) ) { if ( $ this -> sortitemid == 'firstname' || $ this -> sortitemid == 'lastname' ) { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'ASC' ; } else { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'DESC' ; } } else if ( $ SESSION -> gradeuserreport -> sortitemid == $ this -> sortitemid ) { // same as last sort if ( $ SESSION -> gradeuserreport -> sort == 'ASC' ) { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'DESC' ; } else { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'ASC' ; } } else { if ( $ this -> sortitemid == 'firstname' || $ this -> sortitemid == 'lastname' ) { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'ASC' ; } else { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort = 'DESC' ; } } } $ SESSION -> gradeuserreport -> sortitemid = $ this -> sortitemid ; } else { // not requesting sort, use last setting (for paging) if ( isset ( $ SESSION -> gradeuserreport -> sortitemid ) ) { $ this -> sortitemid = $ SESSION -> gradeuserreport -> sortitemid ; } else { $ this -> sortitemid = 'lastname' ; } if ( isset ( $ SESSION -> gradeuserreport -> sort ) ) { $ this -> sortorder = $ SESSION -> gradeuserreport -> sort ; } else { $ this -> sortorder = 'ASC' ; } } }
docstring: Setting the sort order, this depends on last state
  all this should be in the new table class that we might need to use
  for displaying grades.
docstring_tokens: Setting the sort order this depends on last state all this should be in the new table class that we might need to use for displaying grades .