forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRolesController.php
More file actions
146 lines (135 loc) · 3.61 KB
/
Copy pathRolesController.php
File metadata and controls
146 lines (135 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
App::uses('UsersAppController', 'Users.Controller');
/**
* Roles Controller
*
* @property Rol $Rol
*/
class RolesController extends UsersAppController {
/**
* index method
*
* @return void
*/
public function index() {
$this->Rol->recursive = 0;
$this->set('roles', $this->paginate());
}
/**
* view method
*
* @param string $id
* @return void
*/
public function view($id = null) {
$this->Rol->id = $id;
if (!$this->Rol->exists()) {
throw new NotFoundException(__('Invalid rol'));
}
$this->set('rol', $this->Rol->read(null, $id));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->Rol->create();
if ($this->Rol->save($this->request->data)) {
$this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success');
$this->redirect($this->referer());
} else {
$this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error');
}
}
$roles_machine_names = $this->Rol->find('list', array(
'recursive' => -1,
'fields' => array(
'machin_name',
'name'
),
'conditions' => array(
'machin_name !=' => ROL_DUENIO
),
'order' => array(
'Rol.created' => 'DESC'
)));
$this->set('roles_machine_names', $roles_machine_names);
$this->render('edit');
}
/**
* edit method
*
* @param string $id
* @return void
*/
public function edit($id = null) {
$this->Rol->id = $id;
if (!$this->Rol->exists()) {
throw new NotFoundException(__('Invalid rol'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Rol->save($this->request->data)) {
$this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error');
}
} else {
$this->request->data = $this->Rol->read(null, $id);
}
$roles_machine_names = $this->Rol->find('list', array(
'recursive' => -1,
'fields' => array(
'machin_name',
'name'
),
'conditions' => array(
'machin_name !=' => ROL_DUENIO
),
'order' => array(
'Rol.created' => 'DESC'
)));
$this->set('roles_machine_names', $roles_machine_names);
}
/**
* delete method
*
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->Rol->id = $id;
if (!$this->Rol->exists()) {
throw new NotFoundException(__('Invalid Rol Id'));
}
if ($this->Rol->delete($id, true)) {
$this->Rol->GenericUser->deleteAll(array('GenericUser.rol_id' => $id));
$this->Session->setFlash(__('Usuario Generico Borrado'),'Risto.flash_success');
$this->redirect($this->referer());
} else {
$this->Session->setFlash(__('Error: Usuario Generico No pudo ser borrado'),'Risto.flash_error');
}
$this->redirect(array('action' => 'index'));
}
public function edit_for_user( $userId ) {
$this->Rol->User->id = $userId;
if (!$this->Rol->User->exists()) {
throw new NotFoundException(__('Invalid User'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Rol->RolUser->asignarRol($this->request->data)) {
$this->Session->setFlash(__('The rol has been saved'),'Risto.flash_success');
$this->redirect($this->referer());
} else {
$this->Session->setFlash(__('The rol could not be saved. Please, try again.'),'Risto.flash_error');
}
} else {
$this->Rol->User->contain(array('Rol'));
$user = $this->Rol->User->read();
$this->request->data = $user;
}
$this->set('roles', $this->Rol->find("list"));
}
}