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__).'/record.class.php'; |
26
|
|
|
require_once dirname(__FILE__).'/right.class.php'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Abscence Right |
30
|
|
|
* |
31
|
|
|
* @property int $id_right |
32
|
|
|
* @property string $saving_begin |
33
|
|
|
* @property string $saving_end |
34
|
|
|
* @property float $per_year |
35
|
|
|
* @property float $per_cet |
36
|
|
|
* @property float $ceiling |
37
|
|
|
* @property float $min_use |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
class absences_RightCet extends absences_Record |
41
|
|
|
{ |
42
|
|
|
private $right; |
43
|
|
|
|
44
|
|
|
private $id_right; |
45
|
|
|
|
46
|
|
|
public static function getFromId($id) |
47
|
|
|
{ |
48
|
|
|
$rightcet = new absences_RightCet; |
49
|
|
|
$rightcet->id = $id; |
50
|
|
|
return $rightcet; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function getFromRight($id_right) |
54
|
|
|
{ |
55
|
|
|
$rightcet = new absences_RightCet; |
56
|
|
|
$rightcet->id_right = $id_right; |
57
|
|
|
return $rightcet; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function getRow() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
if (null === $this->row) |
67
|
|
|
{ |
68
|
|
|
if (!isset($this->id) && !isset($this->id_right)) |
69
|
|
|
{ |
70
|
|
|
$this->row = false; |
|
|
|
|
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
global $babDB; |
75
|
|
|
|
76
|
|
|
$query = 'SELECT * FROM absences_rights_cet WHERE '; |
77
|
|
|
|
78
|
|
|
if (isset($this->id)) |
79
|
|
|
{ |
80
|
|
|
$query .= 'id='.$babDB->quote($this->id); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($this->id_right)) |
84
|
|
|
{ |
85
|
|
|
$query .= 'id_right='.$babDB->quote($this->id_right); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$res = $babDB->db_query($query); |
89
|
|
|
$this->setRow($babDB->db_fetch_assoc($res)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->row; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* |
97
|
|
|
* @param absences_Right $right |
98
|
|
|
* @return absences_RightCet |
99
|
|
|
*/ |
100
|
|
|
public function setRight(absences_Right $right) |
101
|
|
|
{ |
102
|
|
|
$this->right = $right; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return absences_Right |
108
|
|
|
*/ |
109
|
|
|
public function getRight() |
110
|
|
|
{ |
111
|
|
|
if (!isset($this->right)) |
112
|
|
|
{ |
113
|
|
|
$row = $this->getRow(); |
114
|
|
|
$this->right = new absences_Right($row['id_right']); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->right; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
View Code Duplication |
public function insert() |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
global $babDB; |
126
|
|
|
|
127
|
|
|
$babDB->db_query('INSERT INTO absences_rights_cet |
128
|
|
|
( |
129
|
|
|
id_right, |
130
|
|
|
saving_begin, |
131
|
|
|
saving_end, |
132
|
|
|
per_year, |
133
|
|
|
per_cet, |
134
|
|
|
ceiling, |
135
|
|
|
min_use |
136
|
|
|
) |
137
|
|
|
VALUES |
138
|
|
|
( |
139
|
|
|
'.$babDB->quote($this->id_right).', |
140
|
|
|
'.$babDB->quote($this->saving_begin).', |
141
|
|
|
'.$babDB->quote($this->saving_end).', |
142
|
|
|
'.$babDB->quote($this->per_year).', |
143
|
|
|
'.$babDB->quote($this->per_cet).', |
144
|
|
|
'.$babDB->quote($this->ceiling).', |
145
|
|
|
'.$babDB->quote($this->min_use).' |
146
|
|
|
) |
147
|
|
|
'); |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
$this->id = $babDB->db_insert_id(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
|
155
|
|
View Code Duplication |
public function update() |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
global $babDB; |
158
|
|
|
|
159
|
|
|
$babDB->db_query('UPDATE absences_rights_cet SET |
160
|
|
|
|
161
|
|
|
saving_begin = '.$babDB->quote($this->saving_begin).', |
162
|
|
|
saving_end = '.$babDB->quote($this->saving_end).', |
163
|
|
|
per_year = '.$babDB->quote($this->per_year).', |
164
|
|
|
per_cet = '.$babDB->quote($this->per_cet).', |
165
|
|
|
ceiling = '.$babDB->quote($this->ceiling).', |
166
|
|
|
min_use = '.$babDB->quote($this->min_use).' |
167
|
|
|
|
168
|
|
|
WHERE id_right = '.$babDB->quote($this->id_right) |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
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.