Completed
Push — master ( 44ae7a...3a6783 )
by Paul
05:10
created

absences_ExportEntry::getElementsHeader()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 20
nc 2
nop 0
dl 0
loc 26
ccs 0
cts 21
cp 0
crap 6
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
require_once dirname(__FILE__).'/entry.class.php';
26
require_once dirname(__FILE__).'/agent.class.php';
27
require_once dirname(__FILE__).'/organization.class.php';
28
29
class absences_ExportEntry
30
{
31
    /**
32
     * @var BAB_DateTime
33
     */
34
    protected $dateb;
35
36
    /**
37
     * @var BAB_DateTime
38
     */
39
    protected $datee;
40
41
    
42
    /**
43
     * @var bool
44
     */
45
    private $splittype;
46
    
47
    /**
48
     * @var absences_EntryIterator
49
     */
50
    private $iterator;
51
52
    /**
53
     * @var string
54
     */
55
    private $separ;
56
57
    /**
58
     * @var string
59
     */
60
    private $sepdec;
61
62
    /**
63
     * @var array
64
     */
65
    private $users_with_requests = array();
66
67
    /**
68
     * @var bool
69
     */
70
    private $users_without_requests;
71
72
    /**
73
     * @var array
74
     */
75
    private $dirfields;
76
77
78
    private $types = array();
79
80
    /**
81
     * @var int
82
     */
83
    private $organization = '';
84
85 1
    public function __construct(BAB_DateTime $dateb, BAB_DateTime $datee, $idstatus, $wsepar, $separ, $sepdec, $users_without_requests, $dirfields, $organization, $splittype)
86
    {
87 1
        $this->dateb = $dateb;
88 1
        $this->datee = $datee;
89 1
        $this->organization = $organization;
90
91 1
        $status = array();
92 1
        if (in_array(0,$idstatus)) {
93 1
            $status[] = '';
94 1
        }
95
        
96 1
        if (in_array(1,$idstatus)) {
97 1
            $status[] = 'Y';
98 1
        }
99
        
100 1
        if (in_array(2,$idstatus)) {
101 1
            $status[] = 'N';
102 1
        }
103
        
104 1
        $this->splittype = (bool) $splittype;
105
106 1
        if ($this->splittype) {
107
            $this->iterator = $this->getRequestTypeIterator($status);
108
        } else {
109 1
            $this->iterator = $this->getRequestIterator($status);
110
        }
111
112
        switch($wsepar)
113
        {
114 1
            case "1":
115 1
                $this->separ = ",";
116 1
                break;
117
            case "2":
118
                $this->separ = "\t";
119
                break;
120
            case "3":
121
                $this->separ = ";";
122
                break;
123
            default:
124
                $this->separ = $separ;
125
                if( empty($separ)) {
126
                    $this->separ = ",";
127
                }
128
                break;
129
        }
130
131 1
        $this->sepdec = $sepdec;
132
133 1
        $this->users_without_requests = (bool) $users_without_requests;
134
135 1
        $this->dirfields = $dirfields;
136 1
    }
137
    
138
    
139 1 View Code Duplication
    private function getRequestIterator($status)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141 1
        $I = new absences_EntryIterator();
142 1
        $I->from = $this->dateb->getIsoDateTime();
143 1
        $I->to = $this->datee->getIsoDateTime();
144
        
145 1
        if($this->organization){
146
            $I->organization = (int) $this->organization ;
147
        }
148
        
149
        
150 1
        $I->status = $status;
151
        
152 1
        return $I;
153
    }
154
    
155
    
156
    
157 1 View Code Duplication
    private function getRequestTypeIterator($status)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $I = new absences_ElementEntryIterator();
160
        $I->from = $this->dateb->getIsoDateTime();
161
        $I->to = $this->datee->getIsoDateTime();
162
        
163
        if($this->organization ){
164
            $I->organization = (int) $this->organization ;
165
        }
166
        
167 1
        $I->status = $status;
168
        
169
        return $I;
170
    }
171
172
173 1
    private function arr_csv(&$value)
174
    {
175 1
        $value = str_replace("\n"," ",$value);
176 1
        $value = str_replace('"',"'",$value);
177 1
        $value = '"'.$value.'"';
178 1
    }
179
180
181 1
    private function numberFormat($quantity)
182
    {
183 1
        return number_format($quantity, 1, $this->sepdec, '');
184
    }
185
    
186
    
187
    
188
    
189
190
191 1
    protected function getEntriesHeader()
192
    {
193 1
        global $babDB;
194
        
195 1
        $line = array();
196
197 1
        if ($this->dirfields) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->dirfields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
198
            $ov_fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
199
        }
200
201 1
        $line[] = absences_translate("lastname");
202 1
        $line[] = absences_translate("firstname");
203 1
        $line[] = absences_translate("Created on");
204 1
        $line[] = absences_translate("Modified on");
205
        
206 1
        $dirfields = array_keys($this->dirfields);
207 1
        foreach ($dirfields as $name) {
208
            $line[] = $ov_fields[$name]['name'];
0 ignored issues
show
Bug introduced by
The variable $ov_fields does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
209 1
        }
210 1
        $line[] = absences_translate("Begin date");
211 1
        $line[] = absences_translate("Begin hour");
212 1
        $line[] = absences_translate("End date");
213 1
        $line[] = absences_translate("End hour");
214 1
        $line[] = absences_translate("Status");
215 1
        $line[] = absences_translate("Total days");
216 1
        $line[] = absences_translate("Total hours");
217
218 1
        $res = $babDB->db_query("SELECT 
219
                t.id,
220
                t.name, 
221
                COUNT(rd.id) with_day,
222
                COUNT(rh.id) with_hour 
223
            FROM absences_types t 
224
                LEFT JOIN absences_rights rd ON rd.id_type=t.id AND rd.quantity_unit='D' 
225
                LEFT JOIN absences_rights rh ON rh.id_type=t.id AND rh.quantity_unit='H' 
226
            GROUP BY t.id 
227
            ORDER BY t.name 
228 1
        ");
229 1
        while ($arr = $babDB->db_fetch_assoc($res))
230
        {
231 1
            if ((bool) $arr['with_day']) {
232 1
                $line[] = $arr['name'].' '.absences_translate('days');
233 1
            }
234
            
235 1
            if ((bool) $arr['with_hour']) {
236
                $line[] = $arr['name'].' '.absences_translate('hours');
237
            }
238
            
239 1
            $this->types[] = array(
240 1
                'id'        => $arr['id'],
241 1
                'with_day'  => (bool) $arr['with_day'],
242 1
                'with_hour' => (bool) $arr['with_hour']
243 1
            );
244 1
        }
245 1
        array_walk($line, array($this, 'arr_csv'));
246
247 1
        return $line;
248
    }
249
    
250
    
251
    protected function getElementsHeader()
252
    {
253
        $line = array();
254
        
255
        $line[] = absences_translate("lastname");
256
        $line[] = absences_translate("firstname");
257
        $line[] = absences_translate("Created on");
258
        $line[] = absences_translate("Modified on");
259
        $dirfields = array_keys($this->dirfields);
260
        foreach ($dirfields as $name) {
261
            $line[] = $ov_fields[$name]['name'];
0 ignored issues
show
Bug introduced by
The variable $ov_fields does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
262
        }
263
        $line[] = absences_translate("Type");
264
        $line[] = absences_translate("Right");
265
        $line[] = absences_translate("Begin date");
266
        $line[] = absences_translate("Begin hour");
267
        $line[] = absences_translate("End date");
268
        $line[] = absences_translate("End hour");
269
        $line[] = absences_translate("Status");
270
        $line[] = absences_translate("Days");
271
        $line[] = absences_translate("Hours");
272
        
273
        array_walk($line, array($this, 'arr_csv'));
274
        
275
        return $line;
276
    }
277
    
278
    
279 1
    public function getHeader()
280
    {
281 1
        if ($this->splittype) {
282
            return $this->getElementsHeader();
283
        }
284
        
285 1
        return $this->getEntriesHeader();
286
    }
287
288
289 1 View Code Duplication
    private function getAgentDirValue(absences_Agent $agent, $fieldname)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
    {
291 1
        $direntry = $agent->getDirEntry();
292
293 1
        if (isset($direntry[$fieldname]))
294 1
        {
295 1
            return $direntry[$fieldname]['value'];
296
        }
297
298
        return '';
299
    }
300
301
302
    /**
303
     * Quantity for one type
304
     * @return float
305
     */
306 1
    private function getTypeDays(absences_Entry $entry, $id_type)
307
    {
308 1
        return $entry->getPlannedDaysBetween($this->iterator->from, $this->iterator->to, $id_type);
309
    }
310
311
312
    /**
313
     * Quantity for one type
314
     * @return float
315
     */
316
    private function getTypeHours(absences_Entry $entry, $id_type)
317
    {
318
        return $entry->getPlannedHoursBetween($this->iterator->from, $this->iterator->to, $id_type);
319
    }
320
321
    /**
322
     * Entry begin timestamp
323
     *
324
     * if overlap with the end date :
325
     * First try with planned periods (in database for absences >= 2.46)
326
     * second with the current working periods (if not removed by configuration)
327
     * last with the iterator boundaries
328
     *
329
     * @return int
330
     */
331 1
    private function getBeginTs(absences_Entry $entry)
332
    {
333 1
        if ($this->iterator->from > $entry->date_begin) {
334
335
            $day = substr($this->iterator->from, 0, 10);
336
            $planned = $entry->getDayPlannedPeriods($day);
337
338 View Code Duplication
            if (0 === count($planned)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
339
                $workingPeriods = $entry->getDayWorkingPeriods($day);
340
341
                if (0 === count($workingPeriods)) {
342
                    return bab_mktime($this->iterator->from);
343
                }
344
345
                $firstPeriod = reset($workingPeriods);
346
                return $firstPeriod->ts_begin;
347
            }
348
349
            $firstperiod = reset($planned);
350
351
            return bab_mktime($firstperiod->date_begin);
352
        }
353
354 1
        return bab_mktime($entry->date_begin);
355
    }
356
357
    /**
358
     * Entry end timestamp
359
     *
360
     * if overlap with the end date :
361
     * First try with planned periods (in database for absences >= 2.46)
362
     * second with the current working periods (if not removed by configuration)
363
     * last with the iterator boundaries
364
     *
365
     * @return int
366
     */
367 1
    private function getEndTs(absences_Entry $entry)
368
    {
369 1
        if ($this->iterator->to < $entry->date_end) {
370
371
            $end = $this->datee->cloneDate();
372
            $end->less(1, BAB_DATETIME_DAY); // un jour a ete ajoute pour inclure le dernier jour dans l'iterateur
373
                                             // on enleve 1 jour pour retrouver la date saisie
374
            $day = $end->getIsoDate();
375
            $planned = $entry->getDayPlannedPeriods($day);
376
377 View Code Duplication
            if (0 === count($planned)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
378
                $workingPeriods = $entry->getDayWorkingPeriods($day);
379
380
                if (0 === count($workingPeriods)) {
381
                    return bab_mktime($this->iterator->to);
382
                }
383
384
                $lastPeriod = end($workingPeriods);
385
                return $lastPeriod->ts_end;
386
            }
387
388
            $lastperiod = end($planned);
389
390
            return bab_mktime($lastperiod->date_end);
391
        }
392
393 1
        return bab_mktime($entry->date_end);
394
    }
395
    
396
    
397
    
398
    protected function getElementRow(absences_EntryElem $elem)
399
    {
400
        $entry = $elem->getEntry();
401
        $right = $elem->getRight();
402
        $type = $right->getType();
403
        $agent = $entry->getAgent();
404
        
405
        $line = array();
406
        
407
408
        $line[] = $this->getAgentDirValue($agent, 'sn');
409
        $line[] = $this->getAgentDirValue($agent, 'givenname');
410
        $line[] = bab_shortDate(bab_mktime($entry->createdOn), false);
411
        $line[] = bab_shortDate(bab_mktime($entry->modifiedOn()), false);
412
        foreach($this->dirfields as $name => $dummy)
413
        {
414
            $line[] = $this->getAgentDirValue($agent, $name);
415
        }
416
        $line[] = $type->name;
417
        $line[] = $right->description;
418
        
419
        $begin = bab_mktime($elem->date_begin);
420
        $end = bab_mktime($elem->date_end);
421
        
422
        $line[] = bab_shortDate($begin, false);
423
        $line[] = date('H:i', $begin);
424
        $line[] = bab_shortDate($end, false);
425
        $line[] = date('H:i', $end);
426
        $line[] = $entry->getShortStatusStr();
427
        
428
        $line[] = $this->numberFormat($elem->getDays());
429
        $line[] = $this->numberFormat($elem->getHours());
430
        
431
        array_walk($line, array($this, 'arr_csv'));
432
433
        return $line;
434
    }
435
436
437
    /**
438
     *
439
     * @return array
440
     */
441 1
    public function getEntryRow(absences_Entry $entry)
442
    {
443 1
        $agent = $entry->getAgent();
444
445 1
        if (isset($agent)) {
446 1
            $this->users_with_requests[] = $agent->getIdUser();
447 1
        }
448
449 1
        $line = array();
450 1
        $line[] = $this->getAgentDirValue($agent, 'sn');
0 ignored issues
show
Bug introduced by
It seems like $agent can be null; however, getAgentDirValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
451 1
        $line[] = $this->getAgentDirValue($agent, 'givenname');
0 ignored issues
show
Bug introduced by
It seems like $agent can be null; however, getAgentDirValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
452
        
453
        
454 1
        if (empty($line[0]) && empty($line[1])) {
455
            // the user has been deleted?
456
            return null;
457
        }
458
        
459
        
460 1
        $line[] = bab_shortDate(bab_mktime($entry->createdOn), false);
461 1
        $line[] = bab_shortDate(bab_mktime($entry->modifiedOn()), false);
462
463 1
        foreach($this->dirfields as $name => $dummy)
464
        {
465
            $line[] = $this->getAgentDirValue($agent, $name);
0 ignored issues
show
Bug introduced by
It seems like $agent can be null; however, getAgentDirValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
466 1
        }
467
468 1
        $begin = $this->getBeginTs($entry);
469 1
        $end = $this->getEndTs($entry);
470
471 1
        $line[] = bab_shortDate($begin, false);
472 1
		$line[] = date('H:i', $begin);
473 1
		$line[] = bab_shortDate($end, false);
474 1
		$line[] = date('H:i', $end);
475 1
        $line[] = $entry->getShortStatusStr();
476
477 1
        $pos = count($line);
478 1
        $tdays = 0.0;
479 1
        $thours = 0.0;
480 1
        foreach ($this->types as $_arr) {
481
            
482 1
            $id_type = $_arr['id'];
483
            
484 1
            if ($_arr['with_day']) {
485 1
                $days = $this->getTypeDays($entry, $id_type);
486 1
                $line[] = $this->numberFormat($days);
487 1
                $tdays += $days;
488 1
            }
489
            
490 1
            if ($_arr['with_hour']) {
491
                $hours = $this->getTypeHours($entry, $id_type);
492
                $line[] = $this->numberFormat($hours);
493
                $thours += $hours;
494
            }
495
            
496 1
        }
497
        
498
        
499 1
        if (0 === (int) round(100 * $tdays) && 0 === (int) round(100 * $thours)) {
500
            return null;
501
        }
502
        
503
504 1
        array_splice($line, $pos++, 0, $this->numberFormat($tdays));
505 1
        array_splice($line, $pos++, 0, $this->numberFormat($thours));
506
507 1
        array_walk($line, array($this, 'arr_csv'));
508
509 1
        return $line;
510
    }
511
512
    
513
    
514
    public function getRow($object)
515
    {
516
        if ($this->splittype) {
517
            return $this->getElementRow($object);
518
        }
519
        
520
        return $this->getEntryRow($object);
521
    }
522
    
523
    
524
525
    /**
526
     * @return absences_Agent[]
527
     */
528
    private function getUsersWithoutRequests()
529
    {
530
        $I = new absences_AgentIterator();
531
        if (count($this->users_with_requests) > 0)
532
        {
533
            $I->exclude_users = $this->users_with_requests;
534
        }
535
        if($this->organization){
536
        	$Orga = absences_Organization::getById($this->organization);
537
        	$I->setOrganization($Orga);
538
        }
539
        return $I;
540
    }
541
542
543
    /**
544
     * @return array
545
     */
546 1
    public function getAgentRow(absences_Agent $agent)
547
    {
548
549 1
        $line = array();
550 1
        $line[] = $this->getAgentDirValue($agent, 'sn');
551 1
        $line[] = $this->getAgentDirValue($agent, 'givenname');
552 1
        $line[] = '';
553 1
        $line[] = '';
554 1
        foreach($this->dirfields as $name => $dummy)
555
        {
556
            $line[] = $this->getAgentDirValue($agent, $name);
557 1
        }
558
559 1
        $line[] = '';
560 1
        $line[] = '';
561 1
        $line[] = '';
562 1
        $line[] = '';
563 1
        $line[] = '';
564 1
        $line[] = 0;
565 1
        $line[] = 0;
566 1
        foreach ($this->types as $_arr) {
567 1
            if ($_arr['with_day']) {
568 1
                $line[] = 0;
569 1
            }
570
            
571 1
            if ($_arr['with_hour']) {
572
                $line[] = 0;
573
            }
574 1
        }
575
576 1
        array_walk($line, array($this, 'arr_csv'));
577
578 1
        return $line;
579
    }
580
581
582
583
    public function output()
584
    {
585
586
        header("Content-Disposition: attachment; filename=\"".absences_translate("Vacation").".csv\""."\n");
587
        header("Content-Type: text/csv"."\n");
588
589
        $header = $this->getHeader();
590
        echo implode($this->separ, $header)."\n";
591
592
        foreach ($this->iterator as $object) {
593
            $line = $this->getRow($object);
594
            
595
            
596
            if (!isset($line)) {
597
                // the entry contain no total quantity or no directory entry
598
                continue;
599
            }
600
601
            
602
603
            echo implode($this->separ, $line)."\n";
604
        }
605
606
        if ($this->users_without_requests) {
607
            foreach ($this->getUsersWithoutRequests() as $agent) {
608
                $line = $this->getAgentRow($agent);
609
                echo implode($this->separ, $line)."\n";
610
            }
611
        }
612
613
        exit;
614
    }
615
}
616
617