Completed
Push — master ( 520222...50fc26 )
by Paul
03:23
created

absences_RightEditor::addItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3142
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
require_once dirname(__FILE__).'/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'));
135
		
136
		
137
		// init frames dynamically displayed
138
		
139
		$this->quantity = $this->quantity();
140
		$this->advanced_options = $W->FlowItems($this->cbalance(), $this->require_approval(), $this->use_in_cet())->setSpacing(1,'em', 4,'em');
141
		$this->no_distribution = $this->no_distribution();
142
		$this->availability_rules = $this->availability_rules();
143
		$this->fixed = $this->fixed();
144
		$this->cet = $this->cet();
145
		$this->inc_month = $this->inc_month();
146
		$this->report = $this->report();
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) {
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
	protected function setRightId()
234
	{
235
	    if (isset($this->right) && !empty($this->right->id))
236
	    {
237
	        $this->setHiddenValue('right[id]', $this->right->id);
238
	    }
239
	}
240
	
241
	
242
	
243
	protected function loadFormValues()
244
	{
245
		$this->setRightId();
246
		
247
		if (isset($_POST['right']))
248
		{
249
			$values = $_POST['right'];
250
		} else if (isset($this->right))
251
		{
252
			$values = $this->right->getRow();
253
			$rules = $this->right->getRightRule();
254
			if ($rules_values = $rules->getRow())
255
			{
256
				$values = array_merge($values, $rules_values);
257
			}
258
			
259
			$cet = $this->right->getRightCet();
260
			if ($cet_values = $cet->getRow())
261
			{
262
				$values = array_merge($values, $cet_values);
263
			}
264
			
265
			list($values['datebeginfx'], $values['hourbeginfx']) = explode(' ',$values['date_begin_fixed']);
266
			list($values['dateendfx'], $values['hourendfx']) = explode(' ',$values['date_end_fixed']);
267
			
268
			if (isset($values['min_use']))
269
			{
270
				$test_min_use = (int) round($values['min_use'] * 10);
271
				
272
				if (0 === $test_min_use)
273
				{
274
					$values['min_use_opt'] = 0;
275
				} else if ($test_min_use < 0) {
276
					$values['min_use_opt'] = -1;
277
				} else if ($test_min_use > 0) {
278
					$values['min_use_opt'] = 1;
279
				}
280
			}
281
			
282
			if ('0000-00-00' !== $values['date_end_report'])
283
			{
284
				$values['report'] = 1;
285
			}
286
			
287
			$values['quantity_alert_types'] = explode(',',$values['quantity_alert_types']);
288
			$values['dynconf_types'] = explode(',',$values['dynconf_types']);
289
			
290
		} else {
291
			$values = array(
292
				'active' => 'Y',	
293
				'id_type' => bab_rp('idtype'),
294
				'delay_before' => 0
295
			);
296
		}
297
298
		
299
		$this->setValues(array('right' => $values));
300
	}
301
	
302
	
303 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...
304
	{
305
		$W = bab_Widgets();
306
		
307
		$button = $W->FlowItems(
308
			$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')),
309
			$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))
310
		)->setSpacing(1,'em');
311
		
312
		if (isset($this->right))
313
		{
314
			$button->addItem(
315
				$W->SubmitButton()
316
					->setConfirmationMessage(absences_translate('Do you really want to delete the vacation right?'))
317
					->setName('delete')->setLabel(absences_translate('Delete'))
318
			);
319
		}
320
		
321
		$this->addItem($button);
322
	}
323
	
324
	
325
	
326 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...
327
	{
328
		$W = bab_Widgets();
329
		
330
		return $W->LabelledWidget(
331
				absences_translate('Right name'),
332
				$W->LineEdit()->setSize(60)->setMaxSize(255)->setMandatory(true, absences_translate('The name is mandatory')),
333
				__FUNCTION__
334
		);
335
	}
336
	
337
	
338
	protected function kind()
339
	{
340
		$W = bab_Widgets();
341
		
342
		$select = $W->Select()->setOptions(absences_kinds());
343
		
344
		$select->setAssociatedDisplayable($this->quantity, array(absences_Right::REGULAR, absences_Right::INCREMENT, absences_Right::FIXED, absences_Right::RECOVERY));
345
		$select->setAssociatedDisplayable($this->advanced_options, array(absences_Right::REGULAR, absences_Right::INCREMENT));
346
		$select->setAssociatedDisplayable($this->no_distribution, array(absences_Right::REGULAR, absences_Right::CET, absences_Right::INCREMENT));
347
		$select->setAssociatedDisplayable($this->availability_rules, array(absences_Right::REGULAR, absences_Right::CET, absences_Right::INCREMENT, absences_Right::RECOVERY));
348
		$select->setAssociatedDisplayable($this->fixed, array(absences_Right::FIXED));
349
		$select->setAssociatedDisplayable($this->cet, array(absences_Right::CET));
350
		$select->setAssociatedDisplayable($this->inc_month, array(absences_Right::INCREMENT));
351
		$select->setAssociatedDisplayable($this->report, array(absences_Right::REGULAR, absences_Right::INCREMENT));
352
		$select->setAssociatedDisplayable($this->test_other_types, array(absences_Right::REGULAR, absences_Right::INCREMENT, absences_Right::RECOVERY));
353
		return $W->LabelledWidget(
354
				absences_translate('Right kind'),
355
				$select,
356
				__FUNCTION__
357
		);
358
	}
359
	
360
	
361
	/**
362
	 * quantity & quantity_unit
363
	 * @return Widget_FlowLayout
364
	 */
365
	protected function quantity()
366
	{
367
		$W = bab_Widgets();
368
	
369
		$lineedit = $W->LineEdit()->setSize(5)->setMaxSize(5)->setMandatory(true, absences_translate('The quantity is mandatory'))->setName('quantity');
370
		$select = $W->Select()->setName('quantity_unit')
371
    		->addOption('D', absences_translate('Day(s)'))
372
    		->addOption('H', absences_translate('Hour(s)'));
373
	
374
		$vbox = $W->VBoxItems(
375
				$W->Label(absences_translate('Quantity'))->setAssociatedWidget($lineedit),
376
				$W->FlowItems($lineedit, $select)
377
		)->setVerticalSpacing(.2,'em');
378
		
379
		if (isset($this->right) && absences_Right::INCREMENT === $this->right->getKind()) {
380
    		$monthlyUpdates = $W->FlowItems(
381
    		    $W->Label(absences_translate('Additional quantity by monthly updates'))->colon(),
382
    		    $W->Label('+'.absences_quantity($this->right->getIncrementQuantity(), $this->right->quantity_unit))
383
    		)->setSpacing(.5, 'em');
384
    		
385
    		$vbox->addItem($monthlyUpdates);
386
		}
387
		
388
		return $vbox;
389
	}
390
	
391
	
392 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...
393
	{
394
		$W = bab_Widgets();
395
		global $babDB;
396
		
397
		$select = $W->Select();
398
		
399
		if ($empty)
400
		{
401
			$select->addOption('0', '');
402
		}
403
		
404
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
405
		while ($arr = $babDB->db_fetch_assoc($res))
406
		{
407
			$select->addOption($arr['id'], $arr['name']);
408
		}
409
		
410
		return $select;
411
	}
412
	
413
	
414
	private function multiType()
415
	{
416
		$W = bab_Widgets();
417
		global $babDB;
418
	
419
		$select = $W->Multiselect();
420
421
	
422
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
423
		while ($arr = $babDB->db_fetch_assoc($res))
424
		{
425
			$select->addOption($arr['id'], $arr['name']);
426
		}
427
	
428
		return $select;
429
	}
430
	
431
	
432
	
433
	
434
	/**
435
	 * 
436
	 * @return Widget_LabelledWidget
437
	 */
438
	protected function id_type()
439
	{
440
		$W = bab_Widgets();
441
442
		return $W->LabelledWidget(
443
			absences_translate('Right type'),
444
			$this->type_select(),
445
			__FUNCTION__
446
		);
447
	}
448
	
449
	
450
	
451
	/**
452
	 *
453
	 * @return Widget_LabelledWidget
454
	 */
455
	protected function id_report_type()
456
	{
457
		$W = bab_Widgets();
458
		
459
		return $W->LabelledWidget(
460
				absences_translate('Type for report rights'),
461
				$this->type_select(true),
462
				__FUNCTION__
463
		);
464
	}
465
	
466
	
467
	/**
468
	 *
469
	 * @return Widget_LabelledWidget
470
	 */
471
	protected function date_end_report()
472
	{
473
		$W = bab_Widgets();
474
		
475
		return $W->LabelledWidget(
476
				absences_translate('Report availability end'),
477
				$W->DatePicker(),
478
				__FUNCTION__
479
		);
480
	}
481
	
482
	
483
	protected function description_report()
484
	{
485
		$W = bab_Widgets();
486
	
487
		return $W->LabelledWidget(
488
				absences_translate('Report right name'),
489
				$W->LineEdit()->setSize(60)->setMaxSize(255),
490
				__FUNCTION__
491
		);
492
	}
493
	
494
	
495
	
496
	protected function report()
497
	{
498
		$W = bab_Widgets();
499
		
500
		$layout = $W->VBoxLayout()->setVerticalSpacing(1,'em');
501
		$morefields = $W->FlowItems(
502
			$this->description_report(),
503
			$this->id_report_type(), 
504
			$this->date_end_report(),
505
			$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)
506
		)->setSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
507
		
508
		$report = $W->LabelledWidget(
509
				absences_translate('Create a report for lasting right after the expiry'),
510
				$W->CheckBox()->setAssociatedDisplayable($morefields, array('1')),
511
				__FUNCTION__
512
		);
513
		
514
		$layout->addItem($report);
515
		$layout->addItem($morefields);
516
		
517
		return $layout;
518
	}
519
	
520
	
521
	
522
	
523
	protected function alert()
524
	{
525
		$W = bab_Widgets();
526
		
527
		$quantity_alert_days = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('quantity_alert_days');
528
		$quantity_alert_types = $this->multiType()->setName('quantity_alert_types');
529
		$period = $W->PeriodPicker()->setNames('quantity_alert_begin', 'quantity_alert_end');
530
		
531
		$flow = $W->FlowItems(
532
			$W->Label(absences_translate('Alert if the user has consumed more than')), 
533
			$quantity_alert_days, 
534
			$W->Label(absences_translate('days of')), 
535
			$quantity_alert_types
536
		)->setSpacing(.2,'em');
537
		
538
		$morefields = $W->VBoxItems(
539
			$flow,
540
			$W->VBoxItems($W->Label(absences_translate('Among the absences within the period'))->setAssociatedWidget($period), $period)->setVerticalSpacing(.5,'em')
541
		)->setVerticalSpacing(1,'em');
542
		
543
		return $W->Section(absences_translate('Alerting depending on the consumed quantity'), $morefields, 6)->setFoldable(true, true);
544
	}
545
	
546
	
547
	
548
	private function createDuplicableDynconf($index, absences_DynamicConfiguration $dynconf = null)
549
	{
550
		$W = bab_Widgets();
551
		$duplicable = $W->Frame(null, $W->FlowLayout()->setSpacing(.5,'em'))->setName(array('dynconf', (string) $index));
552
	
553
		$select = $W->Select()
554
			->addOption('-', absences_translate('Remove'))
555
			->addOption('+', absences_translate('Add'))
556
			->setName('sign');
557
	
558
		$test_quantity = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('test_quantity');
559
		$quantity = $W->LineEdit()->setSize(6)->setMaxSize(10)->setName('quantity');
560
		
561
		if (isset($dynconf))
562
		{
563
			// the edit quantity unit is not known here
564
			$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...
565
			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...
566
			{
567
				$select->setValue('+');
568
			} else {
569
				$select->setValue('-');
570
			}
571
			
572
			$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...
573
		}
574
		
575
		$duplicable->addItem($W->Label(absences_translate('If quantity taken is beyond')));
576
		$duplicable->addItem($test_quantity);
577
		$duplicable->addItem($W->Label(absences_translate('day(s), ')));
578
		$duplicable->addItem($select)->addItem($quantity);
579
		$duplicable->addItem($W->Button()->addItem($W->Icon('', Func_Icons::ACTIONS_LIST_REMOVE)));
580
	
581
		return $duplicable;
582
	}
583
	
584
	
585
	/**
586
	 *
587
	 * @param Widget_VBoxLayout $list
588
	 * @return bool
589
	 */
590
	private function addDuplicableDynconfToList($list)
591
	{
592
		if (!isset($this->right))
593
		{
594
			return false;
595
		}
596
	
597
		global $babDB;
598
	
599
		$res = $this->right->getDynamicConfigurationIterator();
600
	
601
		if (!$res->count())
602
		{
603
			return false;
604
		}
605
	
606
		$index = 0;
607
		foreach ($res as $dynconf)
608
		{
609
			$dupli = $this->createDuplicableDynconf($index++, $dynconf);
610
			$list->addItem($dupli);
611
		}
612
	
613
	
614
		return true;
615
	}
616
	
617
	
618
	
619
	protected function dynamic_configuration()
620
	{
621
		$W = bab_Widgets();
622
		
623
		
624
		
625
		$quantity_alert_types = $this->multiType()->setName('dynconf_types');
626
		$period = $W->PeriodPicker()->setNames('dynconf_begin', 'dynconf_end');
627
		
628
		$comoncriteria = $W->FlowItems(
629
				$W->Label(absences_translate('Test days of type')),
630
				$quantity_alert_types,
631
				$W->VBoxItems($W->Label(absences_translate('Among the absences within the period'))->setAssociatedWidget($period), $period)->setVerticalSpacing(.5,'em')
632
		)->setSpacing(1,'em')->setVerticalAlign('middle');
633
	
634
		
635
		
636
		$list = $W->VBoxLayout('absences_dynconf_rows');
637
		
638
		if (!$this->addDuplicableDynconfToList($list))
639
		{
640
			$list->addItem($this->createDuplicableDynconf(0));
641
		}
642
643
		$morefields = $W->VBoxItems(
644
			$comoncriteria,
645
			$W->VBoxItems(
646
				$list,
647
				$W->Button('absences_dynconf_add')->addItem($W->Icon(absences_translate('Add a test'), Func_Icons::ACTIONS_LIST_ADD))
648
			)->addClass('widget-bordered'),
649
			$W->Icon(absences_translate('The added or removed quantity is in the same unit as the vacation right'), Func_Icons::STATUS_DIALOG_INFORMATION)
650
		)->setVerticalSpacing(.5,'em');
651
		
652
		
653
		
654
		return $W->Section(absences_translate('Change available quantity depending on the consumed quantity'), $morefields, 6)->setFoldable(true, true)->addClass(Func_Icons::ICON_LEFT_16);
655
		
656
		
657
	}
658
	
659
	
660
	
661
	
662
	/**
663
	 * Right group
664
	 * @return Widget_LabelledWidget
665
	 */
666 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...
667
	{
668
		$W = bab_Widgets();
669
		global $babDB;
670
	
671
		$select = $W->Select();
672
		$select->addOption(0, absences_translate('None'));
673
	
674
		$res = $babDB->db_query('SELECT id, name FROM absences_rgroup ORDER BY name');
675
		while ($arr = $babDB->db_fetch_assoc($res))
676
		{
677
			$select->addOption($arr['id'], $arr['name']);
678
		}
679
	
680
		return $W->LabelledWidget(
681
				absences_translate('Right group'),
682
				$select,
683
				__FUNCTION__
684
		);
685
	}
686
	
687
	
688
	
689
	/**
690
	 * Periode theorique du droit
691
	 */
692
	protected function theoretical_period()
693
	{
694
		$W = bab_Widgets();
695
		
696
		return $W->LabelledWidget(
697
			absences_translate('Right theoretical period'),
698
			$W->PeriodPicker()->setNames('date_begin', 'date_end')
699
		);
700
	}
701
702
	
703
	
704
	/**
705
	 * 
706
	 */
707
	protected function active()
708
	{
709
		$W = bab_Widgets();
710
		
711
		/*
712
		return $W->LabelledWidget(
713
			absences_translate('Active'),
714
			$W->Checkbox()->setCheckedValue('Y')->setUncheckedValue('N'),
715
			__FUNCTION__
716
		);
717
		*/
718
		return $W->LabelledWidget(
719
				absences_translate('Active'),
720
				$W->Select()->setOptions(array(
721
						'Y' => absences_translate('Yes, usable by appliquant'),
722
						'N' => absences_translate('No, only for managers or delegated managers')
723
				)),
724
				__FUNCTION__
725
		);
726
	}
727
	
728
	
729
	
730
	/**
731
	 * 
732
	 */
733 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...
734
	{
735
		$W = bab_Widgets();
736
		return $W->LabelledWidget(
737
				absences_translate('Accept negative balance'),
738
				$W->Select()->setOptions(array(
739
					'Y' => absences_translate('Yes'),
740
					'N' => absences_translate('No')
741
				)),
742
				__FUNCTION__
743
		);
744
	}
745
	
746
	/**
747
	 *
748
	 */
749 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...
750
	{
751
		$W = bab_Widgets();
752
		return $W->LabelledWidget(
753
				absences_translate('Distribution on request'),
754
				$W->Select()->setOptions(array(
755
					'0' => absences_translate('Yes'),
756
					'1' => absences_translate('No')
757
				)),
758
				__FUNCTION__
759
		);
760
	}
761
	
762
	
763
	/**
764
	 *
765
	 */
766
	protected function use_in_cet()
767
	{
768
		$W = bab_Widgets();
769
		
770
		$cet_quantity = $W->Frame();
771
		$cet_quantity->addItem($this->cet_quantity());
772
		
773
		$use_in_cet = $W->LabelledWidget(
774
				absences_translate('Allow moving to the time savings account'),
775
				$W->Select()->setOptions(array(
776
						'1' => absences_translate('Yes'),
777
						'0' => absences_translate('No')
778
				))->setAssociatedDisplayable($cet_quantity, array('1')),
779
				__FUNCTION__
780
		);
781
		
782
		
783
		return $W->HBoxItems($use_in_cet, $cet_quantity)->setHorizontalSpacing(3,'em');
784
		
785
	}
786
	
787
	
788
	/**
789
	 *
790
	 */
791
	protected function cet_quantity()
792
	{
793
		$W = bab_Widgets();
794
		return $W->LabelledWidget(
795
				absences_translate('Saving quantity'),
796
				$W->LineEdit()->setSize(6),
797
				__FUNCTION__,
798
				absences_translate('in the same unit as right quantity')
799
		);
800
	}
801
	
802
	
803 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...
804
	{
805
		$W = bab_Widgets();
806
		return $W->LabelledWidget(
807
				absences_translate('Require approval'),
808
				$W->Select()->setOptions(array(
809
						'1' => absences_translate('Yes'),
810
						'0' => absences_translate('No')
811
				)),
812
				__FUNCTION__
813
		);
814
	}
815
	
816
	
817
	/**
818
	 * Interface for FIXED right
819
	 * @return Widget_VBoxLayout
820
	 */
821 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...
822
	{
823
		$W = bab_Widgets();
824
		
825
		return $W->VBoxItems(
826
			$W->Label(absences_translate('This vacation period will be set for all right beneficiaries')),
827
			$W->FlowItems($this->beginfx(), $this->endfx())	
828
		)->setVerticalSpacing(1,'em');
829
	}
830
	
831
	
832
	
833
	
834 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...
835
	{
836
		$W = bab_Widgets();
837
		$date = $W->DatePicker()->setMandatory(true)->setName('datebeginfx');
838
		$hours = $W->Select()->setName('hourbeginfx')->setOptions(absences_hoursList());
839
		
840
		return $W->FlowItems(
841
			$W->Label(absences_translate('from date'))->setAssociatedWidget($date),
842
			$date,
843
			$hours
844
		)->setSpacing(.5,'em');
845
	}
846
	
847
	
848 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...
849
	{
850
		$W = bab_Widgets();
851
		$date = $W->DatePicker()->setMandatory(true)->setName('dateendfx');
852
		$hours = $W->Select()->setName('hourendfx')->setOptions(absences_hoursList());
853
		
854
		return $W->FlowItems(
855
			$W->Label(absences_translate('to date'))->setAssociatedWidget($date),
856
			$date,
857
			$hours
858
		)->setSpacing(.5,'em');
859
	}
860
	
861
	
862
	protected function inc_month()
863
	{
864
		$W = bab_Widgets();
865
		
866
		return $W->VBoxItems(
867
				$this->quantity_inc_month(),
868
				$this->quantity_inc_max()
869
		)->setVerticalSpacing(1,'em');
870
	}
871
	
872
	
873 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...
874
	{
875
		$W = bab_Widgets();
876
		return $W->LabelledWidget(
877
				absences_translate('Quantity to add each month'),
878
				$W->LineEdit()->setSize(6)->setMaxSize(10)->setMandatory(true, absences_translate('The quantity per month is mandatory')),
879
				__FUNCTION__,
880
				absences_translate('The quantity will grow each month before the end date from "Availability depends on the requested period dates"')
881
		);
882
	}
883
	
884
	
885 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...
886
	{
887
		$W = bab_Widgets();
888
		return $W->LabelledWidget(
889
				absences_translate('Maximum quantity'),
890
				$W->LineEdit()->setSize(6)->setMaxSize(10),
891
				__FUNCTION__,
892
				absences_translate('The quantity will grow each month up to this limit')
893
		);
894
	}
895
	
896
	
897
	/**
898
	 * parametres specifiques pour les CET
899
	 */
900
	protected function cet()
901
	{
902
		$W = bab_Widgets();
903
		
904
		return $W->VBoxItems(
905
			$this->saving(),
906
			$this->per_year(),
907
		//	$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
908
			$this->ceiling(),
909
			$this->min_use()
910
		)->setVerticalSpacing(1,'em');
911
	}
912
	
913
	
914
	
915
916
	
917
	
918
	/**
919
	 * CET max days saving per years
920
	 */
921 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...
922
	{
923
		$W = bab_Widgets();
924
		return $W->LabelledWidget(
925
				absences_translate('Maximum savings per year'),
926
				$W->LineEdit()->setSize(6)->setMaxSize(10),
927
				__FUNCTION__,
928
				null,
929
				absences_translate('day(s)')
930
		);
931
	}
932
	
933
	
934
	/**
935
	 * CET max days saving for CET period
936
	 */
937 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...
938
	{
939
		$W = bab_Widgets();
940
		return $W->LabelledWidget(
941
				absences_translate('Maximum savings for the account saving time period'),
942
				$W->LineEdit()->setSize(6)->setMaxSize(10),
943
				__FUNCTION__,
944
				null,
945
				absences_translate('day(s)')
946
		);
947
	}
948
	
949
	
950
	/**
951
	 * CET ceiling
952
	 */
953 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...
954
	{
955
		$W = bab_Widgets();
956
		return $W->LabelledWidget(
957
				absences_translate('Maximum savings in the account saving time'),
958
				$W->LineEdit()->setSize(6)->setMaxSize(10),
959
				__FUNCTION__,
960
				null,
961
				absences_translate('day(s)')
962
		);
963
	}
964
	
965
	
966
	
967
	/**
968
	 * CET minimal use
969
	 */
970
	protected function min_use()
971
	{
972
		$W = bab_Widgets();
973
		
974
		$select = $W->Select()
975
			->addOption('0', absences_translate('No constraint'))
976
			->addOption('-1', absences_translate('Force the use of the total in one take'))
977
			->addOption('1', absences_translate('Set the minimum to use in one take'));
978
		
979
		
980
		$options = $W->LabelledWidget(
981
				absences_translate('Constraint when using the account'),
982
				$select,
983
				'min_use_opt'
984
		);
985
		
986
		$min_use = $W->LabelledWidget(
987
				absences_translate('Minimum allowed'),
988
				$W->LineEdit()->setSize(6)->setMaxSize(10),
989
				__FUNCTION__,
990
				null,
991
				absences_translate('day(s)')
992
		);
993
		
994
		
995
		$displayable = $W->Frame()->addItem($min_use);
996
		
997
		
998
		$select->setAssociatedDisplayable($displayable, array('1'));
999
		
1000
		
1001
		return $W->HBoxItems($options, $displayable)->setHorizontalSpacing(3,'em');
1002
	}
1003
	
1004
	
1005
	
1006
	
1007
	/**
1008
	 * Criteres de disponibilite d'un droit
1009
	 */
1010
	protected function availability_rules()
1011
	{
1012
		$W = bab_Widgets();
1013
		
1014
		
1015
	
1016
		return $W->Accordions()
1017
			->addPanel(absences_translate('Availability depends on the date of the vacation request input'), $this->by_request_input_date())
1018
			->addPanel(absences_translate('Availability depends on the requested period dates'), $this->by_requested_period())
1019
			->addPanel(absences_translate('Right assignement in function of requested days'), $this->by_confirmed_quantity())
1020
			->addPanel(absences_translate('Availability depends on an earlier date'), $this->by_earlier_date())
1021
			->addPanel(absences_translate('Availability depends on an later date'), $this->by_later_date())
1022
			->addPanel(absences_translate('Availability depends on the interval between the requested period dates and the current date'), $this->by_request_date())
1023
		;
1024
	}
1025
	
1026
	
1027
	
1028
	
1029
	
1030
	private function createDuplicable($index, $values = null)
1031
	{
1032
		$W = bab_Widgets();
1033
		$duplicable = $W->Frame(null, $W->FlowLayout()->setSpacing(.5,'em'))->setName(array('inperiod', (string) $index));
1034
		
1035
		$select = $W->Select()
1036
		->addOption(1, absences_translate('In rule period'))
1037
		->addOption(2, absences_translate('Out of rule period'))
1038
		->setName('right_inperiod');
1039
		
1040
		
1041
		
1042
		$periodPicker = $W->PeriodPicker()->setNames('period_start', 'period_end');
1043
		
1044
		if (isset($values))
1045
		{
1046
			$select->setValue($values['right_inperiod']);
1047
			$periodPicker->setValues($values['period_start'], $values['period_end']);
1048
		}
1049
		
1050
		$duplicable->addItem($select);
1051
		$duplicable->addItem($W->Label(absences_translate('in this period'))->colon());
1052
		$duplicable->addItem($periodPicker);
1053
		$duplicable->addItem($W->Button()->addItem($W->Icon('', Func_Icons::ACTIONS_LIST_REMOVE)));
1054
		
1055
		return $duplicable;
1056
	}
1057
	
1058
	
1059
	/**
1060
	 * 
1061
	 * @param Widget_VBoxLayout $list
1062
	 * @return bool
1063
	 */
1064
	private function addDuplicableToList($list)
1065
	{
1066
		if (!isset($this->right))
1067
		{
1068
			return false;
1069
		}
1070
		
1071
		global $babDB;
1072
		
1073
		$res = $this->right->getRightRule()->getInPeriodRes();
1074
		
1075
		if (!$res || 0 === $babDB->db_num_rows($res))
1076
		{
1077
			return false;
1078
		}
1079
		
1080
		$index = 0;
1081
		while ($arr = $babDB->db_fetch_assoc($res))
1082
		{
1083
			$dupli = $this->createDuplicable($index++, $arr);
1084
			$list->addItem($dupli);
1085
		}
1086
		
1087
		
1088
		return true;
1089
	}
1090
	
1091
	
1092
	
1093
	/**
1094
	 * Disponibilite en fonction de la periode de conges demandee
1095
	 * @return Widget_VBoxLayout
1096
	 */
1097
	protected function by_requested_period()
1098
	{
1099
		$W = bab_Widgets();
1100
		bab_functionality::includefile('Icons');
1101
		
1102
		
1103
		
1104
		
1105
		$validoverlap = $W->LabelledWidget(
1106
				absences_translate('Allow overlap between the request period and the test periods'),
1107
				$W->CheckBox(),
1108
				'validoverlap'
1109
		);
1110
		
1111
		$list = $W->VBoxLayout('absences_dupli_periods');
1112
		
1113
		if (!$this->addDuplicableToList($list))
1114
		{
1115
			$list->addItem($this->createDuplicable(0));
1116
		}
1117
		
1118
		return $W->VBoxItems(
1119
				$W->Label(absences_translate('The right is available if the vacation request is')),
1120
				$list,
1121
				$W->Button('absences_dupli_add')->addItem($W->Icon(absences_translate('Add a test period'), Func_Icons::ACTIONS_LIST_ADD)),
1122
				$validoverlap
1123
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_16);
1124
	}
1125
	
1126
	
1127
	/**
1128
	 * Attribution du droit en fonction des jours demandes et valides
1129
	 */
1130
	protected function by_confirmed_quantity()
1131
	{
1132
		global $babDB;
1133
		$W = bab_Widgets();
1134
		
1135
		$types = $W->Select()->setName('trigger_type');
1136
		$res = $babDB->db_query('SELECT id, name FROM absences_types ORDER BY name');
1137
		$types->addOption(0, absences_translate('All'));
1138
		while($arr = $babDB->db_fetch_assoc($res))
1139
		{
1140
			$types->addOption($arr['id'], $arr['name']);
1141
		}
1142
		
1143
		
1144
		return $W->VBoxItems(
1145
				$W->Label(absences_translate('The right is displayed if the user has requested')),
1146
				$W->FlowItems(
1147
					$W->Label(absences_translate('at least'))->colon(), 
1148
					$W->LineEdit()->setSize(5)->setMaxSize(10)->setName('trigger_nbdays_min'),
1149
					$W->Label(absences_translate('day(s)')),
1150
					$W->Label(absences_translate('but less than'))->colon(),
1151
					$W->LineEdit()->setSize(5)->setMaxSize(10)->setName('trigger_nbdays_max'),
1152
					$W->Label(absences_translate('day(s)'))
1153
				)->setSpacing(.5,'em'),
1154
				$W->FlowItems($W->Label(absences_translate('vacation of type'))->colon(), $types),
1155
				$W->LabelledWidget(absences_translate('First test period'), $W->PeriodPicker()->setNames('trigger_p1_begin', 'trigger_p1_end')),
1156
				$W->LabelledWidget(absences_translate('Second test period'), $W->PeriodPicker()->setNames('trigger_p2_begin', 'trigger_p2_end')),
1157
				$W->LabelledWidget(absences_translate('Use vacation requests witch overlap the test period'), $W->CheckBox(), 'trigger_overlap')
1158
				
1159
		)->setVerticalSpacing(1,'em');
1160
	}
1161
	
1162
	
1163
	/**
1164
	 * A select with directory fields
1165
	 * @return Widget_Select
1166
	 */
1167
	private function dirFieldsSelect()
1168
	{
1169
		$W = bab_Widgets();
1170
		$select = $W->Select();
1171
		
1172
		$fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
1173
		$select->addOption('', '');
1174
		
1175
		foreach($fields as $fieldname => $arr)
1176
		{
1177
			$select->addOption($fieldname, $arr['name']);
1178
		}
1179
		
1180
		return $select;
1181
	}
1182
	
1183 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...
1184
	{
1185
		$W = bab_Widgets();
1186
		
1187
		return $W->VBoxItems(
1188
				$W->VBoxItems(
1189
					$W->FlowItems(
1190
						$W->Label(absences_translate('The right is granted if the field')),
1191
						$this->dirFieldsSelect()->setName('earlier'),
1192
						$W->Label(absences_translate('is set with a date in the user directory entry'))
1193
					)->setSpacing(.5,'em'),
1194
					$W->Label(absences_translate('and the day of the request is:')),
1195
					
1196
					$W->HBoxItems(
1197
						$W->Label(absences_translate('at least')),
1198
						$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('earlier_begin_valid'),
1199
						$W->Label(absences_translate('year(s) after the date set in the directory entry'))
1200
					)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'),
1201
					$W->HBoxItems(
1202
						$W->Label(absences_translate('and at more')),
1203
						$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('earlier_end_valid'),
1204
						$W->Label(absences_translate('year(s) after the date set in the directory entry'))
1205
					)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle')
1206
				)->setSpacing(1,'em'),
1207
				
1208
				$W->Icon(absences_translate('Example: use a field with the user birthday, the criteria will be an age range'), Func_Icons::STATUS_DIALOG_QUESTION)
1209
		
1210
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
1211
	}
1212
	
1213 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...
1214
	{
1215
		$W = bab_Widgets();
1216
		
1217
		return $W->VBoxItems(
1218
				$W->VBoxItems(
1219
						$W->FlowItems(
1220
								$W->Label(absences_translate('The right is granted if the field')),
1221
								$this->dirFieldsSelect()->setName('later'),
1222
								$W->Label(absences_translate('is set with a date in the user directory entry'))
1223
						)->setSpacing(.5,'em'),
1224
						$W->Label(absences_translate('and the day of the request is:')),
1225
		
1226
						$W->HBoxItems(
1227
								$W->Label(absences_translate('at least')),
1228
								$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('later_begin_valid'),
1229
								$W->Label(absences_translate('year(s) before the date set in the directory entry'))
1230
						)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'),
1231
						$W->HBoxItems(
1232
								$W->Label(absences_translate('and at more')),
1233
								$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('later_end_valid'),
1234
								$W->Label(absences_translate('year(s) before the date set in the directory entry'))
1235
						)->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle')
1236
				)->setSpacing(1,'em'),
1237
				
1238
				$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)
1239
		
1240
		)->setVerticalSpacing(1,'em')->addClass(Func_Icons::ICON_LEFT_24);
1241
	}
1242
	
1243
	
1244
	
1245
	/**
1246
	 * Disponibilite en fonction de la date de la demande de conges et de la date de saisie
1247
	 */
1248
	protected function by_request_date()
1249
	{
1250
		$W = bab_Widgets();
1251
	
1252
		return $W->FlowItems(
1253
				$W->Label(absences_translate('The right is available if the request start date is at least')),
1254
				$W->LineEdit()->setSize(3)->setMaxSize(10)->setName('delay_before'),
1255
				$W->Label(absences_translate('days after the current date. (0: test disabled)'))
1256
		)->setVerticalAlign('middle')->setHorizontalSpacing(.25, 'em');
1257
	}
1258
	
1259
	
1260
	
1261
	public function display(Widget_Canvas $canvas)
1262
	{
1263
		$html = parent::display($canvas);
1264
		$html.= $canvas->loadScript($this->getId(), bab_getAddonInfosInstance('absences')->getTemplatePath().'righteditor.jquery.js');
1265
		
1266
		return $html;
1267
	}
1268
}
1269
1270
1271
1272
class absences_CreateRightEditor extends absences_RightEditor
1273
{
1274
    protected function setRightHiddenFields()
1275
    {
1276
        $arr = array();
1277
        $this->getSelfPageHiddenFields($arr);
1278
        unset($arr['from']);
1279
        $this->setRightHiddenValues($arr);
1280
    }
1281
    
1282
    protected function setRightId()
1283
    {
1284
        
1285
    }
1286
}
1287
1288
1289
1290
/**
1291
 * Add personnel tu right by user group
1292
 *
1293
 */
1294
class absences_RightAddPersonnelEditor extends Widget_Form 
1295
{
1296
	/**
1297
	 * 
1298
	 * @var absences_Right
1299
	 */
1300
	protected $right;
1301
	
1302
1303
	
1304 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...
1305
	{
1306
		$W = bab_Widgets();
1307
		
1308
		parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(1,'em'));
1309
		
1310
		$this->right = $right;
1311
		
1312
		$this->setName('right');
1313
		$this->addClass('widget-bordered');
1314
		$this->addClass('BabLoginMenuBackground');
1315
		$this->addClass('widget-centered');
1316
		$this->colon();
1317
		
1318
		$this->setCanvasOptions($this->Options()->width(70,'em'));
1319
		
1320
		
1321
		
1322
		$this->addFields();
1323
		
1324
		$this->addButtons();
1325
		$this->setSelfPageHiddenFields();
1326
		
1327
		$this->setHiddenValue('right[id]', $right->id);
1328
	}
1329
	
1330
	
1331 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...
1332
	{
1333
		$W = bab_Widgets();
1334
		
1335
		$this->addItem($W->LabelledWidget(absences_translate('Grant the right by using the group'), $W->GroupPicker(), 'group'));
1336
		
1337
		$this->addItem($W->LabelledWidget(absences_translate('Use the group and his childen'), $W->Checkbox(), 'tree'));
1338
	}
1339
	
1340
1341 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...
1342
	{
1343
		$W = bab_Widgets();
1344
	
1345
		$button = $W->FlowItems(
1346
				$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')),
1347
				$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))
1348
		)->setSpacing(1,'em');
1349
	
1350
		$this->addItem($button);
1351
	}
1352
1353
}
1354
1355
1356
1357
1358
1359
class absences_RightCardFrame extends absences_CardFrame
1360
{
1361
	protected $right;
1362
	
1363
	public function __construct(absences_Right $right, $layout = null)
1364
	{
1365
		$W = bab_Widgets();
1366
	
1367
		if (null === $layout)
1368
		{
1369
			$layout = $W->VBoxLayout()->setVerticalSpacing(1,'em');
1370
		}
1371
		
1372
	
1373
		parent::__construct(null, $layout);
1374
	
1375
		$this->right = $right;
1376
	
1377
		$this->loadPage();
1378
	}
1379
	
1380
	
1381
	protected function initClasses()
1382
	{
1383
		$this->addClass('absences-right-cardframe');
1384
		$this->addClass(Func_Icons::ICON_LEFT_24);
1385
		
1386
	}
1387
	
1388
	
1389
	protected function loadPage()
1390
	{
1391
		$this->initClasses();
1392
		$this->addColHead();
1393
1394
		
1395
		if ($conditions = $this->conditions())
1396
		{
1397
			$this->addItem($conditions);
1398
		}
1399
	}
1400
	
1401
	
1402
	protected function addColHead()
1403
	{
1404
		$W = bab_Widgets();
1405
		
1406
		$icon = $W->Frame();
1407
		
1408
		$type = $this->right->getType();
1409
		if ($type->getRow())
1410
		{
1411
			$icon->setCanvasOptions($icon->Options()->width(20,'px')->height(20,'px')->backgroundColor('#'.$type->color));
1412
		} else {
1413
			$icon = null;
1414
		}
1415
		$this->addItem($W->HBoxItems($icon, $W->Title($this->right->description, 2))->setHorizontalSpacing(.5,'em')->setVerticalAlign('middle'));
1416
		
1417
		
1418
		$this->addItem($W->HBoxItems(
1419
				$col1 = $W->VBoxLayout()->setVerticalSpacing(.2,'em'),
1420
				$col2 = $W->VBoxLayout()->setVerticalSpacing(.2,'em')
1421
		)->setHorizontalSpacing(3,'em'));
1422
		
1423
		
1424
		$col1->addItem(
1425
				$this->titledLabel(
1426
						absences_translate('Right kind'),
1427
						$this->right->getKindLabel()
1428
				)
1429
		);
1430
		
1431
		if ($type->getRow())
1432
		{
1433
			$col1->addItem(
1434
					$this->titledLabel(
1435
							absences_translate('Type'),
1436
							$this->right->getType()->name
1437
					)
1438
			);
1439
		}
1440
		
1441
		if (absences_Right::CET !== $this->right->getKind())
1442
		{
1443
			$col1->addItem(
1444
					$this->titledLabel(
1445
							absences_translate('Quantity'),
1446
							absences_quantity($this->right->quantity, $this->right->quantity_unit)
1447
					)
1448
			);
1449
		}
1450
		
1451
		
1452
		if (absences_Right::INCREMENT === $this->right->getKind())
1453
		{
1454
		    $col1->addItem(
1455
		        $this->titledLabel(
1456
		            absences_translate('Quantity to add each month'),
1457
		            absences_quantity($this->right->quantity_inc_month, $this->right->quantity_unit)
1458
		        )
1459
		    );
1460
		    
1461
		    
1462
		    $col1->addItem(
1463
		        $this->titledLabel(
1464
		            absences_translate('Do not increment more than'),
1465
		            absences_quantity($this->right->quantity_inc_max, $this->right->quantity_unit)
1466
		        )
1467
		    );
1468
		    
1469
		    
1470
		    $col1->addItem(
1471
		        $this->titledLabel(
1472
		            absences_translate('Additional quantity by monthly updates'),
1473
		            '+'.absences_quantity($this->right->getIncrementQuantity(), $this->right->quantity_unit)
1474
		        )
1475
		    );
1476
		    
1477
		    
1478
		}
1479
		
1480
		
1481
		$col1->addItem(
1482
				$this->titledLabel(
1483
						absences_translate('Status'),
1484
						$this->right->getStatus()
1485
				)
1486
		);
1487
		
1488
		
1489
		if ($this->right->renewal_parent) {
1490
		    
1491
		    $parent = new absences_Right($this->right->renewal_parent);
1492
		    $addon = bab_getAddonInfosInstance('absences');
1493
		    
1494
    		$col1->addItem(
1495
    		    $W->FlowItems(
1496
    		        $W->Label(absences_translate('Previous right in the renewal history'))->colon()->addClass('widget-strong'),
1497
    		        $W->Link($parent->description, $addon->getUrl().'vacadma&idx=viewvr&idvr='.$parent->id)
1498
    		    )->addClass('widget-small')->setSpacing(.2,'em', .3,'em')
1499
    		);
1500
		}
1501
		
1502
		
1503
		
1504
		$col2->addItem(
1505
				$this->titledLabel(
1506
						absences_translate('Author'),
1507
						bab_getUserName($this->right->id_creditor)
1508
				)
1509
		);
1510
		
1511
		
1512
		if ('0000-00-00 00:00:00' !== $this->right->createdOn) {
1513
    		$col2->addItem(
1514
    		    $this->titledLabel(
1515
    		        absences_translate('Creation date'),
1516
    		        bab_shortDate(bab_mktime($this->right->createdOn), false)
1517
    		    )
1518
    		);
1519
		}
1520
		
1521
		
1522
		$col2->addItem(
1523
			$this->titledLabel(
1524
				absences_translate('Last modification date'),
1525
				bab_shortDate(bab_mktime($this->right->date_entry), false)
1526
			)
1527
		);
1528
		
1529
		
1530
		if ($theoretical_period = $this->getTheoreticalPeriod())
1531
		{
1532
			$col2->addItem($theoretical_period);
1533
		}
1534
		
1535
		
1536
		if ($fixed_period = $this->getFixedPeriod())
1537
		{
1538
			$col2->addItem($fixed_period);
1539
		}
1540
		
1541
		
1542
		// CET
1543
		$rightCet = $this->right->getRightCet();
1544
		if ($rightCet->getRow())
1545
		{
1546
			if ($p = $this->getSavingPeriod($rightCet))
1547
			{
1548
				$col1->addItem($p);
1549
			}
1550
			
1551 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...
1552
			{
1553
				$col2->addItem(
1554
					$this->titledLabel(
1555
						absences_translate('Maximum savings per year'),
1556
						sprintf(absences_translate('%s days'), $rightCet->per_year)
1557
					)
1558
				);
1559
			}
1560
			
1561
			
1562 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...
1563
			{
1564
				$col2->addItem(
1565
					$this->titledLabel(
1566
						absences_translate('Maximum savings in the account saving time'),
1567
						sprintf(absences_translate('%s days'), $rightCet->ceiling)
1568
					)
1569
				);
1570
			}
1571
			
1572
			// TODO others CET fields
1573
1574
1575
		}
1576
		
1577
		
1578
		
1579
		
1580
		
1581
		
1582
	}
1583
	
1584
	
1585
	
1586
	
1587
	protected function getPeriod($begin, $end, $hours = true)
1588
	{
1589
		return sprintf(
1590
			absences_translate('from %s to %s'), 
1591
			bab_shortDate(bab_mktime($begin), $hours), 
1592
			bab_shortDate(bab_mktime($end), $hours)
1593
		);
1594
	}
1595
	
1596
	
1597
	protected function getTheoreticalPeriod()
1598
	{
1599
		if ('0000-00-00' === $this->right->date_begin || '0000-00-00' === $this->right->date_end)
1600
		{
1601
			return null;
1602
		}
1603
		
1604
		
1605
		return $this->titledLabel(
1606
			absences_translate('Theoretical period'),
1607
			$this->getPeriod($this->right->date_begin, $this->right->date_end, false)
1608
		);
1609
	}
1610
	
1611
	
1612
	protected function getFixedPeriod()
1613
	{
1614
		if (absences_Right::FIXED !== $this->right->getKind())
1615
		{
1616
			return null;
1617
		}
1618
		
1619
		return $this->titledLabel(
1620
			absences_translate('Fixed right period'),
1621
			$this->getPeriod($this->right->date_begin_fixed, $this->right->date_end_fixed)
1622
		);
1623
	}
1624
	
1625
	
1626
	
1627
	protected function sync()
1628
	{
1629
		$W = bab_Widgets();
1630
1631
		if (0 === $this->right->getSyncStatus())
1632
		{
1633
			return null;
1634
		}
1635
		
1636
		
1637
		
1638
		if (absences_Right::SYNC_SERVER !== $this->right->getSyncStatus())
1639
		{
1640
			$frame = $W->Frame(null, $W->VBoxLayout()->setVerticalSpacing(.5,'em'))->addClass('widget-bordered');
1641
			$frame->addItem($W->Title(sprintf(absences_translate('Shared right from %s'), absences_getVacationOption('sync_url')), 5));
1642
			$frame->addItem($W->Label($this->right->getSyncStatusLabel()));
1643
			$frame->addItem($this->titledLabel(absences_translate('Last update'), bab_shortDate(bab_mktime($this->right->sync_update))));
1644
			
1645
			return $frame;
1646
			
1647
		} else {
1648
			
1649
			return $W->Label($this->right->getSyncStatusLabel());
1650
		}
1651
	}
1652
	
1653
	
1654
	protected function conditions()
1655
	{
1656
		$W = bab_Widgets();
1657
		$cond = $this->right->getAccessConditions();
1658
		
1659
		if (null === $cond)
1660
		{
1661
			return null;
1662
		}
1663
		
1664
		return $W->RichText($cond);
1665
	}
1666
	
1667
	
1668
	
1669
	
1670
	
1671
	/**
1672
	 * 
1673
	 * @param absences_CollectionIterator $collections
1674
	 */
1675
	protected function getCollectionsTable($collections)
1676
	{
1677
		$W = bab_Widgets();
1678
		$table = $W->VBoxLayout()->setVerticalSpacing(.5,'em');
1679
		
1680
		foreach($collections as $collection)
1681
		{
1682
			$table->addItem($W->Label($collection->name));
1683
		}
1684
		
1685
		return $table;
1686
	}
1687
	
1688
	
1689
	protected function getSavingPeriod($rightCet)
1690
	{
1691
		if ('0000-00-00' === $rightCet->saving_begin || '0000-00-00' === $rightCet->saving_end)
1692
		{
1693
			return null;
1694
		}
1695
	
1696
	
1697
		return $this->titledLabel(
1698
				absences_translate('Saving period'),
1699
				$this->getPeriod($rightCet->saving_begin, $rightCet->saving_end, false)
1700
		);
1701
	}
1702
1703
}
1704
1705
1706
1707
1708
1709
1710
class absences_RightFullFrame extends absences_RightCardFrame
1711
{
1712
	
1713
	protected function initClasses()
1714
	{
1715
		$this->addClass('absences-right-fullframe');
1716
		$this->addClass(Func_Icons::ICON_LEFT_16);
1717
		
1718
		$this->addClass('widget-bordered');
1719
		$this->addClass('BabLoginMenuBackground');
1720
		$this->addClass('widget-centered');
1721
		
1722
		$this->setCanvasOptions($this->Options()->width(70,'em'));
1723
	
1724
	}
1725
	
1726
	
1727
	protected function loadPage()
1728
	{
1729
		$this->initClasses();
1730
		$W = bab_Widgets();
1731
	
1732
		$this->addColHead();
1733
		
1734
		if ($sync = $this->sync())
1735
		{
1736
			$this->addItem($sync);
1737
		}
1738
	
1739
	
1740
		if ($conditions = $this->conditions())
1741
		{
1742
			$this->addItem($conditions);
1743
		}
1744
	
1745
		if ($beneficiaries = $this->beneficiaries())
1746
		{
1747
			$this->addItem($beneficiaries);
1748
		}
1749
		
1750
		if ($alert = $this->alert())
1751
		{
1752
			$this->addItem($alert);
1753
		}
1754
		
1755
		if ($dynconf = $this->dynamic_configuration())
1756
		{
1757
			$this->addItem($dynconf);
1758
		}
1759
		
1760
		$addon = bab_getAddonInfosInstance('absences');
1761
		$this->addItem($W->Link(
1762
		    $W->Icon(absences_translate('Create a new right from this one'), Func_Icons::ACTIONS_LIST_ADD), 
1763
		    $addon->getUrl().'vacadma&idx=addvr&from='.$this->right->id
1764
		));
1765
	}
1766
	
1767
	
1768
	
1769
	protected function beneficiaries()
1770
	{
1771
		$W = bab_Widgets();
1772
		$vbox = $W->VBoxLayout();
1773
	
1774
		$coll_section = $W->Section(absences_translate('Collections'), $coll_layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em'))->setFoldable(true, false);
1775
		$vbox->addItem($coll_section);
1776
	
1777
		$collections = $this->right->getCollectionIterator();
1778
	
1779
		if ($collections->count() == 0)
1780
		{
1781
			$coll_layout->addItem($W->Label(absences_translate('No collections associated to this right')));
1782
		}
1783
		else if ($collections->count() < 20)
1784
		{
1785
			$coll_layout->addItem($this->getCollectionsTable($collections));
1786
		} else {
1787
			$coll_layout->addItem($W->Label(sprintf(absences_translate('%d collections'), $collections->count())));
1788
		}
1789
	
1790
		$button = $W->Button()->addItem($W->Label(absences_translate('Edit beneficiaries collections'))->addClass('widget-small'));
1791
		$coll_layout->addItem($W->Link($button, absences_addon()->getUrl().'vacadma&idx=lvrc&idvr='.$this->right->id)->setSizePolicy(Widget_SizePolicy::MINIMUM));
1792
		$coll_layout->setCanvasOptions($coll_layout->Options()->width(100, '%'));
1793
	
1794
	
1795
		$a_section = $W->Section(absences_translate('Agents'), $a_layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em'))->setFoldable(true, false);
1796
		$vbox->addItem($a_section);
1797
	
1798
		$agents = $this->right->getAgentIterator();
1799
	
1800
		if ($agents->count() == 0)
1801
		{
1802
			$a_layout->addItem($W->Label(absences_translate('No users associated to this right')));
1803
		}
1804
		else {
1805
			$a_layout->addItem($stat_layout = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
1806
	
1807
	
1808
			$stat_layout->addItem($W->Label(sprintf(absences_translate('%d associated users'), $agents->count())));
1809
	
1810
			$stats = $this->right->getAgentUsage();
1811
	
1812
			$stat_layout->addItem(
1813
					$this->titledLabel(
1814
							absences_translate('Total unused quantity'),
1815
							$stats['available']
1816
					)
1817
			);
1818
	
1819
			$stat_layout->addItem(
1820
					$this->titledLabel(
1821
							absences_translate('Total waiting quantity (approbation ongoing)'),
1822
							$stats['waiting']
1823
					)
1824
			);
1825
	
1826
			$stat_layout->addItem(
1827
					$this->titledLabel(
1828
							absences_translate('Agents with remaining rights'),
1829
							$stats['agents']
1830
					)
1831
			);
1832
	
1833
			/*
1834
			 $stat_layout->addItem(
1835
			 		$this->titledLabel(
1836
			 				absences_translate('agents with remaining rights (without unconfirmed requests)'),
1837
			 				$stats['agents_iu']
1838
			 		)
1839
			 );
1840
			*/
1841
		}
1842
	
1843
		$button = $W->Button()->addItem($W->Label(absences_translate('Edit beneficiaries agents'))->addClass('widget-small'));
1844
		$a_layout->addItem($W->Link($button, absences_addon()->getUrl().'vacadma&idx=lvrp&idvr='.$this->right->id)->setSizePolicy(Widget_SizePolicy::MINIMUM));
1845
	
1846
		$a_layout->setCanvasOptions($a_layout->Options()->width(100, '%'));
1847
	
1848
		return $vbox;
1849
	}
1850
	
1851
	
1852
	/**
1853
	 * Liste des agents concernes par lalerte configuree
1854
	 * @return Widget_Displayable_Interface
1855
	 */
1856
	public function alert()
1857
	{
1858
		$W = bab_Widgets();
1859
		
1860
		$types = $this->right->getQuantityAlertTypes();
1861
		
1862
		if (empty($types))
1863
		{
1864
			return null;
1865
		}
1866
		
1867
		$section = $W->Section(absences_translate('Alert depending on the consumed quantity'), $hbox = $W->HBoxLayout())->setFoldable(true);
1868
		
1869
		$hbox->addItem($vbox = $W->VBoxLayout()->setVerticalSpacing(1, 'em'));
1870
		
1871
		$vbox->addItem($this->titledLabel(
1872
			absences_translate('Consumed quantity on types'),
1873
			$types
1874
		));
1875
		
1876
		
1877
		$vbox->addItem($this->titledLabel(
1878
			absences_translate('Consumed quantity on period'),
1879
			$this->getPeriod($this->right->quantity_alert_begin, $this->right->quantity_alert_end, false)
1880
		));
1881
		
1882
		$vbox->addItem($this->titledLabel(
1883
				absences_translate('Consumed quantity limit'),
1884
				absences_quantity($this->right->quantity_alert_days, 'D')
1885
		));
1886
		
1887
		$I = $this->right->getAgentRightIterator();
1888
		
1889
		$table = $W->BabTableView();
1890
		
1891
		$row = 0;
1892
		$table->addHeadRow($row);
1893
		
1894
		$table->addItem($W->Label(absences_translate('Beneficiary with alert')), $row, 0);
1895
		$table->addItem($W->Label(absences_translate('Quantity')), $row, 1);
1896
		$row++;
1897
		
1898
		$quantity_alert_days = (float) $this->right->quantity_alert_days;
1899
		
1900
		foreach($I as $agentRight)
1901
		{
1902
			/*@var $agentRight absences_AgentRight */
1903
			$qte = $agentRight->getQuantityAlertConsumed();
1904
			
1905
			if ($qte > $quantity_alert_days)
1906
			{
1907
				$table->addItem($W->Link($agentRight->getAgent()->getName(), absences_addon()->getUrl().'vacadm&idx=agentright&ar='.$agentRight->id), $row, 0);
1908
				$table->addItem($W->Label(absences_quantity(round($qte, 2), 'D')), $row, 1);
1909
				$row++;
1910
			}
1911
			
1912
			
1913
		}
1914
		
1915
		$vbox->setSizePolicy('widget-50pc');
1916
		$table->setSizePolicy('widget-50pc');
1917
		
1918
		$hbox->addItem($table);
1919
		
1920
		return $section;
1921
	}
1922
	
1923
	
1924
	
1925
	
1926
	/**
1927
	 * afficher la configuration des soldes dynamiques
1928
	 */
1929
	public function dynamic_configuration()
1930
	{
1931
		$I = $this->right->getDynamicConfigurationIterator();
1932
		
1933
		if (0 === $I->count())
1934
		{
1935
			return null;
1936
		}
1937
		
1938
		
1939
		$W = bab_Widgets();
1940
		$section = $W->Section(absences_translate('Quantity modification depending on the consumed number of days'), $hbox = $W->HBoxLayout())->setFoldable(true);
1941
		
1942
		$hbox->addItem($vbox = $W->VBoxLayout()->setVerticalSpacing(1, 'em'));
1943
		
1944
		$vbox->addItem($this->titledLabel(
1945
			absences_translate('Consumed quantity on period'),
1946
			$this->getPeriod($this->right->dynconf_begin, $this->right->dynconf_end, false)
1947
		));
1948
		
1949
		
1950
		
1951
		$vbox->addItem($this->titledLabel(
1952
				absences_translate('Consumed quantity on types'),
1953
				implode(', ',$this->right->getDynamicTypes())
1954
		));
1955
		
1956
1957
		$table = $W->BabTableView();
1958
		
1959
		$row = 0;
1960
		$table->addHeadRow($row);
1961
		
1962
		$table->addItem($W->Label(absences_translate('Quantity limit')), $row, 0);
1963
		$table->addItem($W->Label(absences_translate('Quantity modification')), $row, 1);
1964
		$row++;
1965
		
1966
		foreach($I as $dynamic_configuration)
1967
		{
1968
			$table->addItem($W->Label(absences_quantity($dynamic_configuration->test_quantity, 'D')), $row, 0);
1969
			$table->addItem($W->Label(absences_quantity($dynamic_configuration->quantity, $this->right->quantity_unit)), $row, 1);
1970
			$row++;
1971
		}
1972
		
1973
		$hbox->addItem($table);
1974
		
1975
		$vbox->setSizePolicy('widget-50pc');
1976
		$table->setSizePolicy('widget-50pc');
1977
		
1978
		
1979
		return $section;
1980
	}
1981
}
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
class absences_RightMovementList extends absences_MovementList
1997
{
1998
1999
    public function __construct(absences_Right $right)
2000
    {
2001
        parent::__construct();
2002
        
2003
        $this->res = $right->getMovementIterator();
2004
        $this->res->rewind();
2005
2006
        $this->paginate($this->res->count(), self::MAX);
2007
        $this->res->seek($this->pos);
2008
    }
2009
2010
}
2011
2012