]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7996 Add ods export support - quiz report and number value, call time pass by...
authorskodak <skodak>
Thu, 21 Dec 2006 20:34:51 +0000 (20:34 +0000)
committerskodak <skodak>
Thu, 21 Dec 2006 20:34:51 +0000 (20:34 +0000)
lib/odslib.class.php
mod/quiz/report/analysis/report.php
mod/quiz/report/overview/report.php

index 803f3c549e030f053eba6ddd0ef984cd03a037f2..8c7272a85b103c11e47f90d9053faef0b67d24eb 100644 (file)
@@ -447,13 +447,21 @@ function get_ods_content(&$worksheets) {
             for($c=0; $c<=$nc; $c++) {
                 if (isset($ws->data[$r][$c])) {
                     if ($ws->data[$r][$c]->type == 'date') {
-                        $buffer .= '<table:table-cell office:value-type="date" table:style-name="Default" office:date-value="' . strftime('%Y-%m-%dT%H:%M:%S', $ws->data[$r][$c]->value) . '">'
+                        $buffer .= '<table:table-cell table:style-name="Default" office:value-type="date" office:date-value="' . strftime('%Y-%m-%dT%H:%M:%S', $ws->data[$r][$c]->value) . '">'
                                  . '<text:p>' . htmlspecialchars($ws->data[$r][$c]->value) . '</text:p>'
                                  . '</table:table-cell>';
-                    } else {
-                        $buffer .= '<table:table-cell office:value-type="' . $ws->data[$r][$c]->type . '">'
+                    } else if ($ws->data[$r][$c]->type == 'float') {
+                        $buffer .= '<table:table-cell office:value-type="float" office:value="' . htmlspecialchars($ws->data[$r][$c]->value) . '">'
+                                 . '<text:p>' . htmlspecialchars($ws->data[$r][$c]->value) . '</text:p>'
+                                 . '</table:table-cell>';
+                    } else if ($ws->data[$r][$c]->type == 'string') {
+                        $buffer .= '<table:table-cell office:value-type="string">'
                                  . '<text:p>' . htmlspecialchars($ws->data[$r][$c]->value) . '</text:p>'
                                  . '</table:table-cell>';
+                    } else {
+                        $buffer .= '<table:table-cell office:value-type="string">'
+                                 . '<text:p>!!Error - unknown type!!</text:p>'
+                                 . '</table:table-cell>';
                     }
                 } else {
                     $buffer .= '<table:table-cell/>';
index b3a4a23ab9abd1c60356b6b829c0a38f84644544..66ea4c4f56f0af8e0c4eba22bfcdf42520083ccd 100644 (file)
@@ -207,7 +207,7 @@ class quiz_report extends quiz_default_report {
         $top -=$gap;
         $bottom +=$gap;
         foreach ($questions as $qid=>$q) {
-            $questions[$qid] = $this->report_question_stats(&$q, $attemptscores, $statstable, $top, $bottom);
+            $questions[$qid] = $this->report_question_stats($q, $attemptscores, $statstable, $top, $bottom);
         }
         unset($attemptscores);
         unset($statstable);
@@ -219,8 +219,8 @@ class quiz_report extends quiz_default_report {
             case "Excel" :
                 $this->Export_Excel($questions, $filename);
                 break;
-            case "OOo": 
-                $this->Export_OOo($questions, $filename);
+            case "ODS": 
+                $this->Export_ODS($questions, $filename);
                 break;
             case "CSV": 
                 $this->Export_CSV($questions, $filename);
@@ -391,13 +391,17 @@ class quiz_report extends quiz_default_report {
         echo "\n";
  
         echo '<table align="center"><tr>';
-        unset($options);
+        $options = array();
         $options["id"] = "$cm->id";
         $options["q"] = "$quiz->id";
         $options["mode"] = "analysis";
         $options['sesskey'] = $USER->sesskey;
         $options["noheader"] = "yes";
         echo '<td>';        
+        $options["download"] = "ODS";
+        print_single_button("report.php", $options, get_string("downloadods"));
+        echo "</td>\n"; 
+        echo '<td>';        
         $options["download"] = "Excel";
         print_single_button("report.php", $options, get_string("downloadexcel"));
         echo "</td>\n"; 
@@ -527,7 +531,7 @@ class quiz_report extends quiz_default_report {
         
         $row = 3;
         foreach($questions as $q) {       
-            $rows = $this->print_row_stats_data(&$q);
+            $rows = $this->print_row_stats_data($q);
             foreach($rows as $rowdata){
                 $col = 0;
                 foreach($rowdata as $item){
@@ -544,27 +548,51 @@ class quiz_report extends quiz_default_report {
     }
 
 
-    function Export_OOo(&$questions, $filename) {
+    function Export_ODS(&$questions, $filename) {
         global $CFG;
-        require_once("$CFG->libdir/phpdocwriter/lib/include.php");
-        import('phpdocwriter.pdw_document');
-        header("Content-Type: application/download\n");   
-        header("Content-Disposition: attachment; filename=\"$filename.sxw\"");
-        header("Expires: 0");
-        header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
-        header("Pragma: public");
-        header("Content-Transfer-Encoding: binary");
-
-        $sxw = new pdw_document;
-        $sxw->SetFileName($filename);
-        $sxw->SetAuthor('Moodle');
-        $sxw->SetTitle(get_string('reportanalysis','quiz_analysis'));
-        $sxw->SetDescription(get_string('reportanalysis','quiz_analysis').' - '.$filename);
-        $sxw->SetLanguage('es','ES');
-        $sxw->SetStdFont("Times New Roman",12);
-        $sxw->AddPageDef(array('name'=>'Standard', 'margins'=>'1,1,1,1', 'w'=>'29.7', 'h'=>'21'));
-        $sxw->Write(get_string('analysistitle','quiz_analysis'));
-        $sxw->Ln(3);
+        require_once("$CFG->libdir/odslib.class.php");
+
+    /// Calculate file name
+        $filename .= ".ods";
+    /// Creating a workbook
+        $workbook = new MoodleODSWorkbook("-");
+    /// Sending HTTP headers
+        $workbook->send($filename);
+    /// Creating the first worksheet
+        $sheettitle = get_string('reportanalysis','quiz_analysis');
+        $myxls =& $workbook->add_worksheet($sheettitle);
+    /// format types
+        $format =& $workbook->add_format();
+        $format->set_bold(0);
+        $formatbc =& $workbook->add_format();
+        $formatbc->set_bold(1);
+        $formatb =& $workbook->add_format();
+        $formatb->set_bold(1);
+        $formaty =& $workbook->add_format();
+        $formaty->set_bg_color('yellow');
+        $formatyc =& $workbook->add_format();
+        $formatyc->set_bg_color('yellow'); //bold text on yellow bg
+        $formatyc->set_bold(1);
+        $formatyc->set_align('center');
+        $formatc =& $workbook->add_format();
+        $formatc->set_align('center');
+        $formatbc->set_align('center');
+        $formatbpct =& $workbook->add_format();
+        $formatbpct->set_bold(1);
+        $formatbpct->set_num_format('0.0%');
+        $formatbrt =& $workbook->add_format();
+        $formatbrt->set_bold(1);
+        $formatbrt->set_align('right');
+        $formatred =& $workbook->add_format();
+        $formatred->set_bold(1);
+        $formatred->set_color('red');
+        $formatred->set_align('center');
+        $formatblue =& $workbook->add_format();
+        $formatblue->set_bold(1);
+        $formatblue->set_color('blue');
+        $formatblue->set_align('center');
+    /// Here starts workshhet headers
+        $myxls->write_string(0,0,$sheettitle,$formatb);
 
         $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), 
                         get_string('qnametitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), 
@@ -574,19 +602,27 @@ class quiz_report extends quiz_default_report {
                         get_string('facilitytitle','quiz_analysis'), get_string('stddevtitle','quiz_analysis'), 
                         get_string('dicsindextitle','quiz_analysis'), get_string('disccoefftitle','quiz_analysis')); 
 
-        foreach($headers as $key=>$header){
-            $headers[$key] = eregi_replace ("<br?>", " ",$header);
+        $col = 0;
+        foreach ($headers as $item) {
+            $myxls->write(2,$col,$item,$formatbc);
+            $col++;
         }
-
-        unset($data);
+        
+        $row = 3;
         foreach($questions as $q) {       
-            $rows = $this->print_row_stats_data(&$q);
-            foreach($rows as $row){
-                $data[] = $row;
+            $rows = $this->print_row_stats_data($q);
+            foreach($rows as $rowdata){
+                $col = 0;
+                foreach($rowdata as $item){
+                    $myxls->write($row,$col,$item,$format);
+                    $col++;
+                }
+                $row++;
             }
         }
-        $sxw->Table($headers,$data);
-        $sxw->Output();
+    /// Close the workbook
+        $workbook->close();
+
         exit;
     }
 
@@ -613,7 +649,7 @@ class quiz_report extends quiz_default_report {
         echo $text;
 
         foreach($questions as $q) {       
-            $rows = $this->print_row_stats_data(&$q);
+            $rows = $this->print_row_stats_data($q);
             foreach($rows as $row){
                 $text = implode("\t", $row);
                 echo $text." \n";
index 1397edd60ff434cd9912abd310b71f7229b29872..4a0de57e0394537b388e0546b07ef96b7d69c2b9 100644 (file)
@@ -162,6 +162,58 @@ class quiz_report extends quiz_default_report {
 
             // Start working -- this is necessary as soon as the niceties are over
             $table->setup();
+        } else if ($download =='ODS') {
+            require_once("$CFG->libdir/odslib.class.php");
+
+            $filename .= ".ods";
+            // Creating a workbook
+            $workbook = new MoodleODSWorkbook("-");
+            // Sending HTTP headers
+            $workbook->send($filename);
+            // Creating the first worksheet
+            $sheettitle = get_string('reportoverview','quiz');
+            $myxls =& $workbook->add_worksheet($sheettitle);
+            // format types
+            $format =& $workbook->add_format();
+            $format->set_bold(0);
+            $formatbc =& $workbook->add_format();
+            $formatbc->set_bold(1);
+            $formatbc->set_align('center');
+            $formatb =& $workbook->add_format();
+            $formatb->set_bold(1);
+            $formaty =& $workbook->add_format();
+            $formaty->set_bg_color('yellow');
+            $formatc =& $workbook->add_format();
+            $formatc->set_align('center');
+            $formatr =& $workbook->add_format();
+            $formatr->set_bold(1);
+            $formatr->set_color('red');
+            $formatr->set_align('center');
+            $formatg =& $workbook->add_format();
+            $formatg->set_bold(1);
+            $formatg->set_color('green');
+            $formatg->set_align('center');
+            // Here starts workshhet headers
+
+            $headers = array(get_string('fullname'), get_string('startedon', 'quiz'), get_string('timecompleted', 'quiz'), get_string('attemptduration', 'quiz'));
+
+            if ($quiz->grade and $quiz->sumgrades) {
+                $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade;
+            }
+            if($detailedmarks) {
+                foreach ($questionids as $id) {
+                    $headers[] = '#'.$questions[$id]->number;
+                }
+            }
+            if ($hasfeedback) {
+                $headers[] = get_string('feedback', 'quiz');
+            }
+            $colnum = 0;
+            foreach ($headers as $item) {
+                $myxls->write(0,$colnum,$item,$formatbc);
+                $colnum++;
+            }
+            $rownum=1;
         } else if ($download =='Excel') {
             require_once("$CFG->libdir/excellib.class.php");
 
@@ -432,7 +484,7 @@ class quiz_report extends quiz_default_report {
                     }
                     if (!$download) {
                         $table->add_data($row);
-                    } else if ($download == 'Excel') {
+                    } else if ($download == 'Excel' or $download == 'ODS') {
                         $colnum = 0;
                         foreach($row as $item){
                             $myxls->write($rownum,$colnum,$item,$format);
@@ -474,13 +526,17 @@ class quiz_report extends quiz_default_report {
                 
                 if (!empty($attempts)) {
                     echo '<table align="center"><tr>';
-                    unset($options);
+                    $options = array();
                     $options["id"] = "$cm->id";
                     $options["q"] = "$quiz->id";
                     $options["mode"] = "overview";
                     $options['sesskey'] = sesskey();
                     $options["noheader"] = "yes";
                     echo '<td>';
+                    $options["download"] = "ODS";
+                    print_single_button("report.php", $options, get_string("downloadods"));
+                    echo "</td>\n";
+                    echo '<td>';
                     $options["download"] = "Excel";
                     print_single_button("report.php", $options, get_string("downloadexcel"));
                     echo "</td>\n";
@@ -493,7 +549,7 @@ class quiz_report extends quiz_default_report {
                     echo "</td>\n";
                     echo '</tr></table>';
                 }
-            } else if ($download == 'Excel') {
+            } else if ($download == 'Excel' or $download == 'ODS') {
                 $workbook->close();
                 exit;
             } else if ($download == 'CSV') {