noalyss Version-9
Public Member Functions | Protected Member Functions | Private Attributes
Noalyss_Csv Class Reference

Manage the CSV : manage files and write CSV record. More...

+ Collaboration diagram for Noalyss_Csv:

Public Member Functions

 __construct ($p_filename)
 
 add ($p_item, $p_type="text")
 
 get_element ()
 
 get_encoding ()
 
 get_filename ()
 
 get_sep_dec ()
 
 get_sep_field ()
 
 get_size ()
 
 send_header ()
 
 set_element ($element)
 
 set_encoding ($encoding)
 
 set_filename ($filename)
 
 set_sep_dec ($sep_dec)
 
 set_sep_field ($sep_field)
 
 set_size ($size)
 
 write ()
 
 write_header ($p_array)
 

Protected Member Functions

 clean ()
 clean the row More...
 
 correct_name ()
 
 encode ($str)
 
 nb ($p_number)
 format the number for the CSV export More...
 

Private Attributes

 $element
 
 $encoding
 
 $filename
 
 $sep_dec
 
 $sep_field
 
 $size
 

Detailed Description

Manage the CSV : manage files and write CSV record.

Definition at line 33 of file noalyss_csv.class.php.

Constructor & Destructor Documentation

◆ __construct()

Noalyss_Csv::__construct (   $p_filename)

Definition at line 43 of file noalyss_csv.class.php.

44 {
45 $this->filename=$p_filename;
46 $this->element=array();
47 $this->size=0;
48
49 $a_field=[';',','];
50 $this->sep_field=$a_field[$_SESSION[SESSION_KEY.'csv_fieldsep']];
51 $a_field=['.',','];
52 $this->sep_dec=$a_field[$_SESSION[SESSION_KEY.'csv_decimal']];
53 $this->encoding=$_SESSION[SESSION_KEY.'csv_encoding'];
54
55 }
$name size

References size.

Member Function Documentation

◆ add()

Noalyss_Csv::add (   $p_item,
  $p_type = "text" 
)

Definition at line 118 of file noalyss_csv.class.php.

119 {
120 if ( ! in_array($p_type, array("text","number"))) {
121 throw new Exception("NOALYSS_CSV::ADD");
122 }
123 $this->element[$this->size]['value']=$p_item;
124 $this->element[$this->size]['type']=$p_type;
125 $this->size++;
126 }

References $p_type, $size, and size.

◆ clean()

Noalyss_Csv::clean ( )
protected

clean the row

Definition at line 162 of file noalyss_csv.class.php.

163 {
164 $this->element=array();
165 $this->size=0;
166 }

References size.

Referenced by write().

◆ correct_name()

Noalyss_Csv::correct_name ( )
protected

Definition at line 62 of file noalyss_csv.class.php.

63 {
64 if (trim(strlen($this->filename))==0) {
65 record_log('CSV->correct_name filename is empty');
66 throw new Exception('CSV-CORRECT_NAME');
67 }
68 $this->filename.="-".date("ymd-Hi");
69 $this->filename.=".csv";
70
71 $this->filename=noalyss_str_replace(";", "", $this->filename);
72 $this->filename=noalyss_str_replace("/", "", $this->filename);
73 $this->filename=noalyss_str_replace(":", "", $this->filename);
74 $this->filename=noalyss_str_replace("*", "", $this->filename);
75 $this->filename=noalyss_str_replace(" ", "_", $this->filename);
76 $this->filename=strtolower($this->filename);
77 }
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342

References noalyss_str_replace(), and record_log().

Referenced by send_header().

+ Here is the call graph for this function:

◆ encode()

Noalyss_Csv::encode (   $str)
protected

Definition at line 182 of file noalyss_csv.class.php.

183 {
184 if ($this->encoding=="utf8") return $str;
185 if ($this->encoding=="latin1") return mb_convert_encoding($str,'ISO-8859-1','UTF-8');
186 throw new Exception(_("Encodage invalide"));
187 }
$str
Definition: fiche.inc.php:91

References $str.

◆ get_element()

Noalyss_Csv::get_element ( )
Returns
array

Definition at line 209 of file noalyss_csv.class.php.

210 {
211 return $this->element;
212 return $this;
213 }

References $element.

◆ get_encoding()

Noalyss_Csv::get_encoding ( )
Returns
mixed

Definition at line 263 of file noalyss_csv.class.php.

264 {
265 return $this->encoding;
266 return $this;
267 }

References $encoding.

◆ get_filename()

Noalyss_Csv::get_filename ( )
Returns
mixed

Definition at line 191 of file noalyss_csv.class.php.

192 {
193 return $this->filename;
194 return $this;
195 }

References $filename.

◆ get_sep_dec()

Noalyss_Csv::get_sep_dec ( )
Returns
mixed

Definition at line 245 of file noalyss_csv.class.php.

246 {
247 return $this->sep_dec;
248 return $this;
249 }

References $sep_dec.

◆ get_sep_field()

Noalyss_Csv::get_sep_field ( )
Returns
mixed

Definition at line 227 of file noalyss_csv.class.php.

228 {
229 return $this->sep_field;
230 return $this;
231 }

References $sep_field.

◆ get_size()

Noalyss_Csv::get_size ( )
Returns
int

Definition at line 281 of file noalyss_csv.class.php.

282 {
283 return $this->size;
284 return $this;
285 }

References $size.

◆ nb()

Noalyss_Csv::nb (   $p_number)
protected

format the number for the CSV export

Parameters
$p_numbernumber

Definition at line 171 of file noalyss_csv.class.php.

172 {
173 $p_number=noalyss_trim($p_number);
174 if ($p_number=="") {return $p_number;}
175 if ( isNumber($p_number) == 1 ) {
176 $r=number_format($p_number, 4, $this->sep_dec,'');
177 } else {
178 $r=$p_number;
179 }
180 return $r;
181 }
isNumber($p_int)
Definition: ac_common.php:215
noalyss_trim($p_string)
Definition: ac_common.php:1545
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r, isNumber(), and noalyss_trim().

+ Here is the call graph for this function:

◆ send_header()

Noalyss_Csv::send_header ( )

Definition at line 82 of file noalyss_csv.class.php.

83 {
84 $this->correct_name();
85 header('Pragma: public');
86 header('Content-type: application/csv');
87 header("Content-Disposition: attachment;filename=\"{$this->filename}\"",
88 FALSE);
89 header('Cache-Control: no-store, no-cache, must-revalidate');
90 header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
91 header('Last-Modified: '.gmdate('D, d M Y H:i:s').'GMT');
92 }

References correct_name().

+ Here is the call graph for this function:

◆ set_element()

Noalyss_Csv::set_element (   $element)
Parameters
array$element

Definition at line 218 of file noalyss_csv.class.php.

219 {
220 $this->element = $element;
221 return $this;
222 }

References $element.

◆ set_encoding()

Noalyss_Csv::set_encoding (   $encoding)
Parameters
mixed$encoding

Definition at line 272 of file noalyss_csv.class.php.

273 {
274 $this->encoding = $encoding;
275 return $this;
276 }

References $encoding.

◆ set_filename()

Noalyss_Csv::set_filename (   $filename)
Parameters
mixed$filename

Definition at line 200 of file noalyss_csv.class.php.

201 {
202 $this->filename = $filename;
203 return $this;
204 }

References $filename.

◆ set_sep_dec()

Noalyss_Csv::set_sep_dec (   $sep_dec)
Parameters
mixed$sep_dec

Definition at line 254 of file noalyss_csv.class.php.

255 {
256 $this->sep_dec = $sep_dec;
257 return $this;
258 }

References $sep_dec.

◆ set_sep_field()

Noalyss_Csv::set_sep_field (   $sep_field)
Parameters
mixed$sep_field

Definition at line 236 of file noalyss_csv.class.php.

237 {
238 $this->sep_field = $sep_field;
239 return $this;
240 }

References $sep_field.

◆ set_size()

Noalyss_Csv::set_size (   $size)
Parameters
int$size

Definition at line 290 of file noalyss_csv.class.php.

291 {
292 $this->size = $size;
293 return $this;
294 }

References $size, and size.

◆ write()

Noalyss_Csv::write ( )

Definition at line 134 of file noalyss_csv.class.php.

135 {
136 if ($this->size == 0 ) return;
137 $sep="";
138 for ($i=0;$i < $this->size;$i++)
139 {
140 if ($this->element[$i]['type'] == 'number' )
141 {
142 printf($sep.'%s', $this->nb($this->element[$i]['value']));
143 }
144 else
145 {
146 $export=($this->element[$i]['value']==null)?"":$this->element[$i]['value'];
147 // remove break-line,
150 // remove double quote
152 printf($sep.'"%s"', $this->encode($export));
153 }
155 }
156 printf("\r\n");
157 $this->clean();
158 }
clean()
clean the row

References $export, $i, $sep, $sep_field, $size, clean(), noalyss_str_replace(), and size.

+ Here is the call graph for this function:

◆ write_header()

Noalyss_Csv::write_header (   $p_array)

Definition at line 99 of file noalyss_csv.class.php.

100 {
101 $size_array=count($p_array);
102 $sep="";
103 for ($i=0; $i<$size_array; $i++)
104 {
105
106 printf($sep.'"%s"', $this->encode($p_array[$i]));
108 }
109 printf("\r\n");
110 }

References $i, $p_array, $sep, and $sep_field.

Field Documentation

◆ $element

Noalyss_Csv::$element
private

Definition at line 37 of file noalyss_csv.class.php.

Referenced by get_element(), and set_element().

◆ $encoding

Noalyss_Csv::$encoding
private

Definition at line 40 of file noalyss_csv.class.php.

Referenced by get_encoding(), and set_encoding().

◆ $filename

Noalyss_Csv::$filename
private

Definition at line 36 of file noalyss_csv.class.php.

Referenced by get_filename(), and set_filename().

◆ $sep_dec

Noalyss_Csv::$sep_dec
private

Definition at line 39 of file noalyss_csv.class.php.

Referenced by get_sep_dec(), and set_sep_dec().

◆ $sep_field

Noalyss_Csv::$sep_field
private

Definition at line 38 of file noalyss_csv.class.php.

Referenced by get_sep_field(), set_sep_field(), write(), and write_header().

◆ $size

Noalyss_Csv::$size
private

Definition at line 41 of file noalyss_csv.class.php.

Referenced by add(), get_size(), set_size(), and write().


The documentation for this class was generated from the following file: