next up previous contents
Next: index.php Up: 成績 Previous: dump.php   Contents

grade_export_csv.php

  1. 檔案內有關 txt 字串,都改成 csv。
    [root@moodle grade]# diff -urNwbBE export/txt/grade_export_txt.php export/csv/grade_export_csv.php
    --- export/txt/grade_export_txt.php	2014-06-12 16:35:49.603701460 +0800
    +++ export/csv/grade_export_csv.php	2014-06-24 15:09:11.636770015 +0800
    @@ -17,9 +17,9 @@
     
     require_once($CFG->dirroot.'/grade/export/lib.php');
     
    -class grade_export_txt extends grade_export {
    +class grade_export_csv extends grade_export {
     
    -    public $plugin = 'txt';
    +    public $plugin = 'csv';
     
         public $separator; // default separator
    
  2. 修改匯出檔案檔名為課程前 10 個字元。
    @@ -62,22 +62,22 @@
             }
             header("Content-Type: application/download\n");
             $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
    -        $downloadfilename = clean_filename("$shortname $strgrades");
    +        $downloadfilename = substr(clean_filename("$shortname"),0,9); //dywang
             header("Content-Disposition: attachment; filename=\"$downloadfilename.csv\"");
    
  3. 修改匯出欄位為校務系統要求的「姓名」、「學號」、「分數(四捨五入取整數」、「備註(限10個中文字)」。
     /// Print names of all the fields
    -        echo get_string("firstname").$separator.
    -             get_string("lastname").$separator.
    -             get_string("idnumber").$separator.
    -             get_string("institution").$separator.
    -             get_string("department").$separator.
    -             get_string("email");
    +        echo iconv('utf-8','big5//TRANSLIT','姓名').$separator.
    +             iconv('utf-8','big5//TRANSLIT','學號').$separator.
    +			iconv('utf-8','big5//TRANSLIT','分數(四捨五入取整數)').$separator.
    +			iconv('utf-8','big5//TRANSLIT','備註(限10個中文字)');//dywang
    
  4. 校務成績只要匯出學期總成績即可,故註解每個成績項目之匯出選擇。
             foreach ($this->columns as $grade_item) {
    -            echo $separator.$this->format_column_name($grade_item);
    +//            echo $separator.$this->format_column_name($grade_item);
     
                 /// add a feedback column
                 if ($this->export_feedback) {
    @@ -95,15 +95,15 @@
     
                 $user = $userdata->user;
     
    -            echo $user->firstname.$separator.$user->lastname.$separator.$user->idnumber.$separator.$user->institution.$separator.$user->department.$separator.$user->email;
    +            echo iconv('utf-8','big5//TRANSLIT',$user->firstname).$separator.iconv('utf-8','big5//TRANSLIT',$user->lastname);//dywang
    
  5. 校務成績使用 BIG5 編碼,故必須將 utf-8 轉成 big5,特殊字無法轉碼時自動跳過,以免程式死當。
                 foreach ($userdata->grades as $itemid => $grade) {
                     if ($export_tracking) {
                         $status = $geub->track($grade);
                     }
     
    -                echo $separator.$this->format_grade($grade);
    +                echo $separator.iconv('utf-8','big5//TRANSLIT',$this->format_grade($grade));
     
                     if ($this->export_feedback) {
                         echo $separator.$this->format_feedback($userdata->feedbacks[$itemid]);
    



2018-08-14