|
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) 2009 by CANTICO ({@link http://www.cantico.fr}) |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The app_AccessManager class |
|
29
|
|
|
* |
|
30
|
|
|
* @method Func_App App() |
|
31
|
|
|
*/ |
|
32
|
|
|
class app_AccessManager implements app_Object_Interface |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var Func_App |
|
36
|
|
|
*/ |
|
37
|
|
|
private $app = null; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param Func_App $app |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(Func_App $app) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->setApp($app); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Forces the Func_App object to which this object is 'linked'. |
|
50
|
|
|
* |
|
51
|
|
|
* @param Func_App $app |
|
52
|
|
|
* @return self |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setApp(Func_App $app) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->app = $app; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get APP object to use with this SET |
|
62
|
|
|
* |
|
63
|
|
|
* @return Func_App |
|
64
|
|
|
*/ |
|
65
|
|
|
public function App() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->app; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* |
|
73
|
|
|
* @param app_RecordSet $recordSet |
|
74
|
|
|
* @param string $accessType |
|
75
|
|
|
* @param int $user |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getAccessCriterion(app_RecordSet $recordSet, $accessType, $user = null) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
return $recordSet->none(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Check if at least one access criterion is not a FalseCriterion. |
|
85
|
|
|
* |
|
86
|
|
|
* If all access criterion are FalseCritertion, return true, otherwise return false. |
|
87
|
|
|
* |
|
88
|
|
|
* @param app_RecordSet $recordSet |
|
89
|
|
|
* @param string $accessType |
|
90
|
|
|
* @param int|null $user |
|
91
|
|
|
* |
|
92
|
|
|
* @return boolean |
|
93
|
|
|
*/ |
|
94
|
|
|
public function hasNoAccess(app_RecordSet $recordSet, $accessType, $user = null) |
|
95
|
|
|
{ |
|
96
|
|
|
$criterion = $this->getAccessCriterion($recordSet, $accessType, $user); |
|
97
|
|
|
if (! $criterion instanceof ORM_FalseCriterion) { |
|
|
|
|
|
|
98
|
|
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
return true; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* |
|
106
|
|
|
* @param app_Record $record |
|
107
|
|
|
* @param string $accessType |
|
108
|
|
|
* @param int $user |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getAccess(app_Record $record, $accessType, $user = null) |
|
111
|
|
|
{ |
|
112
|
|
|
$recordSet = $record->getParentSet(); |
|
113
|
|
|
$criterion = $this->getAccessCriterion($recordSet, $accessType, $user); |
|
114
|
|
|
|
|
115
|
|
|
$matches = $recordSet->select($criterion->_AND_($recordSet->id->is($record->id))); |
|
116
|
|
|
|
|
117
|
|
|
return ($matches->count() !== 0); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.