Completed
Push — master ( 3daf50...de98bb )
by Paul
04:03
created

absences_Request::modifiedOn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
crap 2
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
	    if (isset($this->todelete) && $this->todelete) {
290
	        $this->addMovement(sprintf(absences_translate('The %s has been deleted with auto-approval'), $this->getTitle()));
291 4
	        $this->delete();
292
	        return false;
293 4
	    }
294
	    
295
	    
296
	    $this->onConfirm();
297 4
	    $this->addMovement(sprintf(absences_translate('The %s has been accepted with auto-approval'), $this->getTitle()));
298
	    return false;
299
	}
300
	
301
	
302
	
303 4
	private function getAutoApprovalUserId()
304 4
	{
305
	    if (!absences_getVacationOption('auto_approval')) {
306
	        return 0;
307 4
	    }
308
	    
309
	    return bab_getUserId();
310
	}
311
	
312
	
313
	
314
	/**
315
	 * Create approbation instance and set it "notified" but do not send email notification
316
	 * retourne TRUE si la demande est bien devenue en attente d'approbation
317
	 * @return bool
318
	 */
319 4
	public function createApprobationInstance()
320
	{
321
		require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
322
		
323
		if (isset($this->idfai) && $this->idfai > 0)
324
		{
325
			bab_WFDeleteInstance($this->idfai);
326
		}
327
		
328
		// si le 3eme parametre est passe avec l'id user en cours, cela active l'auto-approbation
329
		// l'auto-approbation a ete active a partir de la version 2.21 du module
330
		// 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)
331
		
332
		$idfai = bab_WFMakeInstance($this->getApprobationId(), get_class($this).':'.$this->id, $this->getAutoApprovalUserId(), $this->id_user);
333
		if (is_int($idfai))
334
		{
335
			$users = bab_WFGetWaitingApproversInstance($idfai, true);
336
			if (count($users) == 0)
337
			{
338
				$a = bab_WFGetApprobationInfos($this->getApprobationId());
339
				
340
				// l'instance n'a pas fonctionne
341
				bab_WFDeleteInstance($idfai);
342
				//TRANSLATORS: \n%1: request type (vacation request), \n%2: schema type (Staff schema), \n%3: schema name
343 4
				$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']));
344 4
				return $this->autoApproval();
345 4
			}
346
			
347 4
			if (isset($this->todelete) && $this->todelete) {
348 4
			    $this->addMovement(sprintf(absences_translate('The %s has been sent to deletion approval'), $this->getTitle()));
349 4
			} else {
350 4
			    $this->addMovement(sprintf(absences_translate('The %s has been sent for approval'), $this->getTitle()));
351
			}
352
			
353
		} else { // $idfai == TRUE : auto-approbation end schema
354
			return $this->autoApproval();
355
		}
356
		
357
		$this->idfai = $idfai;
358
		$this->status = '';
359
		$this->id_approver = 0;
360
		$this->appr_notified = 0;
361
		$this->comment2 = '';
362
		$this->save();
363
364
		return true;
365
	}
366
	
367
	
368
	/**
369
	 * Approbator confirm
370
	 * move to next approbator or close instance and set the request accepted
371
	 * 
372
	 * 
373
	 * @param	bool	$status				Accept or reject approbation step
374
	 * @param	string	$approver_comment	
375
	 * 
376
	 */
377
	public function approbationNext($status, $approver_comment)
378
	{
379
		require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
380
		$res = bab_WFUpdateInstance($this->idfai, bab_getUserId(), $status);
381
		
382
		switch ($res) {
383
			case 0:
384
				bab_WFDeleteInstance($this->idfai);
385
				$this->idfai = 0;
386
				if ($this->todelete) {
387
				    
388
				    // demande de suppression refusee
389
				    $this->status = 'Y';
390
				} else {
391
				    $this->status = 'N';
392
				}
393
				$this->onReject();
394
				break;
395
				
396
			case 1:
397
				bab_WFDeleteInstance($this->idfai);
398
				$this->idfai = 0;
399
				$this->status = 'Y';
400
				
401
				if (!$this->firstconfirm) {
402
				    $this->firstconfirm = 1;
403
				}
404
				
405
				if ($this->todelete) {
406
				    return $this->delete();
407
				}
408
				$this->onConfirm();
409
				break;
410
411
				
412
			default: // -1
413
				$nfusers = bab_WFGetWaitingApproversInstance($this->idfai, true);
414
				if (count($nfusers) > 0) {
415
					$this->appr_notified = 0;
416
				} else {
417
					// no approvers found or approvers allready notified (all user must confirm without order)
418
					// do nothing
419
				}
420
				
421
			break;
422
		}
423
424
		$this->id_approver = bab_getUserId();
425
		$this->comment2 = $approver_comment;
426
		$this->save();
427
		
428
		
429
		$str_status = $status ? absences_translate('accepted') :absences_translate('rejected');
430
		
431
		// movement must be saved after status modification to save the new status in movement
432
		$this->addMovement(
433
		    sprintf(absences_translate('The %s has been %s by %s'), $this->getTitle(), $str_status, bab_getUserName(bab_getUserId())),
434
		    $approver_comment
435
		);
436
		
437
	}
438
	
439
	
440
	
441
	/**
442
	 * Auto confirm the request
443
	 */
444
	public function autoConfirm()
445
	{
446
		$this->addMovement(
447
			sprintf(absences_translate('The %s has been confirmed automatically because of the validation timout'), $this->getTitle())
448
		);
449
		
450
		
451
		if ($this->idfai > 0)
452
		{
453
			require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
454
			bab_WFDeleteInstance($this->idfai);
455
		}
456
		
457
		$this->idfai = 0;
458
		$this->status = 'Y';
459
		$this->onConfirm();
460
		
461
		$this->id_approver = 0;
462
		$this->save();
463
		$this->notifyOwner();
464
	}
465
	
466
	
467
	
468
	/**
469
	 * Test if the logged in user can modify the entry
470
	 * @return bool
471
	 */
472
	public function canModify()
473
	{
474
	    $modify_waiting = (bool) absences_getVacationOption('modify_waiting');
475
	    $modify_confirmed = (bool) absences_getVacationOption('modify_confirmed');
476
	    
477
		require_once dirname(__FILE__).'/agent.class.php';
478
		$agent = absences_Agent::getCurrentUser();
479
	
480
		$personal = ($agent->isInPersonnel() && $agent->id_user === $this->id_user);
481
	
482
		switch($this->status)
483
		{
484
			case 'Y': // confirmed
485
			    if ($this->isFixed()) {
486
			        return false;
487
			    }
488
489
			    if ($modify_confirmed) {
490
			        return true;
491
			    }
492
			    
493
			    return !$personal; // ce n'est pas ma propre demande, je suis gestionnaire delegue
494
495
				
496
	
497
			case 'N': // rejected
498
				return false;
499
	
500
			case 'P': // previsional
501
				return $personal;
502
	
503
			default: // waiting
504
				return ($personal && $modify_waiting);
505
		}
506
	}
507
	
508
	
509
	/**
510
	 * Test if the user can delete the entry
511
	 * @return bool
512
	 */
513
	public function canDelete()
514
	{
515
		return $this->canModify();
516
	}
517
	
518
	
519
	
520
	
521
	
522
	/**
523
	 * Process specific code when the request is rejected
524
	 *
525
	 */
526
	abstract protected function onReject();
527
	
528
	/**
529
	 * Process specific code when the request is confirmed
530
	 */
531
	abstract protected function onConfirm();
532
533
	/**
534
	 * request title
535
	 * @return string
536
	 */
537
	abstract public function getTitle();
538
539
540
	
541
	/**
542
	 * Get a list of field to display in the notifications for this request
543
	 * @return array
544
	 */
545
	abstract public function getNotifyFields();
546
	
547
	
548
	/**
549
	 * annee de la demande
550
	 * @return int
551
	 */
552
	abstract public function getYear();
553
	
554
	
555
	/**
556
	 * annee de la demande, pour l'archivage par annee, tiens compte du parametrage du mois de debut de periode.
557
	 * Utilise dans l'archivage par annee
558
	 * @return int
559
	 */
560
	abstract public function getArchiveYear();
561
	
562
	
563
	abstract public function archive();
564
	
565
	
566
	/**
567
	 * approver has been notified
568
	 */
569
	abstract public function setNotified();
570
	
571
	
572
	/**
573
	 * Url to edit request as a manager
574
	 */
575
	abstract public function getManagerEditUrl();
576
	
577
	/**
578
	 * Url to delete request as a manager
579
	 */
580
	abstract public function getManagerDeleteUrl();
581
	
582
	
583
	/**
584
	 * Notify request next approvers
585
	 */
586
	public function notifyApprovers()
587
	{
588
		$defer = (bool) absences_getVacationOption('approb_email_defer');
589
		if (!$defer)
590
		{
591
			require_once dirname(__FILE__).'/request.notify.php';
592
			absences_notifyRequestApprovers();
593
		}
594
	}
595
	
596
	
597
	/**
598
	 * Notify request owner about the approval or reject of the request
599
	 */
600
	public function notifyOwner()
601
	{
602
		$appliquant_email = (bool) absences_getVacationOption('appliquant_email');
603
		
604
		if (!$appliquant_email)
605
		{
606
			return;
607
		}
608
		
609
		require_once dirname(__FILE__).'/request.notify.php';
610
		
611
		
612
		
613
		switch($this->status)
614
		{
615
			case 'N':
616
				$subject = sprintf(absences_translate("Your %s has been refused"), $this->getTitle());
617
				break;
618
				
619
			case 'Y':
620
				$subject = sprintf(absences_translate("Your %s has been accepted"), $this->getTitle());
621
				break;
622
				
623
			default: // next approver
624
				return;
625
		}
626
		
627
		absences_notifyRequestAuthor(array($this), $subject, $subject, $this->id_user);
628
	}
629
630
631
	/**
632
	 * Get request card frame to display in requests list
633
	 * @param bool 			$display_username	Affiche le nom du demandeur dans la card frame ou non, utile pour les listes contenant plusieurs demandeurs possibles
634
	 * @param int			$rfrom				si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue
635
 	 * @param int			$ide				id entite de l'organigramme >0 si gestionnaire delegue seulement
636
	 * @return Widget_Frame
637
	 */
638
	abstract public function getCardFrame($display_username, $rfrom, $ide);
639
640
	
641
	/**
642
	 * Get request frame to display in manager lists
643
	 * @return Widget_Frame
644
	 */
645
	abstract public function getManagerFrame();
646
	
647
648
	
649
	/**
650
	 * Delete request
651
	 */
652
	public function delete()
653
	{
654
		if ($this->idfai > 0)
655
		{
656
			require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
657
			bab_WFDeleteInstance($this->idfai);
658
		}
659
		
660
		global $babDB;
661
		$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));
662
	}
663
	
664
	
665
	
666
	/**
667
	 * @return absences_MovementIterator
668
	 */
669
	public function getMovementIterator()
670
	{
671
		require_once dirname(__FILE__).'/movement.class.php';
672
	
673
		$I = new absences_MovementIterator;
674
		$I->setRequest($this);
675
	
676
		return $I;
677
	}
678
	
679
	
680
	
681
	/**
682
	 *
683
	 * @param string $message	Generated message
684
	 * @param string $comment	Author comment
685
	 */
686 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...
687
	{
688 4
		require_once dirname(__FILE__).'/movement.class.php';
689
	
690 4
		$movement = new absences_Movement();
691 4
		$movement->message = $message;
692 4
		$movement->comment = $comment;
693 4
		$movement->setRequest($this);
694 4
		$movement->setAgent($this->getAgent());
695 4
		$movement->createdOn = $createdOn;
696 4
		$movement->save();
697 4
	}
698
	
699
	
700
	
701
	/**
702
	 * @return absences_Movement
703
	 */
704
	public function getLastMovement()
705
	{
706
		if (!isset($this->lastMovement))
707
		{
708
			$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...
709
			$I = $this->getMovementIterator();
710
			foreach($I as $movement)
711
			{
712
				$this->lastMovement = $movement;
713
				break;
714
			}
715
		}
716
		
717
		return $this->lastMovement;
718
	}
719
	
720
	
721
	/**
722
	 * Faut-il allerter l'approbateur que le delai d'approbation est depasse
723
	 * @return bool
724
	 */
725
	public function approbAlert()
726
	{
727
		$last = $this->getLastMovement();
728
		
729
		if (!$last)
730
		{
731
			return false;
732
		}
733
			
734
		$s = (time() - bab_mktime($last->createdOn));
735
		$d = ($s / 86400);
736
		
737
		$approb_alert = (int) absences_getVacationOption('approb_alert');
738
		
739
		if ($approb_alert > $d)
740
		{
741
			return false;
742
		}
743
		
744
		return true;
745
	}
746
}
747
748
749
750
751
752
753
754
755
756
/**
757
 * Get the list of request from the users, requests are :
758
 * 
759
 * - vacations requests
760
 * - workday entiling recovery
761
 * - time saving account deposits
762
 *
763
 * Sorted by the most recent in first
764
 */
765
class absences_RequestIterator implements SeekableIterator, Countable 
766
{
767
768
	/**
769
	 * 
770
	 * @var array
771
	 */
772
	public $users;
773
	
774
	/**
775
	 * Filter by organization
776
	 * @var int
777
	 */
778
	public $organization;
779
	
780
	/**
781
	 * 
782
	 * @var array
783
	 */
784
	private $data;
785
	
786
	/**
787
	 * 
788
	 * @var int
789
	 */
790
	private $pos;
791
	
792
	
793
	/**
794
	 * Return only one entry per folder
795
	 * @var bool
796
	 */
797
	public $one_per_folder = false;
798
	
799
	
800
	/**
801
	 * Filtrer les demandes necessitant ou pas un email aux approbateurs
802
	 * @var int
803
	 */
804
	public $appr_notified;
805
	
806
	/**
807
	 * Filtrer les demandes avec unes instance d'approbation
808
	 * @var bool
809
	 */
810
	public $idfai_set;
811
	
812
	/**
813
	 * Filtrer les demandes par status
814
	 * @var string
815
	 */
816
	public $status;
817
	
818
	
819
	/**
820
	 * Search all request created before this date
821
	 * @var string
822
	 */
823
	public $createdOn;
824
	
825
	
826
	/**
827
	 * Search all request modified before this date
828
	 * @var string
829
	 */
830
	public $modifiedOn;
831
	
832
	/**
833
	 * Filtrer les demandes par annee
834
	 * @var int
835
	 */
836
	public $year;
837
	
838
	/**
839
	 * Filtrer les demandes par date de debut superieur
840
	 * @var string
841
	 */
842
	public $startFrom;
843
	
844
	/**
845
	 * Filtrer les demandes par date de debut inferieur
846
	 * @var string
847
	 */
848
	public $startTo;
849
	
850
	/**
851
	 * Filtrer les demandes par statut d'archivage
852
	 * @var int
853
	 */
854
	public $archived = 0;
855
	
856
	
857
	public function __construct($users = null)
858
	{
859
		$this->users = $users;
860
	}
861
	
862
	/**
863
	 * Get all requests in one array (not sorted)
864
	 * @return array
865
	 */
866
	public function getArray()
867
	{
868
		require_once dirname(__FILE__).'/entry.class.php';
869
		require_once dirname(__FILE__).'/workperiod_recover_request.class.php';
870
		require_once dirname(__FILE__).'/cet_deposit_request.class.php';
871
		
872
		
873
		$return = array();
874
		
875
		$entries = new absences_EntryIterator;
876
		$entries->users = $this->users;
877
		$entries->organization = $this->organization;
878
		$entries->appr_notified = $this->appr_notified;
879
		$entries->idfai_set = $this->idfai_set;
880
		$entries->status = $this->status;
881
		$entries->createdOn = $this->createdOn;
882
		$entries->modifiedOn = $this->modifiedOn;
883
		$entries->year = $this->year;
884
		$entries->archived = $this->archived;
885
		$entries->startFrom = $this->startFrom;
886
		$entries->startTo = $this->startTo;
887
		
888
		$folders = array();
889
		
890
		foreach($entries as $entry)
891
		{
892
			if ($this->one_per_folder && isset($entry->folder) && $entry->folder > 0)
893
			{
894
				if (isset($folders[$entry->folder]))
895
				{
896
					continue;
897
				}
898
				
899
				$folders[$entry->folder] = 1;
900
			}
901
			
902
			$return[] = $entry;
903
		}
904
		
905
		
906
		$cetdeposits = new absences_CetDepositRequestIterator;
907
		$cetdeposits->users = $this->users;
908
		$cetdeposits->organization = $this->organization;
909
		$cetdeposits->appr_notified = $this->appr_notified;
910
		$cetdeposits->idfai_set = $this->idfai_set;
911
		$cetdeposits->status = $this->status;
912
		$cetdeposits->createdOn = $this->createdOn;
913
		$cetdeposits->modifiedOn = $this->modifiedOn;
914
		$cetdeposits->year = $this->year;
915
		$cetdeposits->archived = $this->archived;
916
		$cetdeposits->startFrom = $this->startFrom;
917
		$cetdeposits->startTo = $this->startTo;
918
		
919
		foreach($cetdeposits as $deposit)
920
		{
921
			$return[] = $deposit;
922
		}
923
		
924
		$workperiods = new absences_WorkperiodRecoverRequestIterator;
925
		$workperiods->users = $this->users;
926
		$workperiods->organization = $this->organization;
927
		$workperiods->appr_notified = $this->appr_notified;
928
		$workperiods->idfai_set = $this->idfai_set;
929
		$workperiods->status = $this->status;
930
		$workperiods->createdOn = $this->createdOn;
931
		$workperiods->modifiedOn = $this->modifiedOn;
932
		$workperiods->year = $this->year;
933
		$workperiods->archived = $this->archived;
934
		$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...
935
		$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...
936
		
937
		foreach($workperiods as $recovery)
938
		{
939
			$return[] = $recovery;
940
		}
941
		
942
		return $return;
943
	}
944
	
945
	/**
946
	 * Get all requests in one array
947
	 * @return array
948
	 */
949
	public function getSortedArray()
950
	{
951
		$arr = $this->getArray();
952
		bab_Sort::sortObjects($arr, 'createdOn', bab_Sort::CASE_INSENSITIVE);
953
		
954
		$arr = array_reverse($arr);
955
		
956
		return array_values($arr);
957
	}
958
	
959
	
960
	/**
961
	 * 
962
	 * @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...
963
	 */
964
	private function getData()
965
	{
966
		if (!isset($this->data))
967
		{
968
			$this->data = $this->getSortedArray();
969
		}
970
		
971
		return $this->data;
972
	}
973
	
974
	
975
	public function seek($position) {
976
		$this->pos = $position;
977
	}
978
	
979
	/**
980
	 * (non-PHPdoc)
981
	 * @see SeekableIterator::current()
982
	 * 
983
	 * @return absences_Request
984
	 */
985
	public function current() {
986
		$data = $this->getData();
987
		return $data[$this->pos];
988
	}
989
	
990
	public function next() {
991
		$this->pos++;
992
	}
993
	
994
	public function key() {
995
		return $this->pos;
996
	}
997
	
998
	public function valid() {
999
		$data = $this->getData();
1000
		return isset($data[$this->pos]);
1001
	}
1002
	
1003
	public function rewind() {
1004
		$this->pos = 0;
1005
	}
1006
	
1007
	/**
1008
	 * (non-PHPdoc)
1009
	 * @see Countable::count()
1010
	 * 
1011
	 * @return int
1012
	 */
1013
	public function count() {
1014
		return count($this->getData());
1015
	}
1016
}
1017
1018
1019
1020
1021