original_string: public static function generate_shortname($data, $templateshortname) {
          if (empty($templateshortname) && !is_numeric($templateshortname)) {
              return null;
          }
          if (strpos($templateshortname, '%') === false) {
              return $templateshortname;
          }
  
          $course = (object) $data;
          $fullname   = isset($course->fullname) ? $course->fullname : '';
          $idnumber   = isset($course->idnumber) ? $course->idnumber  : '';
  
          $callback = partial(array('tool_uploadcourse_helper', 'generate_shortname_callback'), $fullname, $idnumber);
          $result = preg_replace_callback('/(?<!%)%([+~-])?(\d)*([fi])/', $callback, $templateshortname);
  
          if (!is_null($result)) {
              $result = clean_param($result, PARAM_TEXT);
          }
  
          if (empty($result) && !is_numeric($result)) {
              $result = null;
          }
  
          return $result;
      }
code: public static function generate_shortname($data, $templateshortname) {
          if (empty($templateshortname) && !is_numeric($templateshortname)) {
              return null;
          }
          if (strpos($templateshortname, '%') === false) {
              return $templateshortname;
          }
  
          $course = (object) $data;
          $fullname   = isset($course->fullname) ? $course->fullname : '';
          $idnumber   = isset($course->idnumber) ? $course->idnumber  : '';
  
          $callback = partial(array('tool_uploadcourse_helper', 'generate_shortname_callback'), $fullname, $idnumber);
          $result = preg_replace_callback('/(?<!%)%([+~-])?(\d)*([fi])/', $callback, $templateshortname);
  
          if (!is_null($result)) {
              $result = clean_param($result, PARAM_TEXT);
          }
  
          if (empty($result) && !is_numeric($result)) {
              $result = null;
          }
  
          return $result;
      }
code_tokens: public static function generate_shortname ( $ data , $ templateshortname ) { if ( empty ( $ templateshortname ) && ! is_numeric ( $ templateshortname ) ) { return null ; } if ( strpos ( $ templateshortname , '%' ) === false ) { return $ templateshortname ; } $ course = ( object ) $ data ; $ fullname = isset ( $ course -> fullname ) ? $ course -> fullname : '' ; $ idnumber = isset ( $ course -> idnumber ) ? $ course -> idnumber : '' ; $ callback = partial ( array ( 'tool_uploadcourse_helper' , 'generate_shortname_callback' ) , $ fullname , $ idnumber ) ; $ result = preg_replace_callback ( '/(?<!%)%([+~-])?(\d)*([fi])/' , $ callback , $ templateshortname ) ; if ( ! is_null ( $ result ) ) { $ result = clean_param ( $ result , PARAM_TEXT ) ; } if ( empty ( $ result ) && ! is_numeric ( $ result ) ) { $ result = null ; } return $ result ; }
docstring: Generate a shortname based on a template.
  
  @param array|object $data course data.
  @param string $templateshortname template of shortname.
  @return null|string shortname based on the template, or null when an error occured.
docstring_tokens: Generate a shortname based on a template .