absences_RightEditor::by_request_date()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 9.4285
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__).'/base.ui.php';
26
27
28
bab_Widgets()->includePhpClass('Widget_Form');
29
30
31
class absences_RightBaseEditor extends Widget_Form
32
{
33
	
34
35
	
36
	
37
38
39
	
40
	
41
	
42
	/**
43
	 * Disponibilite en fonction de la date de saisie de la demande de conges
44
	 */
45
	protected function by_request_input_date()
46
	{
47
		$W = bab_Widgets();
48
		$period = $W->PeriodPicker()->setNames('date_begin_valid', 'date_end_valid');
49
	
50
		return $W->VBoxItems(
51
				$W->Label(absences_translate('The right is available if the request is in the period')),
52
				$period,
53
				$W->Label(absences_translate('if empty, the right will be available with others conditions'))
54
		)->setVerticalSpacing(1,'em');
55
	}
56
	
57
	
58
	
59
	/**
60
	 * CET saving period
61
	 */
62
	protected function saving()
63
	{
64
		$W = bab_Widgets();
65
		return $W->LabelledWidget(
66
				absences_translate('Saving period'),
67
				$W->PeriodPicker()->setNames('saving_begin', 'saving_end')
68
		);
69
	}
70
}
71
72
73
class absences_RightEditor extends absences_RightBaseEditor 
74
{
75
	/**
76
	 * 
77
	 * @var absences_Right
78
	 */
79
	protected $right;
80
	
81
	/**
82
	 * 
83
	 * @var Widget_VBoxLayout
84
	 */
85
	protected $fixed;
86
	
87
	/**
88
	 * 
89
	 * @var Widget_VBoxLayout
90
	 */
91
	protected $advanced_options;
92
	
93
	
94
	/**
95
     * @var Widget_VBoxLayout
96
	 */
97
	protected $no_distribution;
98
	
99
	/**
100
	 *
101
	 * @var Widget_VBoxLayout
102
	 */
103
	protected $availability_rules;
104
	
105
	
106
	/**
107
	 *
108
	 * @var Widget_VBoxLayout
109
	 */
110
	protected $test_other_types;
111
	
112
	
113
	/**
114
	 *
115
	 * @var Widget_VBoxLayout
116
	 */
117
	protected $cet;
118
	
119
	
120
	public function __construct(absences_Right $right = null)
121
	{
122
		$W = bab_Widgets();
123
		
124
		parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(1,'em'));
125
		
126
		$this->right = $right;
127
		
128
		$this->setName('right');
129
		$this->addClass('widget-bordered');
130
		$this->addClass('BabLoginMenuBackground');
131
		$this->addClass('widget-centered');
132
		$this->colon();
133
		
134
		$this->setCanvasOptions($this->Options()->width(70,'em'));
0 ignored issues
show
Bug introduced by
It seems like $this->Options()->width(70, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
135
		
136
		
137
		// init frames dynamically displayed
138
		
139
		$this->quantity = $this->quantity();
0 ignored issues
show
Bug introduced by
The property quantity does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
140
		$this->advanced_options = $W->FlowItems($this->cbalance(), $this->require_approval(), $this->use_in_cet())->setSpacing(1,'em', 4,'em');
0 ignored issues
show
Documentation Bug introduced by
It seems like $W->FlowItems($this->cba...acing(1, 'em', 4, 'em') of type object<Widget_FlowLayout> is incompatible with the declared type object<Widget_VBoxLayout> of property $advanced_options.

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...
141
		$this->no_distribution = $this->no_distribution();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->no_distribution() of type object<Widget_LabelledWidget> is incompatible with the declared type object<Widget_VBoxLayout> of property $no_distribution.

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...
142
		$this->availability_rules = $this->availability_rules();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->availability_rules() of type object<Widget_Accordions> is incompatible with the declared type object<Widget_VBoxLayout> of property $availability_rules.

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...
143
		$this->fixed = $this->fixed();
144
		$this->cet = $this->cet();
145
		$this->inc_month = $this->inc_month();
0 ignored issues
show
Bug introduced by
The property inc_month does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
146
		$this->report = $this->report();
0 ignored issues
show
Bug introduced by
The property report does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
147
		
148
		$this->test_other_types = $W->VBoxItems($this->alert(), $this->dynamic_configuration())->setVerticalSpacing(1,'em');
149
		
150
		$this->addFields();
151
		$this->loadFormValues();
152
		
153
		$this->addButtons();
154
		$this->setRightHiddenFields();
155
156
	}
157
	
158
	
159
	protected function setRightHiddenFields()
160
	{
161
	    $arr = array();
162
	    $this->getSelfPageHiddenFields($arr);
163
	    $this->setRightHiddenValues($arr);
164
	}
165
	
166
	
167
	protected function setRightHiddenValues($arr)
168
	{
169
	    foreach ($arr as $name => $value) {
170
	        $this->setHiddenValue($name, $value);
171
	    }
172
	}
173
	
174
	
175
	
176
	/**
177
	 * Updates the content of hiddenFields array with values from _GET and _POST matching the fields of the form $id.
178
	 *
179
	 * @param array $hiddenFields
180
	 */
181
	protected function getSelfPageHiddenFields(&$hiddenFields)
182
	{
183
	    $W = bab_Widgets();
184
	    $canvas = $W->HtmlCanvas();
185
	    $context = array_keys($_POST + $_GET);
186
	    $form = $this;
187
	     
188
	    $fnames = array();
189
	    
190
	    
191
	    foreach ($form->getFields() as $f) {
0 ignored issues
show
Bug introduced by
The expression $form->getFields() of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
192
	        $htmlname = $canvas->getHtmlName($f->getFullName());
193
	        if (!empty($htmlname)) {
194
	            $fnames[] = $htmlname;
195
	        }
196
	    }
197
	     
198
	    $context = array_diff($context, $fnames);
199
	     
200
	    foreach ($context as $fieldname) {
201
	        $value = bab_rp($fieldname);
202
	        if (!is_array($value) && !isset($hiddenFields[$fieldname])) {
203
	            $hiddenFields[$fieldname] = $value;
204
	        }
205
	    }
206
	}
207
	
208
	
209
	
210
	protected function addFields()
211
	{
212
		$W = bab_Widgets();
213
		
214
		$this->addItem($W->FlowItems($this->kind(), $this->active())->setHorizontalSpacing(3,'em')->setVerticalAlign('bottom'))
215
			->addItem($this->description())
216
			->addItem($this->theoretical_period())
217
			->addItem($W->FlowItems($this->id_type(), $this->id_rgroup())->setHorizontalSpacing(3,'em'))
218
			->addItem($this->quantity)
219
			->addItem($this->inc_month)
220
			->addItem($this->advanced_options)
221
			->addItem($this->no_distribution)
222
			
223
			->addItem($this->fixed)
224
			->addItem($this->cet)
225
			
226
			->addItem($this->availability_rules)
227
			->addItem($this->report)
228
			->addItem($this->test_other_types)
229
			
230
		;
231
	}
232
	
233
	
234
	protected function hide_empty()
235
	{
236
	    $W = bab_Widgets();
237
	    
238
	    return $W->LabelledWidget(
239
	        absences_translate('Hide the right when the quantity is 0 or negative'),
240
	        $W->CheckBox(),
241
	        __FUNCTION__
242
	    );
243
	}
244
	
245
	
246
	protected function setRightId()
247
	{
248
	    if (isset($this->right) && !empty($this->right->id))
249
	    {
250
	        $this->setHiddenValue('right[id]', $this->right->id);
251
	    }
252
	}
253
	
254
	
255
	
256
	protected function loadFormValues()
257
	{
258
		$this->setRightId();
259
		
260
		if (isset($_POST['right']))
261
		{
262
			$values = $_POST['right'];
263
		} else if (isset($this->right))
264
		{
265
			$values = $this->right->getRow();
266
			$rules = $this->right->getRightRule();
267
			if ($rules_values = $rules->getRow())
268
			{
269
				$values = array_merge($values, $rules_values);
270
			}
271
			
272
			$cet = $this->right->getRightCet();
273
			if ($cet_values = $cet->getRow())
274
			{
275
				$values = array_merge($values, $cet_values);
276
			}
277
			
278
			list($values['datebeginfx'], $values['hourbeginfx']) = explode(' ',$values['date_begin_fixed']);
279
			list($values['dateendfx'], $values['hourendfx']) = explode(' ',$values['date_end_fixed']);
280
			
281
			if (isset($values['min_use']))
282
			{
283
				$test_min_use = (int) round($values['min_use'] * 10);
284
				
285
				if (0 === $test_min_use)
286
				{
287
					$values['min_use_opt'] = 0;
288
				} else if ($test_min_use < 0) {
289
					$values['min_use_opt'] = -1;
290
				} else if ($test_min_use > 0) {
291
					$values['min_use_opt'] = 1;
292
				}
293
			}
294
			
295
			if ('0000-00-00' !== $values['date_end_report'])
296
			{
297
				$values['report'] = 1;
298
			}
299
			
300
			$values['quantity_alert_types'] = explode(',',$values['quantity_alert_types']);
301
			$values['dynconf_types'] = explode(',',$values['dynconf_types']);
302
			
303
		} else {
304
			$values = array(
305
				'active' => 'Y',	
306
				'id_type' => bab_rp('idtype'),
307
				'delay_before' => 0
308
			);
309
		}
310
311
		
312
		$this->setValues(array('right' => $values));
313
	}
314
	
315
	
316 View Code Duplication
	protected function addButtons()
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...
317
	{
318
		$W = bab_Widgets();
319
		
320
		$button = $W->FlowItems(
321
			$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')),
322
			$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))
323
		)->setSpacing(1,'em');
324
		
325
		if (isset($this->right))
326
		{
327
			$button->addItem(
328
				$W->SubmitButton()
329
					->setConfirmationMessage(absences_translate('Do you really want to delete the vacation right?'))
330
					->setName('delete')->setLabel(absences_translate('Delete'))
331
			);
332
		}
333
		
334
		$this->addItem($button);
335
	}
336
	
337
	
338
	
339 View Code Duplication
	protected function description()
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...
340
	{
341
		$W = bab_Widgets();
342
		
343
		return $W->LabelledWidget(
344
				absences_translate('Right name'),
345
				$W->LineEdit()->setSize(60)->setMaxSize(255)->setMandatory(true, absences_translate('The name is mandatory')),
346
				__FUNCTION__
347
		);
348
	}
349
	
350
	
351
	protected function kind()
352
	{
353
		$W = bab_Widgets();
354
		
355
		$select = $W->Select()->setOptions(absences_kinds());
356
		
357
		$select->setAssociatedDisplayable($this->quantity, array(absences_Right::REGULAR, absences_Right::INCREMENT, absences_Right::FIXED, absences_Right::RECOVERY));
358
		$select->setAssociatedDisplayable($this->advanced_options, array(absences_Right::REGULAR, absences_Right::INCREMENT));
359
		$select->setAssociatedDisplayable($this->no_distribution, array(absences_Right::REGULAR, absences_Right::CET, absences_Right::INCREMENT));
360
		$select->setAssociatedDisplayable($this->availability_rules, array(absences_Right::REGULAR, absences_Right::CET, absences_Right::INCREMENT, absences_Right::RECOVERY));
361
		$select->setAssociatedDisplayable($this->fixed, array(absences_Right::FIXED));
362
		$select->setAssociatedDisplayable($this->cet, array(absences_Right::CET));
363
		$select->setAssociatedDisplayable($this->inc_month, array(absences_Right::INCREMENT));
364
		$select->setAssociatedDisplayable($this->report, array(absences_Right::REGULAR, absences_Right::INCREMENT));
365
		$select->setAssociatedDisplayable($this->test_other_types, array(absences_Right::REGULAR, absences_Right::INCREMENT, absences_Right::RECOVERY));
366
		return $W->LabelledWidget(
367
				absences_translate('Right kind'),
368
				$select,
369
				__FUNCTION__
370
		);
371
	}
372
	
373
	
374
	/**
375
	 * quantity & quantity_unit
376
	 * @return Widget_FlowLayout
377
	 */
378
	protected function quantity()
379
	{
380
		$W = bab_Widgets();
381
	
382
		$lineedit = $W->LineEdit()->setSize(5)->setMaxSize(5)->setMandatory(true, absences_translate('The quantity is mandatory'))->setName('quantity');
383
		$select = $W->Select()->setName('quantity_unit')
384
    		->addOption('D', absences_translate('Day(s)'))
385
    		->addOption('H', absences_translate('Hour(s)'));
386
	
387
		$vbox = $W->VBoxItems(
388
				$W->Label(absences_translate('Quantity'))->setAssociatedWidget($lineedit),
389
				$W->FlowItems($lineedit, $select)
390
		)->setVerticalSpacing(.2,'em');
391
		
392
		if (isset($this->right) && absences_Right::INCREMENT === $this->right->getKind()) {
393
    		$monthlyUpdates = $W->FlowItems(
394
    		    $W->Label(absences_translate('Additional quantity by monthly updates'))->colon(),
395
    		    $W->Label('+'.absences_quantity($this->right->getIncrementQuantity(), $this->right->quantity_unit))
396
    		)->setSpacing(.5, 'em');
397
    		
398
    		$vbox->addItem($monthlyUpdates);
399
		}
400
		
401
		return $vbox;
402
	}
403
	
404
	
405 View Code Duplication
	private function type_select($empty = false)
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...
406
	{
407
		$W = bab_Widgets();
408
		global $babDB;
409
		
410
		$select = $W->Select();
411
		
412
		if ($empty)
413
		{
414
			$select->addOption('0', '');
415
		}
416
		
417
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
418
		while ($arr = $babDB->db_fetch_assoc($res))
419
		{
420
			$select->addOption($arr['id'], $arr['name']);
421
		}
422
		
423
		return $select;
424
	}
425
	
426
	
427
	private function multiType()
428
	{
429
		$W = bab_Widgets();
430
		global $babDB;
431
	
432
		$select = $W->Multiselect();
433
434
	
435
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
436
		while ($arr = $babDB->db_fetch_assoc($res))
437
		{
438
			$select->addOption($arr['id'], $arr['name']);
439
		}
440
	
441
		return $select;
442
	}
443
	
444
	
445
	
446
	
447
	/**
448
	 * 
449
	 * @return Widget_LabelledWidget
450
	 */
451
	protected function id_type()
452
	{
453
		$W = bab_Widgets();
454
455
		return $W->LabelledWidget(
456
			absences_translate('Right type'),
457
			$this->type_select(),
458
			__FUNCTION__
459
		);
460
	}
461
	
462
	
463
	
464
	/**
465
	 *
466
	 * @return Widget_LabelledWidget
467
	 */
468
	protected function id_report_type()
469
	{
470
		$W = bab_Widgets();
471
		
472
		return $W->LabelledWidget(
473
				absences_translate('Type for report rights'),
474
				$this->type_select(true),
475
				__FUNCTION__
476
		);
477
	}
478
	
479
	
480
	/**
481
	 *
482
	 * @return Widget_LabelledWidget
483
	 */
484
	protected function date_end_report()
485
	{
486
		$W = bab_Widgets();
487
		
488
		return $W->LabelledWidget(
489
				absences_translate('Report availability end'),
490
				$W->DatePicker(),
491
				__FUNCTION__
492
		);
493
	}
494
	
495
	
496
	protected function description_report()
497
	{
498
		$W = bab_Widgets();
499
	
500
		return $W->LabelledWidget(
501
				absences_translate('Report right name'),
502
				$W->LineEdit()->setSize(60)->setMaxSize(255),
503
				__FUNCTION__
504
		);
505
	}
506
	
507
	
508
	
509
	protected function report()
510
	{
511
		$W = bab_Widgets();
512
		
513
		$layout = $W->VBoxLayout()->setVerticalSpacing(1,'em');
514
		$morefields = $W->FlowItems(
515
			$this->description_report(),
516
			$this->id_report_type(), 
517
			$this->date_end_report(),
518
			$W->Icon(absences_translate('The report will be created if the end date of right visibility is in the past and if there is unused quantity left'), Func_Icons::STATUS_DIALOG_QUESTION)
519
		)->setSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
520
		
521
		$report = $W->LabelledWidget(
522
				absences_translate('Create a report for lasting right after the expiry'),
523
				$W->CheckBox()->setAssociatedDisplayable($morefields, array('1')),
524
				__FUNCTION__
525
		);
526
		
527
		$layout->addItem($report);
528
		$layout->addItem($morefields);
529
		
530
		return $layout;
531
	}
532
	
533
	
534
	
535
	
536
	protected function alert()
537
	{
538
		$W = bab_Widgets();
539
		
540
		$quantity_alert_days = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('quantity_alert_days');
541
		$quantity_alert_types = $this->multiType()->setName('quantity_alert_types');
542
		$period = $W->PeriodPicker()->setNames('quantity_alert_begin', 'quantity_alert_end');
543
		
544
		$flow = $W->FlowItems(
545
			$W->Label(absences_translate('Alert if the user has consumed more than')), 
546
			$quantity_alert_days, 
547
			$W->Label(absences_translate('days of')), 
548
			$quantity_alert_types
549
		)->setSpacing(.2,'em');
550
		
551
		$morefields = $W->VBoxItems(
552
			$flow,
553
			$W->VBoxItems($W->Label(absences_translate('Among the absences within the period'))->setAssociatedWidget($period), $period)->setVerticalSpacing(.5,'em')
554
		)->setVerticalSpacing(1,'em');
555
		
556
		return $W->Section(absences_translate('Alerting depending on the consumed quantity'), $morefields, 6)->setFoldable(true, true);
557
	}
558
	
559
	
560
	
561
	private function createDuplicableDynconf($index, absences_DynamicConfiguration $dynconf = null)
562
	{
563
		$W = bab_Widgets();
564
		$duplicable = $W->Frame(null, $W->FlowLayout()->setSpacing(.5,'em'))->setName(array('dynconf', (string) $index));
565
	
566
		$select = $W->Select()
567
			->addOption('-', absences_translate('Remove'))
568
			->addOption('+', absences_translate('Add'))
569
			->setName('sign');
570
	
571
		$test_quantity = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('test_quantity');
572
		$quantity = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('quantity');
573
		
574
		if (isset($dynconf))
575
		{
576
			// the edit quantity unit is not known here
577
			$quantity->setValue(absences_editQuantity(abs((float) $dynconf->quantity)));
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<absences_DynamicConfiguration>. 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...
578
			if ($dynconf->quantity > 0)
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<absences_DynamicConfiguration>. 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...
579
			{
580
				$select->setValue('+');
581
			} else {
582
				$select->setValue('-');
583
			}
584
			
585
			$test_quantity->setValue(absences_editQuantity($dynconf->test_quantity));
0 ignored issues
show
Documentation introduced by
The property test_quantity does not exist on object<absences_DynamicConfiguration>. 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...
586
		}
587
		
588
		$duplicable->addItem($W->Label(absences_translate('If quantity taken is beyond')));
589
		$duplicable->addItem($test_quantity);
590
		$duplicable->addItem($W->Label(absences_translate('day(s), ')));
591
		$duplicable->addItem($select)->addItem($quantity);
592
		$duplicable->addItem($W->Button()->addItem($W->Icon('', Func_Icons::ACTIONS_LIST_REMOVE)));
593
	
594
		return $duplicable;
595
	}
596
	
597
	
598
	/**
599
	 *
600
	 * @param Widget_VBoxLayout $list
601
	 * @return bool
602
	 */
603
	private function addDuplicableDynconfToList($list)
604
	{
605
		if (!isset($this->right))
606
		{
607
			return false;
608
		}
609
	
610
		global $babDB;
611
	
612
		$res = $this->right->getDynamicConfigurationIterator();
613
	
614
		if (!$res->count())
615
		{
616
			return false;
617
		}
618
	
619
		$index = 0;
620
		foreach ($res as $dynconf)
621
		{
622
			$dupli = $this->createDuplicableDynconf($index++, $dynconf);
623
			$list->addItem($dupli);
624
		}
625
	
626
	
627
		return true;
628
	}
629
	
630
	
631
	
632
	protected function dynamic_configuration()
633
	{
634
		$W = bab_Widgets();
635
		
636
		
637
		
638
		$quantity_alert_types = $this->multiType()->setName('dynconf_types');
639
		$period = $W->PeriodPicker()->setNames('dynconf_begin', 'dynconf_end');
640
		
641
		$comoncriteria = $W->FlowItems(
642
				$W->Label(absences_translate('Test days of type')),
643
				$quantity_alert_types,
644
				$W->VBoxItems($W->Label(absences_translate('Among the absences within the period'))->setAssociatedWidget($period), $period)->setVerticalSpacing(.5,'em')
645
		)->setSpacing(1,'em')->setVerticalAlign('middle');
646
	
647
		
648
		
649
		$list = $W->VBoxLayout('absences_dynconf_rows');
650
		
651
		if (!$this->addDuplicableDynconfToList($list))
652
		{
653
			$list->addItem($this->createDuplicableDynconf(0));
654
		}
655
656
		$morefields = $W->VBoxItems(
657
			$comoncriteria,
658
			$W->VBoxItems(
659
				$list,
660
				$W->Button('absences_dynconf_add')->addItem($W->Icon(absences_translate('Add a test'), Func_Icons::ACTIONS_LIST_ADD))
661
			)->addClass('widget-bordered'),
662
			$W->Icon(absences_translate('The added or removed quantity is in the same unit as the vacation right'), Func_Icons::STATUS_DIALOG_INFORMATION)
663
		)->setVerticalSpacing(.5,'em');
664
		
665
		
666
		
667
		return $W->Section(absences_translate('Change available quantity depending on the consumed quantity'), $morefields, 6)->setFoldable(true, true)->addClass(Func_Icons::ICON_LEFT_16);
668
		
669
		
670
	}
671
	
672
	
673
	
674
	
675
	/**
676
	 * Right group
677
	 * @return Widget_LabelledWidget
678
	 */
679 View Code Duplication
	protected function id_rgroup()
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
		$W = bab_Widgets();
682
		global $babDB;
683
	
684
		$select = $W->Select();
685
		$select->addOption(0, absences_translate('None'));
686
	
687
		$res = $babDB->db_query('SELECT id, name FROM absences_rgroup ORDER BY name');
688
		while ($arr = $babDB->db_fetch_assoc($res))
689
		{
690
			$select->addOption($arr['id'], $arr['name']);
691
		}
692
	
693
		return $W->LabelledWidget(
694
				absences_translate('Right group'),
695
				$select,
696
				__FUNCTION__
697
		);
698
	}
699
	
700
	
701
	
702
	/**
703
	 * Periode theorique du droit
704
	 */
705
	protected function theoretical_period()
706
	{
707
		$W = bab_Widgets();
708
		
709
		return $W->LabelledWidget(
710
			absences_translate('Right theoretical period'),
711
			$W->PeriodPicker()->setNames('date_begin', 'date_end')
712
		);
713
	}
714
715
	
716
	
717
	/**
718
	 * 
719
	 */
720
	protected function active()
721
	{
722
		$W = bab_Widgets();
723
		
724
		/*
725
		return $W->LabelledWidget(
726
			absences_translate('Active'),
727
			$W->Checkbox()->setCheckedValue('Y')->setUncheckedValue('N'),
728
			__FUNCTION__
729
		);
730
		*/
731
		return $W->LabelledWidget(
732
				absences_translate('Active'),
733
				$W->Select()->setOptions(array(
734
						'Y' => absences_translate('Yes, usable by appliquant'),
735
						'N' => absences_translate('No, only for managers or delegated managers')
736
				)),
737
				__FUNCTION__
738
		);
739
	}
740
	
741
	
742
	
743
	/**
744
	 * 
745
	 */
746 View Code Duplication
	protected function cbalance()
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...
747
	{
748
		$W = bab_Widgets();
749
		return $W->LabelledWidget(
750
				absences_translate('Accept negative balance'),
751
				$W->Select()->setOptions(array(
752
					'Y' => absences_translate('Yes'),
753
					'N' => absences_translate('No')
754
				)),
755
				__FUNCTION__
756
		);
757
	}
758
	
759
	/**
760
	 *
761
	 */
762 View Code Duplication
	protected function no_distribution()
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...
763
	{
764
		$W = bab_Widgets();
765
		return $W->LabelledWidget(
766
				absences_translate('Distribution on request'),
767
				$W->Select()->setOptions(array(
768
					'0' => absences_translate('Yes'),
769
					'1' => absences_translate('No')
770
				)),
771
				__FUNCTION__
772
		);
773
	}
774
	
775
	
776
	/**
777
	 *
778
	 */
779
	protected function use_in_cet()
780
	{
781
		$W = bab_Widgets();
782
		
783
		$cet_quantity = $W->Frame();
784
		$cet_quantity->addItem($this->cet_quantity());
785
		
786
		$use_in_cet = $W->LabelledWidget(
787
				absences_translate('Allow moving to the time savings account'),
788
				$W->Select()->setOptions(array(
789
						'1' => absences_translate('Yes'),
790
						'0' => absences_translate('No')
791
				))->setAssociatedDisplayable($cet_quantity, array('1')),
792
				__FUNCTION__
793
		);
794
		
795
		
796
		return $W->HBoxItems($use_in_cet, $cet_quantity)->setHorizontalSpacing(3,'em');
797
		
798
	}
799
	
800
	
801
	/**
802
	 *
803
	 */
804
	protected function cet_quantity()
805
	{
806
		$W = bab_Widgets();
807
		return $W->LabelledWidget(
808
				absences_translate('Saving quantity'),
809
				$W->LineEdit()->setSize(6),
810
				__FUNCTION__,
811
				absences_translate('in the same unit as right quantity')
812
		);
813
	}
814
	
815
	
816 View Code Duplication
	protected function require_approval()
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...
817
	{
818
		$W = bab_Widgets();
819
		return $W->LabelledWidget(
820
				absences_translate('Require approval'),
821
				$W->Select()->setOptions(array(
822
						'1' => absences_translate('Yes'),
823
						'0' => absences_translate('No')
824
				)),
825
				__FUNCTION__
826
		);
827
	}
828
	
829
	
830
	/**
831
	 * Interface for FIXED right
832
	 * @return Widget_VBoxLayout
833
	 */
834 View Code Duplication
	protected function fixed()
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...
835
	{
836
		$W = bab_Widgets();
837
		
838
		return $W->VBoxItems(
839
			$W->Label(absences_translate('This vacation period will be set for all right beneficiaries')),
840
			$W->FlowItems($this->beginfx(), $this->endfx())	
841
		)->setVerticalSpacing(1,'em');
842
	}
843
	
844
	
845
	
846
	
847 View Code Duplication
	protected function beginfx()
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...
848
	{
849
		$W = bab_Widgets();
850
		$date = $W->DatePicker()->setMandatory(true)->setName('datebeginfx');
851
		$hours = $W->Select()->setName('hourbeginfx')->setOptions(absences_hoursList());
852
		
853
		return $W->FlowItems(
854
			$W->Label(absences_translate('from date'))->setAssociatedWidget($date),
855
			$date,
856
			$hours
857
		)->setSpacing(.5,'em');
858
	}
859
	
860
	
861 View Code Duplication
	protected function endfx()
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...
862
	{
863
		$W = bab_Widgets();
864
		$date = $W->DatePicker()->setMandatory(true)->setName('dateendfx');
865
		$hours = $W->Select()->setName('hourendfx')->setOptions(absences_hoursList());
866
		
867
		return $W->FlowItems(
868
			$W->Label(absences_translate('to date'))->setAssociatedWidget($date),
869
			$date,
870
			$hours
871
		)->setSpacing(.5,'em');
872
	}
873
	
874
	
875
	protected function inc_month()
876
	{
877
		$W = bab_Widgets();
878
		
879
		return $W->VBoxItems(
880
				$this->quantity_inc_month(),
881
				$this->quantity_inc_max()
882
		)->setVerticalSpacing(1,'em');
883
	}
884
	
885
	
886 View Code Duplication
	protected function quantity_inc_month()
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...
887
	{
888
		$W = bab_Widgets();
889
		return $W->LabelledWidget(
890
				absences_translate('Quantity to add each month'),
891
				$W->LineEdit()->setSize(6)->setMaxSize(10)->setMandatory(true, absences_translate('The quantity per month is mandatory')),
892
				__FUNCTION__,
893
				absences_translate('The quantity will grow each month before the end date from "Availability depends on the requested period dates"')
894
		);
895
	}
896
	
897
	
898 View Code Duplication
	protected function quantity_inc_max()
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...
899
	{
900
		$W = bab_Widgets();
901
		return $W->LabelledWidget(
902
				absences_translate('Maximum quantity'),
903
				$W->LineEdit()->setSize(6)->setMaxSize(10),
904
				__FUNCTION__,
905
				absences_translate('The quantity will grow each month up to this limit')
906
		);
907
	}
908
	
909
	
910
	/**
911
	 * parametres specifiques pour les CET
912
	 */
913
	protected function cet()
914
	{
915
		$W = bab_Widgets();
916
		
917
		return $W->VBoxItems(
918
			$this->saving(),
919
			$this->per_year(),
920
		//	$this->per_cet(), TODO comment ce critere peut-il fonctionner ? cela devrait etre un plafont par utilisateur en plus pour ne pas faire doublon avec le plafont du CET configure au niveau du droit
921
			$this->ceiling(),
922
			$this->min_use()
923
		)->setVerticalSpacing(1,'em');
924
	}
925
	
926
	
927
	
928
929
	
930
	
931
	/**
932
	 * CET max days saving per years
933
	 */
934 View Code Duplication
	protected function per_year()
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...
935
	{
936
		$W = bab_Widgets();
937
		return $W->LabelledWidget(
938
				absences_translate('Maximum savings per year'),
939
				$W->LineEdit()->setSize(6)->setMaxSize(10),
940
				__FUNCTION__,
941
				null,
942
				absences_translate('day(s)')
943
		);
944
	}
945
	
946
	
947
	/**
948
	 * CET max days saving for CET period
949
	 */
950 View Code Duplication
	protected function per_cet()
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...
951
	{
952
		$W = bab_Widgets();
953
		return $W->LabelledWidget(
954
				absences_translate('Maximum savings for the account saving time period'),
955
				$W->LineEdit()->setSize(6)->setMaxSize(10),
956
				__FUNCTION__,
957
				null,
958
				absences_translate('day(s)')
959
		);
960
	}
961
	
962
	
963
	/**
964
	 * CET ceiling
965
	 */
966 View Code Duplication
	protected function ceiling()
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...
967
	{
968
		$W = bab_Widgets();
969
		return $W->LabelledWidget(
970
				absences_translate('Maximum savings in the account saving time'),
971
				$W->LineEdit()->setSize(6)->setMaxSize(10),
972
				__FUNCTION__,
973
				null,
974
				absences_translate('day(s)')
975
		);
976
	}
977
	
978
	
979
	
980
	/**
981
	 * CET minimal use
982
	 */
983
	protected function min_use()
984
	{
985
		$W = bab_Widgets();
986
		
987
		$select = $W->Select()
988
			->addOption('0', absences_translate('No constraint'))
989
			->addOption('-1', absences_translate('Force the use of the total in one take'))
990
			->addOption('1', absences_translate('Set the minimum to use in one take'));
991
		
992
		
993
		$options = $W->LabelledWidget(
994
				absences_translate('Constraint when using the account'),
995
				$select,
996
				'min_use_opt'
997
		);
998
		
999
		$min_use = $W->LabelledWidget(
1000
				absences_translate('Minimum allowed'),
1001
				$W->LineEdit()->setSize(6)->setMaxSize(10),
1002
				__FUNCTION__,
1003
				null,
1004
				absences_translate('day(s)')
1005
		);
1006
		
1007
		
1008
		$displayable = $W->Frame()->addItem($min_use);
1009
		
1010
		
1011
		$select->setAssociatedDisplayable($displayable, array('1'));
1012
		
1013
		
1014
		return $W->HBoxItems($options, $displayable)->setHorizontalSpacing(3,'em');
1015
	}
1016
	
1017
	
1018
	
1019
	
1020
	/**
1021
	 * Criteres de disponibilite d'un droit
1022
	 */
1023
	protected function availability_rules()
1024
	{
1025
		$W = bab_Widgets();
1026
		
1027
		
1028
	
1029
		return $W->Accordions()
1030
			->addPanel(absences_translate('Availability depends on the date of the vacation request input'), $this->by_request_input_date())
1031
			->addPanel(absences_translate('Availability depends on the requested period dates'), $this->by_requested_period())
1032
			->addPanel(absences_translate('Right assignement in function of requested days'), $this->by_confirmed_quantity())
1033
			->addPanel(absences_translate('Availability depends on an earlier date'), $this->by_earlier_date())
1034
			->addPanel(absences_translate('Availability depends on an later date'), $this->by_later_date())
1035
			->addPanel(absences_translate('Availability depends on the interval between the requested period dates and the current date'), $this->by_request_date())
1036
		;
1037
	}
1038
	
1039
	
1040
	
1041
	
1042
	
1043
	private function createDuplicable($index, $values = null)
1044
	{
1045
		$W = bab_Widgets();
1046
		$duplicable = $W->Frame(null, $W->FlowLayout()->setSpacing(.5,'em'))->setName(array('inperiod', (string) $index));
1047
		
1048
		$select = $W->Select()
1049
		->addOption(1, absences_translate('In rule period'))
1050
		->addOption(2, absences_translate('Out of rule period'))
1051
		->setName('right_inperiod');
1052
		
1053
		
1054
		
1055
		$periodPicker = $W->PeriodPicker()->setNames('period_start', 'period_end');
1056
		
1057
		if (isset($values))
1058
		{
1059
			$select->setValue($values['right_inperiod']);
1060
			$periodPicker->setValues($values['period_start'], $values['period_end']);
1061
		}
1062
		
1063
		$duplicable->addItem($select);
1064
		$duplicable->addItem($W->Label(absences_translate('in this period'))->colon());
1065
		$duplicable->addItem($periodPicker);
1066
		$duplicable->addItem($W->Button()->addItem($W->Icon('', Func_Icons::ACTIONS_LIST_REMOVE)));
1067
		
1068
		return $duplicable;
1069
	}
1070
	
1071
	
1072
	/**
1073
	 * 
1074
	 * @param Widget_VBoxLayout $list
1075
	 * @return bool
1076
	 */
1077
	private function addDuplicableToList($list)
1078
	{
1079
		if (!isset($this->right))
1080
		{
1081
			return false;
1082
		}
1083
		
1084
		global $babDB;
1085
		
1086
		$res = $this->right->getRightRule()->getInPeriodRes();
1087
		
1088
		if (!$res || 0 === $babDB->db_num_rows($res))
1089
		{
1090
			return false;
1091
		}
1092
		
1093
		$index = 0;
1094
		while ($arr = $babDB->db_fetch_assoc($res))
1095
		{
1096
			$dupli = $this->createDuplicable($index++, $arr);
1097
			$list->addItem($dupli);
1098
		}
1099
		
1100
		
1101
		return true;
1102
	}
1103
	
1104
	
1105
	
1106
	/**
1107
	 * Disponibilite en fonction de la periode de conges demandee
1108
	 * @return Widget_VBoxLayout
1109
	 */
1110
	protected function by_requested_period()
1111
	{
1112
		$W = bab_Widgets();
1113
		bab_functionality::includefile('Icons');
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class bab_functionality as the method includefile() does only exist in the following sub-classes of bab_functionality: Func_Archive, Func_Archive_Zip, Func_Archive_Zip_ZipArchive, Func_Archive_Zip_Zlib, Func_CalendarBackend, Func_CalendarBackend_Ovi, Func_ContextActions, Func_ContextActions_Article, Func_ContextActions_ArticleTopic, Func_Home, Func_Home_Ovidentia, Func_Icons, Func_Icons_Default, Func_Ovml, Func_Ovml_Container, Func_Ovml_Container_Addon, Func_Ovml_Container_Article, Func_Ovml_Container_ArticleCategories, Func_Ovml_Container_ArticleCategory, Func_Ovml_Container_ArticleCategoryNext, Func_Ovml_Container_ArticleCategoryPrevious, Func_Ovml_Container_ArticleFiles, Func_Ovml_Container_ArticleNext, Func_Ovml_Container_ArticlePrevious, Func_Ovml_Container_ArticleTopic, Func_Ovml_Container_ArticleTopicNext, Func_Ovml_Container_ArticleTopicPrevious, Func_Ovml_Container_ArticleTopics, Func_Ovml_Container_Articles, Func_Ovml_Container_ArticlesHomePages, Func_Ovml_Container_CalendarCategories, Func_Ovml_Container_CalendarEventDomains, Func_Ovml_Container_CalendarEvents, Func_Ovml_Container_CalendarGroupEvents, Func_Ovml_Container_CalendarResourceEvents, Func_Ovml_Container_CalendarUserEvents, Func_Ovml_Container_Calendars, Func_Ovml_Container_DbDirectories, Func_Ovml_Container_DbDirectory, Func_Ovml_Container_DbDirectoryAcl, Func_Ovml_Container_DbDirectoryEntry, Func_Ovml_Container_DbDirectoryEntryFields, Func_Ovml_Container_DbDirectoryFields, Func_Ovml_Container_DbDirectoryMemberFields, Func_Ovml_Container_DbDirectoryMembers, Func_Ovml_Container_Delegation, Func_Ovml_Container_DelegationAdministrators, Func_Ovml_Container_DelegationItems, Func_Ovml_Container_DelegationManaged, Func_Ovml_Container_Delegations, Func_Ovml_Container_DelegationsCategories, Func_Ovml_Container_DelegationsCategory, Func_Ovml_Container_DelegationsManaged, Func_Ovml_Container_Faq, Func_Ovml_Container_FaqNext, Func_Ovml_Container_FaqPrevious, Func_Ovml_Container_FaqQuestion, Func_Ovml_Container_FaqQuestionNext, Func_Ovml_Container_FaqQuestionPrevious, Func_Ovml_Container_FaqQuestions, Func_Ovml_Container_FaqSubCategories, Func_Ovml_Container_FaqSubCategory, Func_Ovml_Container_Faqs, Func_Ovml_Container_File, Func_Ovml_Container_FileFields, Func_Ovml_Container_FileNext, Func_Ovml_Container_FilePrevious, Func_Ovml_Container_Files, Func_Ovml_Container_Folder, Func_Ovml_Container_FolderNext, Func_Ovml_Container_FolderPrevious, Func_Ovml_Container_Folders, Func_Ovml_Container_Forum, Func_Ovml_Container_ForumNext, Func_Ovml_Container_ForumPrevious, Func_Ovml_Container_Forums, Func_Ovml_Container_IfEqual, Func_Ovml_Container_IfGreaterThan, Func_Ovml_Container_IfGreaterThanOrEqual, Func_Ovml_Container_IfIsSet, Func_Ovml_Container_IfLessThan, Func_Ovml_Container_IfLessThanOrEqual, Func_Ovml_Container_IfNotEqual, Func_Ovml_Container_IfNotIsSet, Func_Ovml_Container_IfUserMemberOfGroups, Func_Ovml_Container_Multipages, Func_Ovml_Container_ObjectsInfo, Func_Ovml_Container_OrgPathToEntity, Func_Ovml_Container_OrgUserEntities, Func_Ovml_Container_OvmlArray, Func_Ovml_Container_OvmlArrayFields, Func_Ovml_Container_OvmlSoap, Func_Ovml_Container_ParentsArticleCategory, Func_Ovml_Container_Post, Func_Ovml_Container_PostFiles, Func_Ovml_Container_RecentArticles, Func_Ovml_Container_RecentComments, Func_Ovml_Container_RecentFaqQuestions, Func_Ovml_Container_RecentFiles, Func_Ovml_Container_RecentPosts, Func_Ovml_Container_RecentThreads, Func_Ovml_Container_SitemapCustomNode, Func_Ovml_Container_SitemapEntries, Func_Ovml_Container_SitemapEntry, Func_Ovml_Container_SitemapPath, Func_Ovml_Container_Soap, Func_Ovml_Container_SubFolders, Func_Ovml_Container_Tags, Func_Ovml_Container_Thread, Func_Ovml_Container_TmProjects, Func_Ovml_Container_TmSpaces, Func_Ovml_Container_TmTaskFields, Func_Ovml_Container_TmTasks, Func_Ovml_Container_WaitingArticles, Func_Ovml_Container_WaitingComments, Func_Ovml_Container_WaitingFiles, Func_Ovml_Container_WaitingPosts, Func_Ovml_Function, Func_Ovml_Function_AOAddition, Func_Ovml_Function_AODivision, Func_Ovml_Function_AOModulus, Func_Ovml_Function_AOMultiplication, Func_Ovml_Function_AOSubtraction, Func_Ovml_Function_AddStyleSheet, Func_Ovml_Function_Addon, Func_Ovml_Function_Ajax, Func_Ovml_Function_ArticleTree, Func_Ovml_Function_CurrentNode, Func_Ovml_Function_FileTree, Func_Ovml_Function_Get, Func_Ovml_Function_GetCookie, Func_Ovml_Function_GetCsrfProtectToken, Func_Ovml_Function_GetCurrentAdmGroup, Func_Ovml_Function_GetLanguage, Func_Ovml_Function_GetPageTitle, Func_Ovml_Function_GetPath, Func_Ovml_Function_GetSelectedSkinPath, Func_Ovml_Function_GetSessionVar, Func_Ovml_Function_GetVar, Func_Ovml_Function_Header, Func_Ovml_Function_IfNotIsSet, Func_Ovml_Function_Include, Func_Ovml_Function_NextArticle, Func_Ovml_Function_Post, Func_Ovml_Function_PreviousArticle, Func_Ovml_Function_PreviousOrNextArticle, Func_Ovml_Function_PutArray, Func_Ovml_Function_PutSoapArray, Func_Ovml_Function_PutVar, Func_Ovml_Function_Recurse, Func_Ovml_Function_Request, Func_Ovml_Function_SetCookie, Func_Ovml_Function_SetSessionVar, Func_Ovml_Function_SitemapCustomNodeId, Func_Ovml_Function_SitemapMenu, Func_Ovml_Function_SitemapPosition, Func_Ovml_Function_SitemapUrl, Func_Ovml_Function_Translate, Func_Ovml_Function_UrlContent, Func_Ovml_Function_WebStat, Func_PortalAuthentication, Func_PortalAuthentication_AuthOvidentia, Func_PwdComplexity, Func_PwdComplexity_DefaultPortal, Func_SearchUi, Func_SitemapDynamicNode, Func_SitemapDynamicNode_Topic, Func_UserEditor, Func_WorkingHours, Func_WorkingHours_Ovidentia, Ovml_Container_Sitemap, bab_ArithmeticOperator, bab_Ovml_Container_Operator, bab_rgp. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
1114
		
1115
		
1116
		
1117
		
1118
		$validoverlap = $W->LabelledWidget(
1119
				absences_translate('Allow overlap between the request period and the test periods'),
1120
				$W->CheckBox(),
1121
				'validoverlap'
1122
		);
1123
		
1124
		$list = $W->VBoxLayout('absences_dupli_periods');
1125
		
1126
		if (!$this->addDuplicableToList($list))
1127
		{
1128
			$list->addItem($this->createDuplicable(0));
1129
		}
1130
		
1131
		return $W->VBoxItems(
1132
				$W->Label(absences_translate('The right is available if the vacation request is')),
1133
				$list,
1134
				$W->Button('absences_dupli_add')->addItem($W->Icon(absences_translate('Add a test period'), Func_Icons::ACTIONS_LIST_ADD)),
1135
				$validoverlap
1136
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_16);
1137
	}
1138
	
1139
	
1140
	/**
1141
	 * Attribution du droit en fonction des jours demandes et valides
1142
	 */
1143
	protected function by_confirmed_quantity()
1144
	{
1145
		global $babDB;
1146
		$W = bab_Widgets();
1147
		
1148
		$types = $W->Select()->setName('trigger_type');
1149
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
1150
		$types->addOption(0, absences_translate('All'));
1151
		while($arr = $babDB->db_fetch_assoc($res))
1152
		{
1153
			$types->addOption($arr['id'], $arr['name']);
1154
		}
1155
		
1156
		
1157
		return $W->VBoxItems(
1158
				$W->Label(absences_translate('The right is displayed if the user has requested')),
1159
				$W->FlowItems(
1160
					$W->Label(absences_translate('at least'))->colon(), 
1161
					$W->LineEdit()->setSize(5)->setMaxSize(10)->setName('trigger_nbdays_min'),
1162
					$W->Label(absences_translate('day(s)')),
1163
					$W->Label(absences_translate('but less than'))->colon(),
1164
					$W->LineEdit()->setSize(5)->setMaxSize(10)->setName('trigger_nbdays_max'),
1165
					$W->Label(absences_translate('day(s)'))
1166
				)->setSpacing(.5,'em'),
1167
				$W->FlowItems($W->Label(absences_translate('vacation of type'))->colon(), $types),
1168
				$W->LabelledWidget(absences_translate('First test period'), $W->PeriodPicker()->setNames('trigger_p1_begin', 'trigger_p1_end')),
1169
				$W->LabelledWidget(absences_translate('Second test period'), $W->PeriodPicker()->setNames('trigger_p2_begin', 'trigger_p2_end')),
1170
				$W->LabelledWidget(absences_translate('Use vacation requests witch overlap the test period'), $W->CheckBox(), 'trigger_overlap'),
1171
		        $this->hide_empty()
1172
				
1173
		)->setVerticalSpacing(1,'em');
1174
	}
1175
	
1176
	
1177
	/**
1178
	 * A select with directory fields
1179
	 * @return Widget_Select
1180
	 */
1181
	private function dirFieldsSelect()
1182
	{
1183
		$W = bab_Widgets();
1184
		$select = $W->Select();
1185
		
1186
		$fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
1187
		$select->addOption('', '');
1188
		
1189
		foreach($fields as $fieldname => $arr)
1190
		{
1191
			$select->addOption($fieldname, $arr['name']);
1192
		}
1193
		
1194
		return $select;
1195
	}
1196
	
1197 View Code Duplication
	protected function by_earlier_date()
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...
1198
	{
1199
		$W = bab_Widgets();
1200
		
1201
		return $W->VBoxItems(
1202
				$W->VBoxItems(
1203
					$W->FlowItems(
1204
						$W->Label(absences_translate('The right is granted if the field')),
1205
						$this->dirFieldsSelect()->setName('earlier'),
1206
						$W->Label(absences_translate('is set with a date in the user directory entry'))
1207
					)->setSpacing(.5,'em'),
1208
					$W->Label(absences_translate('and the day of the request is:')),
1209
					
1210
					$W->HBoxItems(
1211
						$W->Label(absences_translate('at least')),
1212
						$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('earlier_begin_valid'),
1213
						$W->Label(absences_translate('year(s) after the date set in the directory entry'))
1214
					)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'),
1215
					$W->HBoxItems(
1216
						$W->Label(absences_translate('and at more')),
1217
						$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('earlier_end_valid'),
1218
						$W->Label(absences_translate('year(s) after the date set in the directory entry'))
1219
					)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle')
1220
				)->setSpacing(1,'em'),
1221
				
1222
				$W->Icon(absences_translate('Example: use a field with the user birthday, the criteria will be an age range'), Func_Icons::STATUS_DIALOG_QUESTION)
1223
		
1224
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
1225
	}
1226
	
1227 View Code Duplication
	protected function by_later_date()
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...
1228
	{
1229
		$W = bab_Widgets();
1230
		
1231
		return $W->VBoxItems(
1232
				$W->VBoxItems(
1233
						$W->FlowItems(
1234
								$W->Label(absences_translate('The right is granted if the field')),
1235
								$this->dirFieldsSelect()->setName('later'),
1236
								$W->Label(absences_translate('is set with a date in the user directory entry'))
1237
						)->setSpacing(.5,'em'),
1238
						$W->Label(absences_translate('and the day of the request is:')),
1239
		
1240
						$W->HBoxItems(
1241
								$W->Label(absences_translate('at least')),
1242
								$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('later_begin_valid'),
1243
								$W->Label(absences_translate('year(s) before the date set in the directory entry'))
1244
						)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'),
1245
						$W->HBoxItems(
1246
								$W->Label(absences_translate('and at more')),
1247
								$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('later_end_valid'),
1248
								$W->Label(absences_translate('year(s) before the date set in the directory entry'))
1249
						)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle')
1250
				)->setSpacing(1,'em'),
1251
				
1252
				$W->Icon(absences_translate('Example: use a field with the user retirment projected date, it will be possible to assign the right in the last years of the employee'), Func_Icons::STATUS_DIALOG_QUESTION)
1253
		
1254
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
1255
	}
1256
	
1257
	
1258
	
1259
	/**
1260
	 * Disponibilite en fonction de la date de la demande de conges et de la date de saisie
1261
	 */
1262
	protected function by_request_date()
1263
	{
1264
		$W = bab_Widgets();
1265
	
1266
		return $W->FlowItems(
1267
				$W->Label(absences_translate('The right is available if the request start date is at least')),
1268
				$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('delay_before'),
1269
				$W->Label(absences_translate('days after the current date. (0: test disabled)'))
1270
		)->setVerticalAlign('middle')->setHorizontalSpacing(.25, 'em');
1271
	}
1272
	
1273
	
1274
	
1275
	public function display(Widget_Canvas $canvas)
1276
	{
1277
		$html = parent::display($canvas);
1278
		$html.= $canvas->loadScript($this->getId(), bab_getAddonInfosInstance('absences')->getTemplatePath().'righteditor.jquery.js');
1279
		
1280
		return $html;
1281
	}
1282
}
1283
1284
1285
1286
class absences_CreateRightEditor extends absences_RightEditor
1287
{
1288
    protected function setRightHiddenFields()
1289
    {
1290
        $arr = array();
1291
        $this->getSelfPageHiddenFields($arr);
1292
        unset($arr['from']);
1293
        $this->setRightHiddenValues($arr);
1294
    }
1295
    
1296
    protected function setRightId()
1297
    {
1298
        
1299
    }
1300
}
1301
1302
1303
1304
/**
1305
 * Add personnel tu right by user group
1306
 *
1307
 */
1308
class absences_RightAddPersonnelEditor extends Widget_Form 
1309
{
1310
	/**
1311
	 * 
1312
	 * @var absences_Right
1313
	 */
1314
	protected $right;
1315
	
1316
1317
	
1318 View Code Duplication
	public function __construct(absences_Right $right = 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...
1319
	{
1320
		$W = bab_Widgets();
1321
		
1322
		parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(1,'em'));
1323
		
1324
		$this->right = $right;
1325
		
1326
		$this->setName('right');
1327
		$this->addClass('widget-bordered');
1328
		$this->addClass('BabLoginMenuBackground');
1329
		$this->addClass('widget-centered');
1330
		$this->colon();
1331
		
1332
		$this->setCanvasOptions($this->Options()->width(70,'em'));
0 ignored issues
show
Bug introduced by
It seems like $this->Options()->width(70, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1333
		
1334
		
1335
		
1336
		$this->addFields();
1337
		
1338
		$this->addButtons();
1339
		$this->setSelfPageHiddenFields();
1340
		
1341
		$this->setHiddenValue('right[id]', $right->id);
1342
	}
1343
	
1344
	
1345 View Code Duplication
	protected function addFields()
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...
1346
	{
1347
		$W = bab_Widgets();
1348
		
1349
		$this->addItem($W->LabelledWidget(absences_translate('Grant the right by using the group'), $W->GroupPicker(), 'group'));
1350
		
1351
		$this->addItem($W->LabelledWidget(absences_translate('Use the group and his childen'), $W->Checkbox(), 'tree'));
1352
	}
1353
	
1354
1355 View Code Duplication
	protected function addButtons()
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...
1356
	{
1357
		$W = bab_Widgets();
1358
	
1359
		$button = $W->FlowItems(
1360
				$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')),
1361
				$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))
1362
		)->setSpacing(1,'em');
1363
	
1364
		$this->addItem($button);
1365
	}
1366
1367
}
1368
1369
1370
1371
1372
1373
class absences_RightCardFrame extends absences_CardFrame
1374
{
1375
	protected $right;
1376
	
1377
	public function __construct(absences_Right $right, $layout = null)
1378
	{
1379
		$W = bab_Widgets();
1380
	
1381
		if (null === $layout)
1382
		{
1383
			$layout = $W->VBoxLayout()->setVerticalSpacing(1,'em');
1384
		}
1385
		
1386
	
1387
		parent::__construct(null, $layout);
1388
	
1389
		$this->right = $right;
1390
	
1391
		$this->loadPage();
1392
	}
1393
	
1394
	
1395
	protected function initClasses()
1396
	{
1397
		$this->addClass('absences-right-cardframe');
1398
		$this->addClass(Func_Icons::ICON_LEFT_24);
1399
		
1400
	}
1401
	
1402
	
1403
	protected function loadPage()
1404
	{
1405
		$this->initClasses();
1406
		$this->addColHead();
1407
1408
		
1409
		if ($conditions = $this->conditions())
1410
		{
1411
			$this->addItem($conditions);
1412
		}
1413
	}
1414
	
1415
	
1416
	protected function addColHead()
1417
	{
1418
		$W = bab_Widgets();
1419
		
1420
		$icon = $W->Frame();
1421
		
1422
		$type = $this->right->getType();
1423
		if ($type->getRow())
1424
		{
1425
			$icon->setCanvasOptions($icon->Options()->width(20,'px')->height(20,'px')->backgroundColor('#'.$type->color));
1426
		} else {
1427
			$icon = null;
1428
		}
1429
		
1430
		$this->addItem($W->HBoxItems($icon, $W->Title($this->right->description, 2))->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'));
1431
		
1432
		
1433
		$this->addItem($W->HBoxItems(
1434
				$col1 = $W->VBoxLayout()->setVerticalSpacing(.2,'em'),
1435
				$col2 = $W->VBoxLayout()->setVerticalSpacing(.2,'em')
1436
		)->setHorizontalSpacing(3,'em'));
1437
		
1438
		
1439
		$col1->addItem(
1440
				$this->titledLabel(
1441
						absences_translate('Right kind'),
1442
						$this->right->getKindLabel()
1443
				)
1444
		);
1445
		
1446
		if ($type->getRow())
1447
		{
1448
			$col1->addItem(
1449
					$this->titledLabel(
1450
							absences_translate('Type'),
1451
							$this->right->getType()->name
1452
					)
1453
			);
1454
		}
1455
		
1456
		if (absences_Right::CET !== $this->right->getKind())
1457
		{
1458
			$col1->addItem(
1459
					$this->titledLabel(
1460
							absences_translate('Quantity'),
1461
							absences_quantity($this->right->quantity, $this->right->quantity_unit)
1462
					)
1463
			);
1464
		}
1465
		
1466
		
1467
		if (absences_Right::INCREMENT === $this->right->getKind())
1468
		{
1469
		    $col1->addItem(
1470
		        $this->titledLabel(
1471
		            absences_translate('Quantity to add each month'),
1472
		            absences_quantity($this->right->quantity_inc_month, $this->right->quantity_unit)
1473
		        )
1474
		    );
1475
		    
1476
		    
1477
		    $col1->addItem(
1478
		        $this->titledLabel(
1479
		            absences_translate('Do not increment more than'),
1480
		            absences_quantity($this->right->quantity_inc_max, $this->right->quantity_unit)
1481
		        )
1482
		    );
1483
		    
1484
		    
1485
		    $col1->addItem(
1486
		        $this->titledLabel(
1487
		            absences_translate('Additional quantity by monthly updates'),
1488
		            '+'.absences_quantity($this->right->getIncrementQuantity(), $this->right->quantity_unit)
1489
		        )
1490
		    );
1491
		    
1492
		    
1493
		}
1494
		
1495
		
1496
		$col1->addItem(
1497
				$this->titledLabel(
1498
						absences_translate('Status'),
1499
						$this->right->getStatus()
1500
				)
1501
		);
1502
		
1503
		
1504
		if ($this->right->renewal_parent) {
1505
		    
1506
		    $parent = new absences_Right($this->right->renewal_parent);
1507
		    
1508
		    if ($parent->getRow()) {
1509
		    
1510
    		    $addon = bab_getAddonInfosInstance('absences');
1511
    		    
1512
        		$col1->addItem(
1513
        		    $W->FlowItems(
1514
        		        $W->Label(absences_translate('Previous right in the renewal history'))->colon()->addClass('widget-strong'),
1515
        		        $W->Link($parent->description, $addon->getUrl().'vacadma&idx=viewvr&idvr='.$parent->id)
1516
        		    )->addClass('widget-small')->setSpacing(.2,'em', .3,'em')
1517
        		);
1518
		    }
1519
		}
1520
		
1521
		
1522
		
1523
		$col2->addItem(
1524
				$this->titledLabel(
1525
						absences_translate('Author'),
1526
						bab_getUserName($this->right->id_creditor)
1527
				)
1528
		);
1529
		
1530
		
1531
		if ('0000-00-00 00:00:00' !== $this->right->createdOn) {
1532
    		$col2->addItem(
1533
    		    $this->titledLabel(
1534
    		        absences_translate('Creation date'),
1535
    		        bab_shortDate(bab_mktime($this->right->createdOn), false)
1536
    		    )
1537
    		);
1538
		}
1539
		
1540
		
1541
		$col2->addItem(
1542
			$this->titledLabel(
1543
				absences_translate('Last modification date'),
1544
				bab_shortDate(bab_mktime($this->right->date_entry), false)
1545
			)
1546
		);
1547
		
1548
		
1549
		if ($theoretical_period = $this->getTheoreticalPeriod())
1550
		{
1551
			$col2->addItem($theoretical_period);
1552
		}
1553
		
1554
		
1555
		if ($fixed_period = $this->getFixedPeriod())
1556
		{
1557
			$col2->addItem($fixed_period);
1558
		}
1559
		
1560
		
1561
		// CET
1562
		$rightCet = $this->right->getRightCet();
1563
		if ($rightCet->getRow())
1564
		{
1565
			if ($p = $this->getSavingPeriod($rightCet))
1566
			{
1567
				$col1->addItem($p);
1568
			}
1569
			
1570 View Code Duplication
			if (0 !== (int) round(10*$rightCet->per_year))
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...
1571
			{
1572
				$col2->addItem(
1573
					$this->titledLabel(
1574
						absences_translate('Maximum savings per year'),
1575
						sprintf(absences_translate('%s days'), $rightCet->per_year)
1576
					)
1577
				);
1578
			}
1579
			
1580
			
1581 View Code Duplication
			if (0 !== (int) round(10*$rightCet->ceiling))
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...
1582
			{
1583
				$col2->addItem(
1584
					$this->titledLabel(
1585
						absences_translate('Maximum savings in the account saving time'),
1586
						sprintf(absences_translate('%s days'), $rightCet->ceiling)
1587
					)
1588
				);
1589
			}
1590
			
1591
			// TODO others CET fields
1592
1593
1594
		}
1595
		
1596
		
1597
		
1598
		
1599
		
1600
		
1601
	}
1602
	
1603
	
1604
	
1605
	
1606
	protected function getPeriod($begin, $end, $hours = true)
1607
	{
1608
		return sprintf(
1609
			absences_translate('from %s to %s'), 
1610
			bab_shortDate(bab_mktime($begin), $hours), 
1611
			bab_shortDate(bab_mktime($end), $hours)
1612
		);
1613
	}
1614
	
1615
	
1616
	protected function getTheoreticalPeriod()
1617
	{
1618
		if ('0000-00-00' === $this->right->date_begin || '0000-00-00' === $this->right->date_end)
1619
		{
1620
			return null;
1621
		}
1622
		
1623
		
1624
		return $this->titledLabel(
1625
			absences_translate('Theoretical period'),
1626
			$this->getPeriod($this->right->date_begin, $this->right->date_end, false)
1627
		);
1628
	}
1629
	
1630
	
1631
	protected function getFixedPeriod()
1632
	{
1633
		if (absences_Right::FIXED !== $this->right->getKind())
1634
		{
1635
			return null;
1636
		}
1637
		
1638
		return $this->titledLabel(
1639
			absences_translate('Fixed right period'),
1640
			$this->getPeriod($this->right->date_begin_fixed, $this->right->date_end_fixed)
1641
		);
1642
	}
1643
	
1644
	
1645
	
1646
	protected function sync()
1647
	{
1648
		$W = bab_Widgets();
1649
1650
		if (0 === $this->right->getSyncStatus())
1651
		{
1652
			return null;
1653
		}
1654
		
1655
		
1656
		
1657
		if (absences_Right::SYNC_SERVER !== $this->right->getSyncStatus())
1658
		{
1659
			$frame = $W->Frame(null, $W->VBoxLayout()->setVerticalSpacing(.5,'em'))->addClass('widget-bordered');
1660
			$frame->addItem($W->Title(sprintf(absences_translate('Shared right from %s'), absences_getVacationOption('sync_url')), 5));
1661
			$frame->addItem($W->Label($this->right->getSyncStatusLabel()));
1662
			$frame->addItem($this->titledLabel(absences_translate('Last update'), bab_shortDate(bab_mktime($this->right->sync_update))));
1663
			
1664
			return $frame;
1665
			
1666
		} else {
1667
			
1668
			return $W->Label($this->right->getSyncStatusLabel());
1669
		}
1670
	}
1671
	
1672
	
1673
	protected function conditions()
1674
	{
1675
		$W = bab_Widgets();
1676
		$cond = $this->right->getAccessConditions();
1677
		
1678
		if (null === $cond)
1679
		{
1680
			return null;
1681
		}
1682
		
1683
		return $W->RichText($cond);
1684
	}
1685
	
1686
	
1687
	
1688
	
1689
	
1690
	/**
1691
	 * 
1692
	 * @param absences_CollectionIterator $collections
1693
	 */
1694
	protected function getCollectionsTable($collections)
1695
	{
1696
		$W = bab_Widgets();
1697
		$table = $W->VBoxLayout()->setVerticalSpacing(.5,'em');
1698
		
1699
		foreach($collections as $collection)
1700
		{
1701
			$table->addItem($W->Label($collection->name));
1702
		}
1703
		
1704
		return $table;
1705
	}
1706
	
1707
	
1708
	protected function getSavingPeriod($rightCet)
1709
	{
1710
		if ('0000-00-00' === $rightCet->saving_begin || '0000-00-00' === $rightCet->saving_end)
1711
		{
1712
			return null;
1713
		}
1714
	
1715
	
1716
		return $this->titledLabel(
1717
				absences_translate('Saving period'),
1718
				$this->getPeriod($rightCet->saving_begin, $rightCet->saving_end, false)
1719
		);
1720
	}
1721
1722
}
1723
1724
1725
1726
1727
1728
1729
class absences_RightFullFrame extends absences_RightCardFrame
1730
{
1731
	
1732
	protected function initClasses()
1733
	{
1734
		$this->addClass('absences-right-fullframe');
1735
		$this->addClass(Func_Icons::ICON_LEFT_16);
1736
		
1737
		$this->addClass('widget-bordered');
1738
		$this->addClass('BabLoginMenuBackground');
1739
		$this->addClass('widget-centered');
1740
		
1741
		$this->setCanvasOptions($this->Options()->width(70,'em'));
0 ignored issues
show
Bug introduced by
It seems like $this->Options()->width(70, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1742
	
1743
	}
1744
	
1745
	
1746
	protected function loadPage()
1747
	{
1748
		$this->initClasses();
1749
		$W = bab_Widgets();
1750
	
1751
		$this->addColHead();
1752
		
1753
		if ($sync = $this->sync())
1754
		{
1755
			$this->addItem($sync);
1756
		}
1757
	
1758
	
1759
		if ($conditions = $this->conditions())
1760
		{
1761
			$this->addItem($conditions);
1762
		}
1763
	
1764
		if ($beneficiaries = $this->beneficiaries())
1765
		{
1766
			$this->addItem($beneficiaries);
1767
		}
1768
		
1769
		if ($alert = $this->alert())
1770
		{
1771
			$this->addItem($alert);
1772
		}
1773
		
1774
		if ($dynconf = $this->dynamic_configuration())
1775
		{
1776
			$this->addItem($dynconf);
1777
		}
1778
		
1779
		$addon = bab_getAddonInfosInstance('absences');
1780
		$this->addItem($W->Link(
1781
		    $W->Icon(absences_translate('Create a new right from this one'), Func_Icons::ACTIONS_LIST_ADD), 
1782
		    $addon->getUrl().'vacadma&idx=addvr&from='.$this->right->id
1783
		));
1784
	}
1785
	
1786
	
1787
	
1788
	protected function beneficiaries()
1789
	{
1790
		$W = bab_Widgets();
1791
		$vbox = $W->VBoxLayout();
1792
	
1793
		$coll_section = $W->Section(absences_translate('Collections'), $coll_layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em'))->setFoldable(true, false);
1794
		$vbox->addItem($coll_section);
1795
	
1796
		$collections = $this->right->getCollectionIterator();
1797
	
1798
		if ($collections->count() == 0)
1799
		{
1800
			$coll_layout->addItem($W->Label(absences_translate('No collections associated to this right')));
1801
		}
1802
		else if ($collections->count() < 20)
1803
		{
1804
			$coll_layout->addItem($this->getCollectionsTable($collections));
1805
		} else {
1806
			$coll_layout->addItem($W->Label(sprintf(absences_translate('%d collections'), $collections->count())));
1807
		}
1808
	
1809
		$button = $W->Button()->addItem($W->Label(absences_translate('Edit beneficiaries collections'))->addClass('widget-small'));
1810
		$coll_layout->addItem($W->Link($button, absences_addon()->getUrl().'vacadma&idx=lvrc&idvr='.$this->right->id)->setSizePolicy(Widget_SizePolicy::MINIMUM));
1811
		$coll_layout->setCanvasOptions($coll_layout->Options()->width(100, '%'));
0 ignored issues
show
Bug introduced by
It seems like $coll_layout->Options()->width(100, '%') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1812
	
1813
	
1814
		$a_section = $W->Section(absences_translate('Agents'), $a_layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em'))->setFoldable(true, false);
1815
		$vbox->addItem($a_section);
1816
	
1817
		$agents = $this->right->getAgentIterator();
1818
	
1819
		if ($agents->count() == 0)
1820
		{
1821
			$a_layout->addItem($W->Label(absences_translate('No users associated to this right')));
1822
		}
1823
		else {
1824
			$a_layout->addItem($stat_layout = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
1825
	
1826
	
1827
			$stat_layout->addItem($W->Label(sprintf(absences_translate('%d associated users'), $agents->count())));
1828
	
1829
			$stats = $this->right->getAgentUsage();
1830
	
1831
			$stat_layout->addItem(
1832
					$this->titledLabel(
1833
							absences_translate('Total unused quantity'),
1834
							$stats['available']
1835
					)
1836
			);
1837
	
1838
			$stat_layout->addItem(
1839
					$this->titledLabel(
1840
							absences_translate('Total waiting quantity (approbation ongoing)'),
1841
							$stats['waiting']
1842
					)
1843
			);
1844
	
1845
			$stat_layout->addItem(
1846
					$this->titledLabel(
1847
							absences_translate('Agents with remaining rights'),
1848
							$stats['agents']
1849
					)
1850
			);
1851
	
1852
			/*
1853
			 $stat_layout->addItem(
1854
			 		$this->titledLabel(
1855
			 				absences_translate('agents with remaining rights (without unconfirmed requests)'),
1856
			 				$stats['agents_iu']
1857
			 		)
1858
			 );
1859
			*/
1860
		}
1861
	
1862
		$button = $W->Button()->addItem($W->Label(absences_translate('Edit beneficiaries agents'))->addClass('widget-small'));
1863
		$a_layout->addItem($W->Link($button, absences_addon()->getUrl().'vacadma&idx=lvrp&idvr='.$this->right->id)->setSizePolicy(Widget_SizePolicy::MINIMUM));
1864
	
1865
		$a_layout->setCanvasOptions($a_layout->Options()->width(100, '%'));
0 ignored issues
show
Bug introduced by
It seems like $a_layout->Options()->width(100, '%') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1866
	
1867
		return $vbox;
1868
	}
1869
	
1870
	
1871
	/**
1872
	 * Liste des agents concernes par lalerte configuree
1873
	 * @return Widget_Displayable_Interface
1874
	 */
1875
	public function alert()
1876
	{
1877
		$W = bab_Widgets();
1878
		
1879
		$types = $this->right->getQuantityAlertTypes();
1880
		
1881
		if (empty($types))
1882
		{
1883
			return null;
1884
		}
1885
		
1886
		$section = $W->Section(absences_translate('Alert depending on the consumed quantity'), $hbox = $W->HBoxLayout())->setFoldable(true);
1887
		
1888
		$hbox->addItem($vbox = $W->VBoxLayout()->setVerticalSpacing(1, 'em'));
1889
		
1890
		$vbox->addItem($this->titledLabel(
1891
			absences_translate('Consumed quantity on types'),
1892
			$types
1893
		));
1894
		
1895
		
1896
		$vbox->addItem($this->titledLabel(
1897
			absences_translate('Consumed quantity on period'),
1898
			$this->getPeriod($this->right->quantity_alert_begin, $this->right->quantity_alert_end, false)
1899
		));
1900
		
1901
		$vbox->addItem($this->titledLabel(
1902
				absences_translate('Consumed quantity limit'),
1903
				absences_quantity($this->right->quantity_alert_days, 'D')
1904
		));
1905
		
1906
		$I = $this->right->getAgentRightIterator();
1907
		
1908
		$table = $W->BabTableView();
1909
		
1910
		$row = 0;
1911
		$table->addHeadRow($row);
1912
		
1913
		$table->addItem($W->Label(absences_translate('Beneficiary with alert')), $row, 0);
1914
		$table->addItem($W->Label(absences_translate('Quantity')), $row, 1);
1915
		$row++;
1916
		
1917
		$quantity_alert_days = (float) $this->right->quantity_alert_days;
1918
		
1919
		foreach($I as $agentRight)
1920
		{
1921
			/*@var $agentRight absences_AgentRight */
1922
			$qte = $agentRight->getQuantityAlertConsumed();
1923
			
1924
			if ($qte > $quantity_alert_days)
1925
			{
1926
				$table->addItem($W->Link($agentRight->getAgent()->getName(), absences_addon()->getUrl().'vacadm&idx=agentright&ar='.$agentRight->id), $row, 0);
1927
				$table->addItem($W->Label(absences_quantity(round($qte, 2), 'D')), $row, 1);
1928
				$row++;
1929
			}
1930
			
1931
			
1932
		}
1933
		
1934
		$vbox->setSizePolicy('widget-50pc');
1935
		$table->setSizePolicy('widget-50pc');
1936
		
1937
		$hbox->addItem($table);
1938
		
1939
		return $section;
1940
	}
1941
	
1942
	
1943
	
1944
	
1945
	/**
1946
	 * afficher la configuration des soldes dynamiques
1947
	 */
1948
	public function dynamic_configuration()
1949
	{
1950
		$I = $this->right->getDynamicConfigurationIterator();
1951
		
1952
		if (0 === $I->count())
1953
		{
1954
			return null;
1955
		}
1956
		
1957
		
1958
		$W = bab_Widgets();
1959
		$section = $W->Section(absences_translate('Quantity modification depending on the consumed number of days'), $hbox = $W->HBoxLayout())->setFoldable(true);
1960
		
1961
		$hbox->addItem($vbox = $W->VBoxLayout()->setVerticalSpacing(1, 'em'));
1962
		
1963
		$vbox->addItem($this->titledLabel(
1964
			absences_translate('Consumed quantity on period'),
1965
			$this->getPeriod($this->right->dynconf_begin, $this->right->dynconf_end, false)
1966
		));
1967
		
1968
		
1969
		
1970
		$vbox->addItem($this->titledLabel(
1971
				absences_translate('Consumed quantity on types'),
1972
				implode(', ',$this->right->getDynamicTypes())
1973
		));
1974
		
1975
1976
		$table = $W->BabTableView();
1977
		
1978
		$row = 0;
1979
		$table->addHeadRow($row);
1980
		
1981
		$table->addItem($W->Label(absences_translate('Quantity limit')), $row, 0);
1982
		$table->addItem($W->Label(absences_translate('Quantity modification')), $row, 1);
1983
		$row++;
1984
		
1985
		foreach($I as $dynamic_configuration)
1986
		{
1987
			$table->addItem($W->Label(absences_quantity($dynamic_configuration->test_quantity, 'D')), $row, 0);
1988
			$table->addItem($W->Label(absences_quantity($dynamic_configuration->quantity, $this->right->quantity_unit)), $row, 1);
1989
			$row++;
1990
		}
1991
		
1992
		$hbox->addItem($table);
1993
		
1994
		$vbox->setSizePolicy('widget-50pc');
1995
		$table->setSizePolicy('widget-50pc');
1996
		
1997
		
1998
		return $section;
1999
	}
2000
}
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
class absences_RightMovementList extends absences_MovementList
2016
{
2017
2018
    public function __construct(absences_Right $right)
2019
    {
2020
        parent::__construct();
2021
        
2022
        $this->res = $right->getMovementIterator();
2023
        $this->res->rewind();
2024
2025
        $this->paginate($this->res->count(), self::MAX);
2026
        $this->res->seek($this->pos);
2027
    }
2028
2029
}
2030
2031