|
1
|
|
|
<?php |
|
2
|
|
|
/************************************************************************ |
|
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
|
4
|
|
|
************************************************************************ |
|
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
|
6
|
|
|
* * |
|
7
|
|
|
* This file is part of Ovidentia. * |
|
8
|
|
|
* * |
|
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
|
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
|
12
|
|
|
* any later version. * |
|
13
|
|
|
* * |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
|
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
|
17
|
|
|
* See the GNU General Public License for more details. * |
|
18
|
|
|
* * |
|
19
|
|
|
* You should have received a copy of the GNU General Public License * |
|
20
|
|
|
* along with this program; if not, write to the Free Software * |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
|
22
|
|
|
* USA. * |
|
23
|
|
|
************************************************************************/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
require_once dirname(__FILE__).'/record.class.php'; |
|
28
|
|
|
require_once dirname(__FILE__).'/right.class.php'; |
|
29
|
|
|
require_once dirname(__FILE__).'/collection.class.php'; |
|
30
|
|
|
|
|
31
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/iterator/iterator.php'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* A vacation right linked to a collection |
|
35
|
|
|
* |
|
36
|
|
|
*/ |
|
37
|
|
|
class absences_CollectionRight extends absences_Record |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
private $collection; |
|
41
|
|
|
|
|
42
|
|
|
private $right; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create absences_CollectionRight |
|
47
|
|
|
* @param int $id |
|
48
|
|
|
* @return absences_CollectionRight |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function getById($id) |
|
51
|
|
|
{ |
|
52
|
|
|
$collectionRight = new absences_CollectionRight; |
|
53
|
|
|
$collectionRight->id = $id; |
|
54
|
|
|
|
|
55
|
|
|
return $collectionRight; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
View Code Duplication |
public function getRow() |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
if (null === $this->row) |
|
67
|
|
|
{ |
|
68
|
|
|
global $babDB; |
|
69
|
|
|
|
|
70
|
|
|
if (isset($this->id)) |
|
71
|
|
|
{ |
|
72
|
|
|
$res = $babDB->db_query('SELECT * FROM absences_coll_rights WHERE id='.$babDB->quote($this->id)); |
|
73
|
|
|
$this->setRow($babDB->db_fetch_assoc($res)); |
|
74
|
|
|
|
|
75
|
|
|
} else if (isset($this->collection) && isset($this->right)) |
|
76
|
|
|
{ |
|
77
|
|
|
$res = $babDB->db_query('SELECT * FROM absences_coll_rights WHERE id_coll='.$babDB->quote($this->collection->id).' AND id_right='.$babDB->quote($this->right->id)); |
|
78
|
|
|
$this->setRow($babDB->db_fetch_assoc($res)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->row; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
* @param absences_Collection $collection |
|
88
|
|
|
* @return absences_CollectionRight |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setCollection(absences_Collection $collection) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->collection = $collection; |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* |
|
98
|
|
|
* @param absences_Right $right |
|
99
|
|
|
* @return absences_CollectionRight |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setRight(absences_Right $right) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->right = $right; |
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return absences_Right |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getRight() |
|
112
|
|
|
{ |
|
113
|
|
|
if (!isset($this->right)) |
|
114
|
|
|
{ |
|
115
|
|
|
$row = $this->getRow(); |
|
116
|
|
|
$this->right = new absences_Right($row['id_right']); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $this->right; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return absences_Collection |
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
public function getCollection() |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
if (!isset($this->collection)) |
|
128
|
|
|
{ |
|
129
|
|
|
$row = $this->getRow(); |
|
130
|
|
|
$this->collection = absences_Collection::getById($row['id_coll']); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $this->collection; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
|
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.