Completed
Push — master ( 03fcbe...f90b04 )
by Paul
10:38
created

absences_ExportEntry::getRow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 6
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 1
80
    /**
81 1
     * @var int
82 1
     */
83 1
    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 1
    {
87
        $this->dateb = $dateb;
88 1
        $this->datee = $datee;
89
        $this->organization = $organization;
90 1
91
        $status = array();
92
        if (in_array(0,$idstatus)) {
93
            $status[] = '';
94 1
        }
95 1
        
96 1
        if (in_array(1,$idstatus)) {
97 1
            $status[] = 'Y';
98
        }
99 1
        
100 1
        if (in_array(2,$idstatus)) {
101 1
            $status[] = 'N';
102
        }
103 1
        
104 1
        $this->splittype = (bool) $splittype;
105 1
106
        if ($this->splittype) {
107 1
            $this->iterator = $this->getRequestTypeIterator($status);
108
        } else {
109 1
            $this->iterator = $this->getRequestIterator($status);
110
        }
111
112
        switch($wsepar)
113 1
        {
114 1
            case "1":
115 1
                $this->separ = ",";
116
                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 1
131
        $this->sepdec = $sepdec;
132 1
133
        $this->users_without_requests = (bool) $users_without_requests;
134 1
135 1
        $this->dirfields = $dirfields;
136
    }
137
    
138 1
    
139 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 1
    {
141 1
        $I = new absences_EntryIterator();
142 1
        $I->from = $this->dateb->getIsoDateTime();
143 1
        $I->to = $this->datee->getIsoDateTime();
144
        
145
        if($this->organization){
146 1
            $I->organization = (int) $this->organization ;
147
        }
148 1
        
149
        
150
        $I->status = $status;
151
        
152 1
        return $I;
153
    }
154 1
    
155
    
156 1
    
157 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 1
    {
159
        $I = new absences_ElementEntryIterator();
160
        $I->from = $this->dateb->getIsoDateTime();
161
        $I->to = $this->datee->getIsoDateTime();
162 1
        
163 1
        if($this->organization ){
164 1
            $I->organization = (int) $this->organization ;
165 1
        }
166 1
        
167 1
        $I->status = $status;
168 1
        
169 1
        return $I;
170 1
    }
171 1
172 1
173 1
    private function arr_csv(&$value)
174 1
    {
175 1
        $value = str_replace("\n"," ",$value);
176
        $value = str_replace('"',"'",$value);
177 1
        $value = '"'.$value.'"';
178
    }
179
180
181
    private function numberFormat($quantity)
182
    {
183
        return number_format($quantity, 1, $this->sepdec, '');
184
    }
185
    
186
    
187 1
    
188 1
    
189
190 1
191 1
    protected function getEntriesHeader()
192 1
    {
193
        global $babDB;
194 1
        
195
        $line = array();
196
197
        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 1
            $ov_fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
199 1
        }
200 1
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
        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
        }
210 1
        $line[] = absences_translate("Begin date");
211
        $line[] = absences_translate("Begin hour");
212 1
        $line[] = absences_translate("End date");
213
        $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
        $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 1
            ORDER BY t.name 
228
        ");
229 1
        while ($arr = $babDB->db_fetch_assoc($res))
230
        {
231
            if ((bool) $arr['with_day']) {
232
                $line[] = $arr['name'].' '.absences_translate('days');
233
            }
234
            
235
            if ((bool) $arr['with_hour']) {
236
                $line[] = $arr['name'].' '.absences_translate('hours');
237
            }
238
            
239
            $this->types[] = array(
240
                'id'        => $arr['id'],
241
                'with_day'  => (bool) $arr['with_day'],
242
                'with_hour' => (bool) $arr['with_hour']
243
            );
244
        }
245
        array_walk($line, array($this, 'arr_csv'));
246
247
        return $line;
248
    }
249
    
250
    
251
    protected function getElementsHeader()
252 1
    {
253
        $line = array();
254 1
        
255
        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...
256
            $ov_fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
0 ignored issues
show
Unused Code introduced by
$ov_fields is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
257
        }
258
        
259
        $line[] = absences_translate("lastname");
260
        $line[] = absences_translate("firstname");
261
        $line[] = absences_translate("Created on");
262
        $line[] = absences_translate("Modified on");
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 1
        return $line;
276
    }
277
    
278
    
279
    protected function getHeader()
280
    {
281
        if ($this->splittype) {
282
            return $this->getElementsHeader();
283
        }
284
        
285
        return $this->getEntriesHeader();
286
    }
287
288 1
289 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 1
    {
291
        $direntry = $agent->getDirEntry();
292
293
        if (isset($direntry[$fieldname]))
294
        {
295
            return $direntry[$fieldname]['value'];
296
        }
297
298
        return '';
299
    }
300
301
302
    /**
303
     * Quantity for one type
304
     * @return float
305
     */
306
    private function getTypeDays(absences_Entry $entry, $id_type)
307
    {
308
        return $entry->getPlannedDaysBetween($this->iterator->from, $this->iterator->to, $id_type);
309
    }
310
311
312
    /**
313
     * Quantity for one type
314 1
     * @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 1
     * Entry begin timestamp
323
     *
324 1
     * if overlap with the end date :
325
     * First try with planned periods (in database for absences >= 2.46)
326 1
     * second with the current working periods (if not removed by configuration)
327 1
     * last with the iterator boundaries
328 1
     *
329
     * @return int
330 1
     */
331 1
    private function getBeginTs(absences_Entry $entry)
332 1
    {
333
        if ($this->iterator->from > $entry->date_begin) {
334
335 1
            $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 1
                if (0 === count($workingPeriods)) {
342 1
                    return bab_mktime($this->iterator->from);
343
                }
344 1
345
                $firstPeriod = reset($workingPeriods);
346
                return $firstPeriod->ts_begin;
347 1
            }
348
349 1
            $firstperiod = reset($planned);
350 1
351
            return bab_mktime($firstperiod->date_begin);
352 1
        }
353 1
354 1
        return bab_mktime($entry->date_begin);
355 1
    }
356 1
357
    /**
358 1
     * Entry end timestamp
359 1
     *
360 1
     * if overlap with the end date :
361 1
     * First try with planned periods (in database for absences >= 2.46)
362
     * second with the current working periods (if not removed by configuration)
363 1
     * last with the iterator boundaries
364
     *
365 1
     * @return int
366 1
     */
367 1
    private function getEndTs(absences_Entry $entry)
368 1
    {
369 1
        if ($this->iterator->to < $entry->date_end) {
370
371 1
            $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 1 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 1
                if (0 === count($workingPeriods)) {
381
                    return bab_mktime($this->iterator->to);
382
                }
383
384
                $lastPeriod = end($workingPeriods);
385 1
                return $lastPeriod->ts_end;
386 1
            }
387
388 1
            $lastperiod = end($planned);
389
390 1
            return bab_mktime($lastperiod->date_end);
391
        }
392
393
        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
        $line[] = $type->name;
413
        $line[] = $right->description;
414
        
415 1
        $begin = $this->getBeginTs($entry);
416
        $end = $this->getEndTs($entry);
417
        
418 1
        $line[] = bab_shortDate($begin, false);
419 1
        $line[] = date('H:i', $begin);
420 1
        $line[] = bab_shortDate($end, false);
421 1
        $line[] = date('H:i', $end);
422 1
        $line[] = $entry->getShortStatusStr();
423 1
        
424
        $line[] = $this->numberFormat($elem->getDays());
425
        $line[] = $this->numberFormat($elem->getHours());
426 1
        
427
        array_walk($line, array($this, 'arr_csv'));
428 1
429 1
        return $line;
430 1
    }
431 1
432 1
433 1
    /**
434 1
     *
435 1
     * @return array
436 1
     */
437 1
    protected function getEntryRow(absences_Entry $entry)
438 1
    {
439
        $agent = $entry->getAgent();
440 1
441
        if (isset($agent)) {
442
            $this->users_with_requests[] = $agent->getIdUser();
443 1
        }
444
445 1
        $line = array();
446
        $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...
447 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...
448
        
449
        
450
        if (empty($line[0]) && empty($line[1])) {
451
            // the user has been deleted?
452
            return null;
453
        }
454
        
455
        
456
        $line[] = bab_shortDate(bab_mktime($entry->createdOn), false);
457
        $line[] = bab_shortDate(bab_mktime($entry->modifiedOn()), false);
458
459
        foreach($this->dirfields as $name => $dummy)
460
        {
461
            $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...
462
        }
463
464
        $begin = $this->getBeginTs($entry);
465
        $end = $this->getEndTs($entry);
466
467
        $line[] = bab_shortDate($begin, false);
468
		$line[] = date('H:i', $begin);
469
		$line[] = bab_shortDate($end, false);
470
		$line[] = date('H:i', $end);
471
        $line[] = $entry->getShortStatusStr();
472
473
        $pos = count($line);
474
        $tdays = 0.0;
475
        $thours = 0.0;
476
        foreach ($this->types as $_arr) {
477
            
478
            $id_type = $_arr['id'];
479
            
480
            if ($_arr['with_day']) {
481
                $days = $this->getTypeDays($entry, $id_type);
482
                $line[] = $this->numberFormat($days);
483
                $tdays += $days;
484
            }
485
            
486
            if ($_arr['with_hour']) {
487
                $hours = $this->getTypeHours($entry, $id_type);
488
                $line[] = $this->numberFormat($hours);
489
                $thours += $hours;
490
            }
491
            
492
        }
493
        
494
        
495
        if (0 === (int) round(100 * $tdays) && 0 === (int) round(100 * $thours)) {
496
            return null;
497
        }
498
        
499
500
        array_splice($line, $pos++, 0, $this->numberFormat($tdays));
501
        array_splice($line, $pos++, 0, $this->numberFormat($thours));
502
503
        array_walk($line, array($this, 'arr_csv'));
504
505
        return $line;
506
    }
507
508
    
509
    
510
    public function getRow($object)
511
    {
512
        if ($this->splittype) {
513
            return $this->getElementRow($object);
514
        }
515
        
516
        return $this->getEntryRow($object);
517
    }
518
    
519
    
520
521
    /**
522
     * @return absences_Agent[]
523
     */
524
    private function getUsersWithoutRequests()
525
    {
526
        $I = new absences_AgentIterator();
527
        if (count($this->users_with_requests) > 0)
528
        {
529
            $I->exclude_users = $this->users_with_requests;
530
        }
531
        if($this->organization){
532
        	$Orga = absences_Organization::getById($this->organization);
533
        	$I->setOrganization($Orga);
534
        }
535
        return $I;
536
    }
537
538
539
    /**
540
     * @return array
541
     */
542
    public function getAgentRow(absences_Agent $agent)
543
    {
544
545
        $line = array();
546
        $line[] = $this->getAgentDirValue($agent, 'sn');
547
        $line[] = $this->getAgentDirValue($agent, 'givenname');
548
        $line[] = '';
549
        $line[] = '';
550
        foreach($this->dirfields as $name => $dummy)
551
        {
552
            $line[] = $this->getAgentDirValue($agent, $name);
553
        }
554
555
        $line[] = '';
556
        $line[] = '';
557
        $line[] = '';
558
        $line[] = '';
559
        $line[] = '';
560
        $line[] = 0;
561
        $line[] = 0;
562
        foreach ($this->types as $_arr) {
563
            if ($_arr['with_day']) {
564
                $line[] = 0;
565
            }
566
            
567
            if ($_arr['with_hour']) {
568
                $line[] = 0;
569
            }
570
        }
571
572
        array_walk($line, array($this, 'arr_csv'));
573
574
        return $line;
575
    }
576
577
578
579
    public function output()
580
    {
581
582
        header("Content-Disposition: attachment; filename=\"".absences_translate("Vacation").".csv\""."\n");
583
        header("Content-Type: text/csv"."\n");
584
585
        $header = $this->getHeader();
586
        echo implode($this->separ, $header)."\n";
587
588
        foreach ($this->iterator as $object) {
589
            $line = $this->getRow($object);
590
            
591
            
592
            if (!isset($line)) {
593
                // the entry contain no total quantity or no directory entry
594
                continue;
595
            }
596
597
            
598
599
            echo implode($this->separ, $line)."\n";
600
        }
601
602
        if ($this->users_without_requests) {
603
            foreach ($this->getUsersWithoutRequests() as $agent) {
604
                $line = $this->getAgentRow($agent);
605
                echo implode($this->separ, $line)."\n";
606
            }
607
        }
608
609
        exit;
610
    }
611
}
612
613