~critecia/critecia/trunk

« back to all changes in this revision

Viewing changes to src/app/controllers/components/acl_builder.php

  • Committer: Christian A. Reiter
  • Date: 2011-11-16 20:08:35 UTC
  • Revision ID: christian.a.reiter@gmail.com-20111116200835-h3xx0ekm47lububw
fixed jQuery file links

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 /**
3
 
 *    This file is part of Critecia
4
 
 *    Copyright (C) 2011 Christian A. Reiter
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
 class AclBuilderComponent {
21
 
        
22
 
 /** 
23
 
 * sets up primary ACOs for a hospital into the ACL tree under the node
24
 
 * Hospital_root/Hospital_${hospital_uuid} given as param
25
 
 * 
26
 
 * @param string $hospital_uuid
27
 
 * @return boolean True if all nodes were created correctly
28
 
 * @access public
29
 
 */
30
 
                public function rebuild_hospital_acos($hospital_uuid) {
31
 
                        // catch direct calls
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());
35
 
                        }
36
 
*/      
37
 
/*                      if(!isset($this->params['requested'])) { //somebody called this function per browser!
38
 
                                $this->cakeError('error404');
39
 
                        }*/
40
 
                
41
 
                        if(!$hospital_uuid) {
42
 
                                debug('No hospital UUID given!');
43
 
                                return false;
44
 
                        }
45
 
                        
46
 
                        App::import('Model', 'Hospital');
47
 
                        $this->Hospital = new Hospital();
48
 
                        #App::import('Model', 'Acl');
49
 
                        #$this->Acl = new Acl();
50
 
                        
51
 
                        //make sure hospital exists in DB
52
 
                        $hospital = $this->Hospital->read(null, $hospital_uuid);
53
 
                        if(!$hospital) {
54
 
                                //TODO: proper error message!
55
 
                                debug('Could not find hospital with ID '.$hospital_uuid);
56
 
                                return false;
57
 
                        }
58
 
                        $log = array();
59
 
                
60
 
                        // shortcut to ACO object
61
 
                        $aco =& $this->Acl->Aco;
62
 
                
63
 
 
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];
68
 
                        } else {
69
 
                                return false;
70
 
                        }
71
 
                
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'],
76
 
                                                                        'model' => null,
77
 
                                                                        'alias' => 'Hospital_'.$hospital_uuid));
78
 
                                $hospital_node =$aco->save();
79
 
                                $hospital_node['Aco']['id'] = $aco->id;
80
 
                        } else {
81
 
                                $hospital_node = $hospital_node[0];
82
 
                        }
83
 
                        
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) {
87
 
                        
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'],
93
 
                                                                                'model' => null, 
94
 
                                                                                'alias' => $controller));
95
 
                                        $controllerNode = $aco->save();
96
 
                                        $controllerNode['Aco']['id'] = $aco->id;
97
 
                                        $log[] = 'Created controller node "' . $controller . '".';
98
 
                        
99
 
                                } else { //controller node exists already in Aco tree
100
 
                        
101
 
                                        $controllerNode = $controllerNode[0];
102
 
                                        $log[] = 'Controller node "' . $controller . '" exists already.';
103
 
                        
104
 
                                }
105
 
 
106
 
                                foreach($actions as $i => $action) {
107
 
                                        if(strpos($action,"global_", 0) === 0 ) { //is this a global controller?
108
 
                                                // skip this action
109
 
                                                unset($actions[$i]);
110
 
                                                continue;
111
 
                                        } else {
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'],
116
 
                                                                                                'model' => null,
117
 
                                                                                                'alias' => $action));
118
 
                                                        $actionNode = $aco->save();
119
 
                                                        $log[] = 'Created Aco node for "'.$controller.'/'.$action . '".';
120
 
                                                }
121
 
                                        }
122
 
                                }
123
 
                        }
124
 
                        if(!isset($this->params['requested'])) {
125
 
                                $this->Session->setFlash('Berechtigungen zurückgesetzt');
126
 
                                $this->redirect(array('action' => 'index'));
127
 
                        }
128
 
                }
129
 
        }
130
 
 
131
 
 ?>