ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
BaseWriter.php
Go to the documentation of this file.
1<?php
2
4
11abstract class BaseWriter implements IWriter
12{
19 protected $tabl_data;
20
27 protected $content_type = 'text';
28
35 protected $file_extension = 'txt';
36
40 public function __construct(){
41 $this->tabl_data = array();
42 }
43
50 public function addRow($values){
51 if (!is_array($values)) {
52 $values = array($values);
53 }
54 array_push($this->tabl_data, $values);
55 }
56
62 public function saveString(){
63 $content = '';
64 foreach ($this->tabl_data as $row) {
65 foreach ($row as $cell) {
66 $content .= $cell.'\t';
67 }
68 $content .= '\n';
69 }
70 return $content;
71 }
72
80 public function saveFile($filename, $target = NULL){
81
82 if (!isset($filename)) {
83 $filename = date('YmdHis');
84 }
85 if (!isset($target)) {
86 // write output to browser
87 $target = 'php://output';
88 }
89
90 // set HTTP response header
91 header('Content-Type: '.$this->content_type);
92 header('Content-Disposition: attachment; filename='.$filename.'.'.$this->file_extension);
93
94 $fp = fopen($target, 'w');
95 fwrite($fp, $this->saveString());
96 fclose($fp);
97
98 if ($target == 'php://output') {
99 // since there must be no data below
100 exit();
101 }
102 }
103
110 public function setData($values){
111 if(!is_array($values)){
112 $values = array($values);
113 }
114 $this->tabl_data = $values;
115 }
116}
117?>
$filename
Definition: buildRTE.php:89
saveFile($filename, $target=NULL)
Export the document.
Definition: BaseWriter.php:80
setData($values)
Set tabular data.
Definition: BaseWriter.php:110
saveString()
Get document content as string.
Definition: BaseWriter.php:62
addRow($values)
Adding row data to table.
Definition: BaseWriter.php:50
define writer interface
Definition: IWriter.php:14
exit
Definition: login.php:54