forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetails_controller.php
More file actions
214 lines (196 loc) · 4.88 KB
/
Copy pathdetails_controller.php
File metadata and controls
214 lines (196 loc) · 4.88 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* Copyright 2010, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Users Details Controller
*
* @package users
* @subpackage users.controllers
*/
class DetailsController extends UsersAppController {
/**
* Name
*
* @var string
*/
public $name = 'Details';
/**
* Helpers
*
* @var array
*/
public $helpers = array('Html', 'Form');
/**
* Index
*
* @return void
*/
public function index() {
$details = $this->Detail->find('all', array(
'contain' => array(),
'conditions' => array(
'Detail.user_id' => $this->Auth->user('id'),
'Detail.field LIKE' => 'user.%'),
'order' => 'Detail.position DESC'));
$this->set('details', $details);
}
/**
* View
*
* @param string $id Detail ID
* @return void
*/
public function view($id = null) {
if (!$id) {
$this->Session->setFlash(__d('users', 'Invalid Detail.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('detail', $this->Detail->read(null, $id));
}
/**
* Add
*
* @return void
*/
public function add() {
if (!empty($this->data)) {
$userId = $this->Auth->user('id');
foreach($this->data as $group => $options) {
foreach($options as $key => $value) {
$field = $group . '.' . $key;
$this->Detail->updateAll(
array('Detail.value' => "'$value'"),
array('Detail.user_id' => $userId, 'Detail.field' => $field));
}
}
$this->Session->setFlash(__d('users', 'Saved', true));
}
$this->redirect(array('action' => 'index'));
}
/**
* Edit
*
* Allows a logged in user to edit his own profile settings
*
* @param string $section Section name
* @return void
*/
public function edit($section = 'user') {
if (!isset($section)) {
$section = 'user';
}
if (!empty($this->data)) {
$this->Detail->saveSection($this->Auth->user('id'), $this->data, $section);
$this->data['Detail'] = $this->Detail->getSection($this->Auth->user('id'), $section);
$this->Session->setFlash(sprintf(__d('users', '%s details saved', true), ucfirst($section)));
}
if (empty($this->data)) {
$this->data['Detail'] = $this->Detail->getSection($this->Auth->user('id'), $section);
}
$this->set('section', $section);
}
/**
* Delete
*
* @param string $id Detail ID
* @return void
*/
public function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__d('users', 'Invalid id for Detail', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Detail->delete($id)) {
$this->Session->setFlash(__d('users', 'Detail deleted', true));
$this->redirect(array('action'=>'index'));
}
}
/**
* Admin Index
*
* @return void
*/
public function admin_index() {
$this->Detail->recursive = 0;
$this->set('details', $this->paginate());
}
/**
* Admin View
*
* @param string $id Detail ID
* @return void
*/
public function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__d('users', 'Invalid Detail.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('detail', $this->Detail->read(null, $id));
}
/**
* Admin Add
*
* @return void
*/
public function admin_add() {
if (!empty($this->data)) {
$this->Detail->create();
if ($this->Detail->save($this->data)) {
$this->Session->setFlash(__d('users', 'The Detail has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.', true));
}
}
$users = $this->Detail->User->find('list');
$this->set(compact('users'));
}
/**
* Admin edit
*
* @param string $id Detail ID
* @return void
*/
public function admin_edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__d('users', 'Invalid Detail', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Detail->save($this->data)) {
$this->Session->setFlash(__d('users', 'The Detail has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__d('users', 'The Detail could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Detail->read(null, $id);
}
$users = $this->Detail->User->find('list');
$this->set(compact('users'));
}
/**
* Admin Delete
*
* @param string $id Detail ID
* @return void
*/
public function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__d('users', 'Invalid id for Detail', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Detail->delete($id)) {
$this->Session->setFlash(__d('users', 'Detail deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}