Completed
Push — master ( 80924f...e83060 )
by Paul
04:24
created

absences_Request::getById()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
nc 1
dl 0
loc 1
ccs 0
cts 1
cp 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
26
require_once dirname(__FILE__).'/record.class.php';
27
28
29
30
31
32
33
/**
34
 * A user request (entry, cet deposit, workperiod recover)
35
 * 
36
 * @property	int 	$id
37
 * @property	int 	$id_user
38
 * @property 	int		$idfai
39
 * @property 	string	$status
40
 * @property 	int		$id_approver
41
 * @property 	int		$appr_notified	
42
 * @property	string	$comment2
43
 * @property    int     $todelete
44
 * @property    int     $firstconfirm
45
 * 
46
 */
47
abstract class absences_Request extends absences_Record
48
{
49
	
50
	/**
51
	 *
52
	 * @var absences_Agent
53
	 */
54
	protected $agent;
55
	
56
	
57
	/**
58
	 * 
59
	 * @var absences_Movement
60
	 */
61
	private $lastMovement;
62
	
63
	
64
	
65
	/**
66
	 * @param int $id
67
	 * @return absences_Request
68
	 */
69
	abstract static public function getById($id);
70
	
71
	
72
	/**
73
	 * @return absences_Agent
74
	 */
75 5 View Code Duplication
	public function getAgent()
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...
76
	{
77 5
		require_once dirname(__FILE__).'/agent.class.php';
78
	
79 5
		if (!isset($this->agent))
80 5
		{
81 5
			$row = $this->getRow();
82 5
			$this->agent = absences_Agent::getFromIdUser($row['id_user']);
83 5
		}
84
	
85 5
		return $this->agent;
86
	}
87
	
88
	
89
	
90
	
91
	/**
92
	 * Method to sort requests by creation date
93
	 */
94
	public function createdOn()
95
	{
96
		return $this->createdOn;
0 ignored issues
show
Documentation introduced by
The property createdOn does not exist on object<absences_Request>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
97
	}
98
99
	/**
100
	 * Method to sort requests by modification date
101
	 */
102
	public function modifiedOn()
103
	{
104
		return $this->modifiedOn;
0 ignored issues
show
Documentation introduced by
The property modifiedOn does not exist on object<absences_Request>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
105
	}
106
107
	/**
108
	 *
109
	 * @return string
110
	 */
111
	public function getUserName()
112
	{
113
		return bab_getUserName($this->id_user);
114
	}
115
116
117
	protected function labelledValue($title, $value)
118
	{
119
		$W = bab_Widgets();
120
		return $W->FlowItems($W->Label($title)->addClass('widget-strong')->colon(), $W->Label($value))->setHorizontalSpacing(.4,'em');
121
	}
122
	
123
	/**
124
	 * 
125
	 * @return string
126
	 */
127
	abstract public function getRequestType();
128
	
129
	/**
130
	 * Get status on date
131
	 * @param string $date
132
	 * @return string
133
	 */
134 10
	public function getDateStatus($date)
135
	{
136 10
        if (!isset($date) || '0000-00-00' === $date) {
137 4
            return $this->status;
138
        }
139
	    
140
	    
141 7
	    require_once dirname(__FILE__).'/movement.class.php';
142 7
	    $I = new absences_MovementIterator();
143 7
	    $I->setRequest($this);
144 7
	    $I->createdOn = $date;
145
	    
146 7
	    foreach($I as $movement) {
147
148
	        // mouvement le plus recent avant la date
149
	        
150 4
	        if (!isset($movement->status)) {
151
	            // movement created before status field in database
152
	            return $this->status;
153
	        }
154
	        
155 4
	        return $movement->status;
156
	        
157 6
	    }
158
	    
159 6
	    return $this->status;
160
	}
161
	
162
	/**
163
	 * @return string
164
	 */
165 1
	public function getShortStatusStr()
166
	{
167 1
	    switch($this->status)
168
	    {
169 1
	        case 'Y':
170 1
	            return absences_translate("Accepted");
171
	        case 'N':
172
	            return absences_translate("Refused");
173
	        case 'P':
174
	            return absences_translate("Previsional request");
175
	        default:
176
	            return absences_translate("Waiting approval");
177
	    }
178
	}
179
180
181
	/**
182
	 * Get status as a string
183
	 * @return string
184
	 */
185
	public function getStatusStr()
186
	{
187
		switch($this->status)
188
		{
189
			case 'Y':
190
				return absences_translate("Accepted");
191
			case 'N':
192
				return absences_translate("Refused");
193
			case 'P':
194
				return absences_translate("Previsional request");
195
			default:
196
			    if ($this->todelete) {
197
			        return sprintf(absences_translate("Will be deleted after approval by %s"), $this->getNextApprovers());
198
			    }
199
				return sprintf(absences_translate("Waiting approval by %s"), $this->getNextApprovers());
200
		}
201
	}
202
	
203
	
204
	
205
	/**
206
	 * @return Widget_Icon
207
	 */
208
	public function getStatusIcon()
209
	{
210
		$W = bab_Widgets();
211
		
212
		switch($this->status)
213
		{
214
			case 'Y':
215
				$icon = Func_Icons::ACTIONS_DIALOG_OK;
216
				break;
217
			case 'N':
218
				$icon = Func_Icons::ACTIONS_DIALOG_CANCEL;
219
				break;
220
			case 'P':
221
				$icon = Func_Icons::STATUS_DIALOG_QUESTION;
222
				break;
223
			default:
224
				$icon = Func_Icons::ACTIONS_VIEW_HISTORY;
225
				break;
226
		}
227
		
228
		return $W->Icon($this->getStatusStr(), $icon);
229
	}
230
	
231
	
232
	/**
233
	 * Test if the has been fixed by a manager (not modifiable by the user)
234
	 * @return bool
235
	 */
236
	public function isFixed()
237
	{
238
	    return false;
239
	
240
	}
241
242
243 4
	private function getNames($arr)
244 4
	{
245
		$return = array();
246
247
		foreach($arr as $k => $id_user)
248 4
		{
249
			$return[$k] = bab_getUserName($id_user);
250
		}
251
252
		return $return;
253
	}
254
255
256
	/**
257
	 * @return string
258
	 */
259 4
	public function getNextApprovers()
260
	{
261 4
		require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
262
263
		$arr = bab_WFGetWaitingApproversInstance($this->idfai);
264
265
		if (count($arr) <= 3)
266
		{
267
			return implode(', ', $this->getNames($arr));
268 4
		}
269
270
		$first = array_shift($arr);
271
		$second = array_shift($arr);
272
273
		return sprintf(absences_translate('%s, %s and %d other approvers'), bab_getUserName($first), bab_getUserName($second), count($arr));
274
	}
275
	
276
	/**
277
	 * Get the apporbation sheme ID for the request
278
	 * @return int
279
	 */
280 4
	abstract public function getApprobationId();
281
	
282
	
283
	
284
	/**
285
	 * @return bool
286
	 */
287 4
	protected function autoApproval()
288
	{
289
	    $this->onConfirm();
290
	    $this->addMovement(sprintf(absences_translate('The %s has been accepted with auto-approval'), $this->getTitle()));
291 4
	    return false;
292
	}
293
	
294
	
295
	
296 4
	private function getAutoApprovalUserId()
297 4
	{
298
	    if (!absences_getVacationOption('auto_approval')) {
299
	        return 0;
300
	    }
301
	    
302 4
	    return bab_getUserId();
303
	}
304
	
305
	
306
	
307
	/**
308
	 * Create approbation instance and set it "notified" but do not send email notification
309
	 * retourne TRUE si la demande est bien devenue en attente d'approbation
310
	 * @return bool
311
	 */
312 4
	public function createApprobationInstance()
313
	{
314
		require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
315
		
316
		if (isset($this->idfai) && $this->idfai > 0)
317
		{
318
			bab_WFDeleteInstance($this->idfai);
319
		}
320
		
321
		// si le 3eme parametre est passe avec l'id user en cours, cela active l'auto-approbation
322
		// l'auto-approbation a ete active a partir de la version 2.21 du module
323
		// le dernier parametre necessite la version 8.0.100 d'ovidentia pour fonctionner (correction du bug de detection du supperieur hierarchique quand le gestionnaire depose l'absence)
324
		
325
		$idfai = bab_WFMakeInstance($this->getApprobationId(), get_class($this).':'.$this->id, $this->getAutoApprovalUserId(), $this->id_user);
326
		if (is_int($idfai))
327
		{
328
			$users = bab_WFGetWaitingApproversInstance($idfai, true);
329
			if (count($users) == 0)
330
			{
331
				$a = bab_WFGetApprobationInfos($this->getApprobationId());
332
				
333
				// l'instance n'a pas fonctionne
334
				bab_WFDeleteInstance($idfai);
335
				//TRANSLATORS: \n%1: request type (vacation request), \n%2: schema type (Staff schema), \n%3: schema name
336
				$this->addMovement(sprintf(absences_translate('The approval initialisation failed on the %s because no approvers were found on %s %s'), $this->getTitle(), mb_strtolower($a['type']), $a['name']));
337
				return $this->autoApproval();
338
			}
339
			
340
			if (isset($this->todelete) && $this->todelete) {
341
			    $this->addMovement(sprintf(absences_translate('The %s has been sent to deletion approval'), $this->getTitle()));
342 4
			} else {
343 4
			    $this->addMovement(sprintf(absences_translate('The %s has been sent for approval'), $this->getTitle()));
344 4
			}
345
			
346 4
		} else { // $idfai == TRUE : auto-approbation end schema
347 4
			return $this->autoApproval();
348 4
		}
349
		
350 4
		$this->idfai = $idfai;
351
		$this->status = '';
352
		$this->id_approver = 0;
353
		$this->appr_notified = 0;
354
		$this->comment2 = '';
355
		$this->save();
356
357
		return true;
358
	}
359
	
360
	
361
	/**
362
	 * Approbator confirm
363
	 * move to next approbator or close instance and set the request accepted
364
	 * 
365
	 * 
366
	 * @param	bool	$status				Accept or reject approbation step
367
	 * @param	string	$approver_comment	
368
	 * 
369
	 */
370
	public function approbationNext($status, $approver_comment)
371
	{
372
		require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
373
		$res = bab_WFUpdateInstance($this->idfai, bab_getUserId(), $status);
374
		
375
		switch ($res) {
376
			case 0:
377
				bab_WFDeleteInstance($this->idfai);
378
				$this->idfai = 0;
379
				if ($this->todelete) {
380
				    
381
				    // demande de suppression refusee
382
				    $this->status = 'Y';
383
				} else {
384
				    $this->status = 'N';
385
				}
386
				$this->onReject();
387
				break;
388
				
389
			case 1:
390
				bab_WFDeleteInstance($this->idfai);
391
				$this->idfai = 0;
392
				$this->status = 'Y';
393
				
394
				if (!$this->firstconfirm) {
395
				    $this->firstconfirm = 1;
396
				}
397
				
398
				if ($this->todelete) {
399
				    return $this->delete();
400
				}
401
				$this->onConfirm();
402
				break;
403
404
				
405
			default: // -1
406
				$nfusers = bab_WFGetWaitingApproversInstance($this->idfai, true);
407
				if (count($nfusers) > 0) {
408
					$this->appr_notified = 0;
409
				} else {
410
					// no approvers found or approvers allready notified (all user must confirm without order)
411
					// do nothing
412
				}
413
				
414
			break;
415
		}
416
417
		$this->id_approver = bab_getUserId();
418
		$this->comment2 = $approver_comment;
419
		$this->save();
420
		
421
		
422
		$str_status = $status ? absences_translate('accepted') :absences_translate('rejected');
423
		
424
		// movement must be saved after status modification to save the new status in movement
425
		$this->addMovement(
426
		    sprintf(absences_translate('The %s has been %s by %s'), $this->getTitle(), $str_status, bab_getUserName(bab_getUserId())),
427
		    $approver_comment
428
		);
429
		
430
	}
431
	
432
	
433
	
434
	/**
435
	 * Auto confirm the request
436
	 */
437
	public function autoConfirm()
438
	{
439
		$this->addMovement(
440
			sprintf(absences_translate('The %s has been confirmed automatically because of the validation timout'), $this->getTitle())
441
		);
442
		
443
		
444
		if ($this->idfai > 0)
445
		{
446
			require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
447
			bab_WFDeleteInstance($this->idfai);
448
		}
449
		
450
		$this->idfai = 0;
451
		$this->status = 'Y';
452
		$this->onConfirm();
453
		
454
		$this->id_approver = 0;
455
		$this->save();
456
		$this->notifyOwner();
457
	}
458
	
459
	
460
	
461
	/**
462
	 * Test if the logged in user can modify the entry
463
	 * @return bool
464
	 */
465
	public function canModify()
466
	{
467
	    $modify_waiting = (bool) absences_getVacationOption('modify_waiting');
468
	    $modify_confirmed = (bool) absences_getVacationOption('modify_confirmed');
469
	    
470
		require_once dirname(__FILE__).'/agent.class.php';
471
		$agent = absences_Agent::getCurrentUser();
472
	
473
		$personal = ($agent->isInPersonnel() && $agent->id_user === $this->id_user);
474
	
475
		switch($this->status)
476
		{
477
			case 'Y': // confirmed
478
			    if ($this->isFixed()) {
479
			        return false;
480
			    }
481
482
			    if ($modify_confirmed) {
483
			        return true;
484
			    }
485
			    
486
			    return !$personal; // ce n'est pas ma propre demande, je suis gestionnaire delegue
487
488
				
489
	
490
			case 'N': // rejected
491
				return false;
492
	
493
			case 'P': // previsional
494
				return $personal;
495
	
496
			default: // waiting
497
				return ($personal && $modify_waiting);
498
		}
499
	}
500
	
501
	
502
	/**
503
	 * Test if the user can delete the entry
504
	 * @return bool
505
	 */
506
	public function canDelete()
507
	{
508
		return $this->canModify();
509
	}
510
	
511
	
512
	
513
	
514
	
515
	/**
516
	 * Process specific code when the request is rejected
517
	 *
518
	 */
519
	abstract protected function onReject();
520
	
521
	/**
522
	 * Process specific code when the request is confirmed
523
	 */
524
	abstract protected function onConfirm();
525
526
	/**
527
	 * request title
528
	 * @return string
529
	 */
530
	abstract public function getTitle();
531
532
533
	
534
	/**
535
	 * Get a list of field to display in the notifications for this request
536
	 * @return array
537
	 */
538
	abstract public function getNotifyFields();
539
	
540
	
541
	/**
542
	 * annee de la demande
543
	 * @return int
544
	 */
545
	abstract public function getYear();
546
	
547
	
548
	/**
549
	 * annee de la demande, pour l'archivage par annee, tiens compte du parametrage du mois de debut de periode.
550
	 * Utilise dans l'archivage par annee
551
	 * @return int
552
	 */
553
	abstract public function getArchiveYear();
554
	
555
	
556
	abstract public function archive();
557
	
558
	
559
	/**
560
	 * approver has been notified
561
	 */
562
	abstract public function setNotified();
563
	
564
	
565
	/**
566
	 * Url to edit request as a manager
567
	 */
568
	abstract public function getManagerEditUrl();
569
	
570
	/**
571
	 * Url to delete request as a manager
572
	 */
573
	abstract public function getManagerDeleteUrl();
574
	
575
	
576
	/**
577
	 * Notify request next approvers
578
	 */
579
	public function notifyApprovers()
580
	{
581
		$defer = (bool) absences_getVacationOption('approb_email_defer');
582
		if (!$defer)
583
		{
584
			require_once dirname(__FILE__).'/request.notify.php';
585
			absences_notifyRequestApprovers();
586
		}
587
	}
588
	
589
	
590
	/**
591
	 * Notify request owner about the approval or reject of the request
592
	 */
593
	public function notifyOwner()
594
	{
595
		$appliquant_email = (bool) absences_getVacationOption('appliquant_email');
596
		
597
		if (!$appliquant_email)
598
		{
599
			return;
600
		}
601
		
602
		require_once dirname(__FILE__).'/request.notify.php';
603
		
604
		
605
		
606
		switch($this->status)
607
		{
608
			case 'N':
609
				$subject = sprintf(absences_translate("Your %s has been refused"), $this->getTitle());
610
				break;
611
				
612
			case 'Y':
613
				$subject = sprintf(absences_translate("Your %s has been accepted"), $this->getTitle());
614
				break;
615
				
616
			default: // next approver
617
				return;
618
		}
619
		
620
		absences_notifyRequestAuthor(array($this), $subject, $subject, $this->id_user);
621
	}
622
623
624
	/**
625
	 * Get request card frame to display in requests list
626
	 * @param bool 			$display_username	Affiche le nom du demandeur dans la card frame ou non, utile pour les listes contenant plusieurs demandeurs possibles
627
	 * @param int			$rfrom				si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue
628
 	 * @param int			$ide				id entite de l'organigramme >0 si gestionnaire delegue seulement
629
	 * @return Widget_Frame
630
	 */
631
	abstract public function getCardFrame($display_username, $rfrom, $ide);
632
633
	
634
	/**
635
	 * Get request frame to display in manager lists
636
	 * @return Widget_Frame
637
	 */
638
	abstract public function getManagerFrame();
639
	
640
641
	
642
	/**
643
	 * Delete request
644
	 */
645
	public function delete()
646
	{
647
		if ($this->idfai > 0)
648
		{
649
			require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
650
			bab_WFDeleteInstance($this->idfai);
651
		}
652
		
653
		global $babDB;
654
		$babDB->db_query("UPDATE absences_movement SET id_request='0' WHERE request_class=".$babDB->quote(get_class($this))." AND id_request=".$babDB->quote($this->id));
655
	}
656
	
657
	
658
	
659
	/**
660
	 * @return absences_MovementIterator
661
	 */
662
	public function getMovementIterator()
663
	{
664
		require_once dirname(__FILE__).'/movement.class.php';
665
	
666
		$I = new absences_MovementIterator;
667
		$I->setRequest($this);
668
	
669
		return $I;
670
	}
671
	
672
	
673
	
674
	/**
675
	 *
676
	 * @param string $message	Generated message
677
	 * @param string $comment	Author comment
678
	 */
679 4 View Code Duplication
	public function addMovement($message, $comment = '', $createdOn = null)
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...
680
	{
681 4
		require_once dirname(__FILE__).'/movement.class.php';
682
	
683 4
		$movement = new absences_Movement();
684 4
		$movement->message = $message;
685 4
		$movement->comment = $comment;
686 4
		$movement->setRequest($this);
687 4
		$movement->setAgent($this->getAgent());
688 4
		$movement->createdOn = $createdOn;
689 4
		$movement->save();
690 4
	}
691
	
692
	
693
	
694
	/**
695
	 * @return absences_Movement
696
	 */
697
	public function getLastMovement()
698
	{
699
		if (!isset($this->lastMovement))
700
		{
701
			$this->lastMovement = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<absences_Movement> of property $lastMovement.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
702
			$I = $this->getMovementIterator();
703
			foreach($I as $movement)
704
			{
705
				$this->lastMovement = $movement;
706
				break;
707
			}
708
		}
709
		
710
		return $this->lastMovement;
711
	}
712
	
713
	
714
	/**
715
	 * Faut-il allerter l'approbateur que le delai d'approbation est depasse
716
	 * @return bool
717
	 */
718
	public function approbAlert()
719
	{
720
		$last = $this->getLastMovement();
721
		
722
		if (!$last)
723
		{
724
			return false;
725
		}
726
			
727
		$s = (time() - bab_mktime($last->createdOn));
728
		$d = ($s / 86400);
729
		
730
		$approb_alert = (int) absences_getVacationOption('approb_alert');
731
		
732
		if ($approb_alert > $d)
733
		{
734
			return false;
735
		}
736
		
737
		return true;
738
	}
739
}
740
741
742
743
744
745
746
747
748
749
/**
750
 * Get the list of request from the users, requests are :
751
 * 
752
 * - vacations requests
753
 * - workday entiling recovery
754
 * - time saving account deposits
755
 *
756
 * Sorted by the most recent in first
757
 */
758
class absences_RequestIterator implements SeekableIterator, Countable 
759
{
760
761
	/**
762
	 * 
763
	 * @var array
764
	 */
765
	public $users;
766
	
767
	/**
768
	 * Filter by organization
769
	 * @var int
770
	 */
771
	public $organization;
772
	
773
	/**
774
	 * 
775
	 * @var array
776
	 */
777
	private $data;
778
	
779
	/**
780
	 * 
781
	 * @var int
782
	 */
783
	private $pos;
784
	
785
	
786
	/**
787
	 * Return only one entry per folder
788
	 * @var bool
789
	 */
790
	public $one_per_folder = false;
791
	
792
	
793
	/**
794
	 * Filtrer les demandes necessitant ou pas un email aux approbateurs
795
	 * @var int
796
	 */
797
	public $appr_notified;
798
	
799
	/**
800
	 * Filtrer les demandes avec unes instance d'approbation
801
	 * @var bool
802
	 */
803
	public $idfai_set;
804
	
805
	/**
806
	 * Filtrer les demandes par status
807
	 * @var string
808
	 */
809
	public $status;
810
	
811
	
812
	/**
813
	 * Search all request created before this date
814
	 * @var string
815
	 */
816
	public $createdOn;
817
	
818
	
819
	/**
820
	 * Search all request modified before this date
821
	 * @var string
822
	 */
823
	public $modifiedOn;
824
	
825
	/**
826
	 * Filtrer les demandes par annee
827
	 * @var int
828
	 */
829
	public $year;
830
	
831
	/**
832
	 * Filtrer les demandes par date de debut superieur
833
	 * @var string
834
	 */
835
	public $startFrom;
836
	
837
	/**
838
	 * Filtrer les demandes par date de debut inferieur
839
	 * @var string
840
	 */
841
	public $startTo;
842
	
843
	/**
844
	 * Filtrer les demandes par statut d'archivage
845
	 * @var int
846
	 */
847
	public $archived = 0;
848
	
849
	
850
	public function __construct($users = null)
851
	{
852
		$this->users = $users;
853
	}
854
	
855
	/**
856
	 * Get all requests in one array (not sorted)
857
	 * @return array
858
	 */
859
	public function getArray()
860
	{
861
		require_once dirname(__FILE__).'/entry.class.php';
862
		require_once dirname(__FILE__).'/workperiod_recover_request.class.php';
863
		require_once dirname(__FILE__).'/cet_deposit_request.class.php';
864
		
865
		
866
		$return = array();
867
		
868
		$entries = new absences_EntryIterator;
869
		$entries->users = $this->users;
870
		$entries->organization = $this->organization;
871
		$entries->appr_notified = $this->appr_notified;
872
		$entries->idfai_set = $this->idfai_set;
873
		$entries->status = $this->status;
874
		$entries->createdOn = $this->createdOn;
875
		$entries->modifiedOn = $this->modifiedOn;
876
		$entries->year = $this->year;
877
		$entries->archived = $this->archived;
878
		$entries->startFrom = $this->startFrom;
879
		$entries->startTo = $this->startTo;
880
		
881
		$folders = array();
882
		
883
		foreach($entries as $entry)
884
		{
885
			if ($this->one_per_folder && isset($entry->folder) && $entry->folder > 0)
886
			{
887
				if (isset($folders[$entry->folder]))
888
				{
889
					continue;
890
				}
891
				
892
				$folders[$entry->folder] = 1;
893
			}
894
			
895
			$return[] = $entry;
896
		}
897
		
898
		
899
		$cetdeposits = new absences_CetDepositRequestIterator;
900
		$cetdeposits->users = $this->users;
901
		$cetdeposits->organization = $this->organization;
902
		$cetdeposits->appr_notified = $this->appr_notified;
903
		$cetdeposits->idfai_set = $this->idfai_set;
904
		$cetdeposits->status = $this->status;
905
		$cetdeposits->createdOn = $this->createdOn;
906
		$cetdeposits->modifiedOn = $this->modifiedOn;
907
		$cetdeposits->year = $this->year;
908
		$cetdeposits->archived = $this->archived;
909
		$cetdeposits->startFrom = $this->startFrom;
910
		$cetdeposits->startTo = $this->startTo;
911
		
912
		foreach($cetdeposits as $deposit)
913
		{
914
			$return[] = $deposit;
915
		}
916
		
917
		$workperiods = new absences_WorkperiodRecoverRequestIterator;
918
		$workperiods->users = $this->users;
919
		$workperiods->organization = $this->organization;
920
		$workperiods->appr_notified = $this->appr_notified;
921
		$workperiods->idfai_set = $this->idfai_set;
922
		$workperiods->status = $this->status;
923
		$workperiods->createdOn = $this->createdOn;
924
		$workperiods->modifiedOn = $this->modifiedOn;
925
		$workperiods->year = $this->year;
926
		$workperiods->archived = $this->archived;
927
		$workperiods->startFrom = $this->startFrom;
0 ignored issues
show
Documentation Bug introduced by
The property $startFrom was declared of type integer, but $this->startFrom is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
928
		$workperiods->startTo = $this->startTo;
0 ignored issues
show
Documentation Bug introduced by
The property $startTo was declared of type integer, but $this->startTo is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
929
		
930
		foreach($workperiods as $recovery)
931
		{
932
			$return[] = $recovery;
933
		}
934
		
935
		return $return;
936
	}
937
	
938
	/**
939
	 * Get all requests in one array
940
	 * @return array
941
	 */
942
	public function getSortedArray()
943
	{
944
		$arr = $this->getArray();
945
		bab_Sort::sortObjects($arr, 'createdOn', bab_Sort::CASE_INSENSITIVE);
946
		
947
		$arr = array_reverse($arr);
948
		
949
		return array_values($arr);
950
	}
951
	
952
	
953
	/**
954
	 * 
955
	 * @return multitype:absences_Request
0 ignored issues
show
Documentation introduced by
The doc-type multitype:absences_Request could not be parsed: Unknown type name "multitype:absences_Request" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
956
	 */
957
	private function getData()
958
	{
959
		if (!isset($this->data))
960
		{
961
			$this->data = $this->getSortedArray();
962
		}
963
		
964
		return $this->data;
965
	}
966
	
967
	
968
	public function seek($position) {
969
		$this->pos = $position;
970
	}
971
	
972
	/**
973
	 * (non-PHPdoc)
974
	 * @see SeekableIterator::current()
975
	 * 
976
	 * @return absences_Request
977
	 */
978
	public function current() {
979
		$data = $this->getData();
980
		return $data[$this->pos];
981
	}
982
	
983
	public function next() {
984
		$this->pos++;
985
	}
986
	
987
	public function key() {
988
		return $this->pos;
989
	}
990
	
991
	public function valid() {
992
		$data = $this->getData();
993
		return isset($data[$this->pos]);
994
	}
995
	
996
	public function rewind() {
997
		$this->pos = 0;
998
	}
999
	
1000
	/**
1001
	 * (non-PHPdoc)
1002
	 * @see Countable::count()
1003
	 * 
1004
	 * @return int
1005
	 */
1006
	public function count() {
1007
		return count($this->getData());
1008
	}
1009
}
1010
1011
1012
1013
1014