-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserAttributesRolesController.php
More file actions
145 lines (126 loc) · 3.77 KB
/
UserAttributesRolesController.php
File metadata and controls
145 lines (126 loc) · 3.77 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
<?php
/**
* UserAttributesRoles Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('UserRolesAppController', 'UserRoles.Controller');
/**
* UserAttributesRoles Controller
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\UserRoles\Controller
*/
class UserAttributesRolesController extends UserRolesAppController {
/**
* 「他人の会員情報を閲覧させない」定数
*
* @var const
*/
const OTHER_NOT_READABLE = 'other_not_readable';
/**
* 「他人の会員情報を閲覧させる」定数
*
* @var const
*/
const OTHER_READABLE = 'other_readable';
/**
* 「他人の会員情報を編集させる」定数
*
* @var const
*/
const OTHER_EDITABLE = 'other_editable';
/**
* use components
*
* @var array
*/
public $components = array(
'UserAttributes.UserAttributeLayout',
);
/**
* use model
*
* @var array
*/
public $uses = array(
'PluginManager.Plugin',
'UserRoles.UserAttributesRole',
'UserRoles.UserRole',
'UserRoles.UserRoleSetting',
);
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'UserAttributes.UserAttributeLayout',
);
/**
* edit
*
* @param string $roleKey user_roles.key
* @return void
*/
public function edit($roleKey = null) {
if ($this->request->is('put')) {
if (! Hash::get($this->request->data, 'UserAttributesRole')) {
return $this->throwBadRequest();
}
//不要パラメータ除去
unset($this->request->data['save']);
//リクエストの整形
$ids = array_keys($this->request->data['UserAttributesRole']);
foreach ($ids as $id) {
$otherRole = Hash::get($this->request->data,
'UserAttributesRole.' . $id . '.UserAttributesRole.other_user_attribute_role', false);
if ($otherRole === false) {
$this->request->data = Hash::remove($this->request->data, 'UserAttributesRole.' . $id);
continue;
}
if (! in_array($otherRole, [self::OTHER_READABLE, self::OTHER_NOT_READABLE], true)) {
return $this->throwBadRequest();
}
$this->request->data['UserAttributesRole'][$id]['UserAttributesRole']['other_readable'] = false;
$this->request->data['UserAttributesRole'][$id]['UserAttributesRole']['other_editable'] = false;
if ($otherRole === self::OTHER_READABLE) {
$this->request->data['UserAttributesRole'][$id]['UserAttributesRole']['other_readable'] = true;
}
}
//登録処理
if ($this->UserAttributesRole->saveUserAttributesRoles($this->request->data)) {
//正常の場合
$this->NetCommons->setFlashNotification(
__d('net_commons', 'Successfully saved.'), array('class' => 'success')
);
$this->redirect('/user_roles/user_roles/index/');
} else {
$this->NetCommons->handleValidationError($this->UserAttributesRole->validationErrors);
$this->redirect('/user_roles/user_attributes_roles/edit/' . h($roleKey));
}
} else {
//既存データ取得
$this->request->data = $this->UserRoleSetting->getUserRoleSetting(
Plugin::PLUGIN_TYPE_FOR_SITE_MANAGER, $roleKey
);
$this->request->data['UserAttributesRole'] =
$this->UserAttributesRole->getUserAttributesRole($roleKey);
$this->request->data['UserAttribute'] = $this->viewVars['userAttributes'];
$userRole = $this->UserRole->find('first', array(
'recursive' => -1,
'conditions' => array(
'key' => $roleKey,
'language_id' => Current::read('Language.id')
)
));
$this->request->data = Hash::merge($userRole, $this->request->data);
$this->set('roleKey', $roleKey);
$this->set('subtitle', $this->request->data['UserRole']['name']);
}
}
}