3
* This file is part of Critecia
4
* Copyright (C) 2011 Christian A. Reiter
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License as
8
* published by the Free Software Foundation, either version 3 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Affero General Public License for more details.
16
* You should have received a copy of the GNU Affero General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
class AclBuilderComponent {
23
* sets up primary ACOs for a hospital into the ACL tree under the node
24
* Hospital_root/Hospital_${hospital_uuid} given as param
26
* @param string $hospital_uuid
27
* @return boolean True if all nodes were created correctly
30
public function rebuild_hospital_acos($hospital_uuid) {
32
/* if(!$this->Access->check('Hospitals/global_index')) { // for redirect afterwords!
33
$this->Session->setFlash('Krankenhäuser dürfen nicht aufgelistet werden!');
34
$this->redirect($this->referer());
37
/* if(!isset($this->params['requested'])) { //somebody called this function per browser!
38
$this->cakeError('error404');
42
debug('No hospital UUID given!');
46
App::import('Model', 'Hospital');
47
$this->Hospital = new Hospital();
48
#App::import('Model', 'Acl');
49
#$this->Acl = new Acl();
51
//make sure hospital exists in DB
52
$hospital = $this->Hospital->read(null, $hospital_uuid);
54
//TODO: proper error message!
55
debug('Could not find hospital with ID '.$hospital_uuid);
60
// shortcut to ACO object
61
$aco =& $this->Acl->Aco;
64
// parent Aco node under which all hospitals are living (Hospital_root):
65
$hospital_root_node = $aco->node('All/Hospital_root');
66
if($hospital_root_node) {
67
$hospital_root_node = $hospital_root_node[0];
72
// get current hospital's node
73
$hospital_node = $aco->node('Hospital_' . $hospital_uuid);
74
if(!$hospital_node) { // already there, delete it!
75
$aco->create(array( 'parent_id' => $hospital_root_node['Aco']['id'],
77
'alias' => 'Hospital_'.$hospital_uuid));
78
$hospital_node =$aco->save();
79
$hospital_node['Aco']['id'] = $aco->id;
81
$hospital_node = $hospital_node[0];
84
// build list of needed controllers/actions and create corresponding nodes + their actions
85
$controllers_actions = $this->Reflector->get_actions_array();
86
foreach($controllers_actions as $controller => $actions) {
88
// is there already a controller node?
89
$controllerNode = $aco->node('All/Hospital_root/Hospital_'.$hospital_uuid.'/'.$controller);
90
if (!$controllerNode) { // none found, create one
91
// create aco node for controller
92
$aco->create(array( 'parent_id' => $hospital_node['Aco']['id'],
94
'alias' => $controller));
95
$controllerNode = $aco->save();
96
$controllerNode['Aco']['id'] = $aco->id;
97
$log[] = 'Created controller node "' . $controller . '".';
99
} else { //controller node exists already in Aco tree
101
$controllerNode = $controllerNode[0];
102
$log[] = 'Controller node "' . $controller . '" exists already.';
106
foreach($actions as $i => $action) {
107
if(strpos($action,"global_", 0) === 0 ) { //is this a global controller?
112
// does action node already exist?
113
$actionNode = $aco->node('Hospital.'.$hospital_uuid.'/'.$controller.'/'.$action);
114
if (!$actionNode) { // no? create it!
115
$aco->create(array( 'parent_id' => $controllerNode['Aco']['id'],
117
'alias' => $action));
118
$actionNode = $aco->save();
119
$log[] = 'Created Aco node for "'.$controller.'/'.$action . '".';
124
if(!isset($this->params['requested'])) {
125
$this->Session->setFlash('Berechtigungen zurückgesetzt');
126
$this->redirect(array('action' => 'index'));