1
|
|
|
<?php |
2
|
|
|
//------------------------------------------------------------------------- |
3
|
|
|
// OVIDENTIA http://www.ovidentia.org |
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
5
|
|
|
// it under the terms of the GNU General Public License as published by |
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
7
|
|
|
// any later version. |
8
|
|
|
// |
9
|
|
|
// This program is distributed in the hope that it will be useful, but |
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
// See the GNU General Public License for more details. |
13
|
|
|
// |
14
|
|
|
// You should have received a copy of the GNU General Public License |
15
|
|
|
// along with this program; if not, write to the Free Software |
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
17
|
|
|
// USA. |
18
|
|
|
//------------------------------------------------------------------------- |
19
|
|
|
/** |
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
21
|
|
|
* @copyright Copyright (c) 2008 by CANTICO ({@link http://www.cantico.fr}) |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* save profiles list into workschedules addon |
27
|
|
|
* |
28
|
|
|
* @throws bab_SaveErrorException |
29
|
|
|
* |
30
|
|
|
* @param int $id_user |
31
|
|
|
* @param array $profiles |
32
|
|
|
* |
33
|
|
|
* @return boolean |
34
|
|
|
*/ |
35
|
|
|
function absences_setProfiles($id_user, Array $profiles) |
36
|
|
|
{ |
37
|
|
|
$babBody = bab_getBody(); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$workschedules = bab_functionality::get('WorkingHours/Workschedules'); |
40
|
|
|
/*@var $workschedules Func_WorkingHours_Workschedules */ |
41
|
|
|
|
42
|
|
|
$set = $workschedules->userProfileSet(); |
43
|
|
|
$res = $workschedules->getUserProfiles($id_user); |
44
|
|
|
$existingProfiles = array(); |
45
|
|
|
|
46
|
|
|
foreach($res as $profile) { |
47
|
|
|
$existingProfiles[$profile->id] = $profile; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$W = bab_Widgets(); |
51
|
|
|
|
52
|
|
|
foreach($profiles['userprofile'] as $position => $id) { |
53
|
|
|
if (isset($existingProfiles[$id])) { |
54
|
|
|
$record = $set->get($id); // the existing profile contain a joined record |
55
|
|
|
unset($existingProfiles[$id]); |
56
|
|
|
} else { |
57
|
|
|
$record = $set->newRecord(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$record->profile = (int) $profiles['profile'][$position]; |
61
|
|
|
|
62
|
|
|
$record->from = $W->DatePicker()->getISODate($profiles['from'][$position]); |
63
|
|
|
$record->to = $W->DatePicker()->getISODate($profiles['to'][$position]); |
64
|
|
|
|
65
|
|
|
$record->user = $id_user; |
66
|
|
|
$record->save(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
// delete unprocessed existing profiles |
71
|
|
|
|
72
|
|
|
if (count($existingProfiles) > 0) { |
73
|
|
|
$set->delete($set->id->in(array_keys($existingProfiles))); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return true; |
77
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.