1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakeCMS Community |
4
|
|
|
* |
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @package Community |
10
|
|
|
* @license MIT |
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
12
|
|
|
* @link https://github.com/CakeCMS/Community". |
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Community\Controller\Admin; |
17
|
|
|
|
18
|
|
|
use Cake\Datasource\Exception\InvalidPrimaryKeyException; |
19
|
|
|
use Cake\Datasource\Exception\RecordNotFoundException; |
20
|
|
|
use Community\Model\Entity\Group; |
21
|
|
|
use Community\Model\Table\GroupsTable; |
22
|
|
|
use Core\Controller\Component\MoveComponent; |
23
|
|
|
use Core\Controller\Component\ProcessComponent; |
24
|
|
|
use Cake\ORM\Exception\RolledbackTransactionException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class GroupsController |
28
|
|
|
* |
29
|
|
|
* @package Community\Controller\Admin |
30
|
|
|
* @property GroupsTable $Groups |
31
|
|
|
* @property MoveComponent $Move |
32
|
|
|
* @property ProcessComponent $Process |
33
|
|
|
*/ |
34
|
|
|
class GroupsController extends AppController |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Edit action. |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
* |
42
|
|
|
* @throws RolledbackTransactionException |
43
|
|
|
* @throws \Aura\Intl\Exception |
44
|
|
|
*/ |
45
|
|
|
public function add() |
46
|
|
|
{ |
47
|
|
|
$group = $this->Groups->newEntity(); |
48
|
|
|
if ($this->request->is('post')) { |
49
|
|
|
$group = $this->Groups->patchEntity($group, $this->request->getData()); |
|
|
|
|
50
|
|
|
$result = $this->Groups->save($group); |
51
|
|
|
if ($result) { |
52
|
|
|
$this->Flash->success(__d('community', 'The group has been saved.')); |
53
|
|
|
return $this->App->redirect([ |
54
|
|
|
'apply' => ['action' => 'edit', $result->id], |
55
|
|
|
]); |
56
|
|
|
} else { |
57
|
|
|
$this->Flash->error(__d('community', 'The group could not be saved. Please, try again.')); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$parents = $this->Groups->getTreeList(); |
62
|
|
|
$this->set(compact('group', 'parents')); |
63
|
|
|
$this->set('page_title', __d('community', 'Add new group')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Move down group action. |
68
|
|
|
* |
69
|
|
|
* @param int $id Group id. |
70
|
|
|
* @return \Cake\Http\Response|null |
71
|
|
|
*/ |
72
|
|
|
public function down($id) |
73
|
|
|
{ |
74
|
|
|
return $this->Move->down($this->Groups, $id); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Edit action. |
79
|
|
|
* |
80
|
|
|
* @param int $id Group id. |
81
|
|
|
* @return \Cake\Http\Response|null |
82
|
|
|
* |
83
|
|
|
* @throws RecordNotFoundException |
84
|
|
|
* @throws InvalidPrimaryKeyException |
85
|
|
|
* @throws RolledbackTransactionException |
86
|
|
|
* @throws \Aura\Intl\Exception |
87
|
|
|
*/ |
88
|
|
|
public function edit($id) |
89
|
|
|
{ |
90
|
|
|
/** @var Group $group */ |
91
|
|
|
$group = $this->Groups->get($id, ['contain' => []]); |
92
|
|
View Code Duplication |
if ($this->request->is(['patch', 'post', 'put'])) { |
|
|
|
|
93
|
|
|
$group = $this->Groups->patchEntity($group, $this->request->getData()); |
|
|
|
|
94
|
|
|
if ($result = $this->Groups->save($group)) { |
95
|
|
|
$this->Flash->success(__d('community', 'The group has been updated.')); |
96
|
|
|
return $this->App->redirect([ |
97
|
|
|
'apply' => ['action' => 'edit', $result->id] |
98
|
|
|
]); |
99
|
|
|
} else { |
100
|
|
|
$this->Flash->error(__d('community', 'The group could not be updated. Please, try again.')); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$parents = $this->Groups->getTreeList(); |
105
|
|
|
$this->set(compact('group', 'parents')); |
106
|
|
|
$this->set('page_title', __d('community', 'Edit group: {0}', $group->name)); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Index action. |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
* |
114
|
|
|
* @throws \Aura\Intl\Exception |
115
|
|
|
*/ |
116
|
|
|
public function index() |
117
|
|
|
{ |
118
|
|
|
$this->set('groups', $this->Groups->getTreeList()); |
119
|
|
|
$this->set('page_title', __d('community', 'User group list')); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Initialization hook method. |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
* |
127
|
|
|
* @throws \Aura\Intl\Exception |
128
|
|
|
* @throws \JBZoo\Utils\Exception |
129
|
|
|
* @throws \Cake\Core\Exception\Exception When trying to set a key that is invalid. |
130
|
|
|
*/ |
131
|
|
|
public function initialize() |
132
|
|
|
{ |
133
|
|
|
parent::initialize(); |
134
|
|
|
|
135
|
|
|
$this->Move->setConfig('messages', [ |
136
|
|
|
'success' => __d('community', 'Group has been moved'), |
137
|
|
|
'error' => __d('community', 'Group could not been moved') |
138
|
|
|
]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Process action. |
143
|
|
|
* |
144
|
|
|
* @return \Cake\Http\Response|null |
145
|
|
|
* |
146
|
|
|
* @throws \Aura\Intl\Exception |
147
|
|
|
*/ |
148
|
|
|
public function process() |
149
|
|
|
{ |
150
|
|
|
list($action, $ids) = $this->Process->getRequestVars($this->name); |
151
|
|
|
return $this->Process->make($this->Groups, $action, $ids); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Move up group action. |
156
|
|
|
* |
157
|
|
|
* @param int $id Group id. |
158
|
|
|
* @return \Cake\Http\Response|null |
159
|
|
|
* |
160
|
|
|
* @SuppressWarnings(PHPMD.ShortMethodName) |
161
|
|
|
*/ |
162
|
|
|
public function up($id) |
163
|
|
|
{ |
164
|
|
|
return $this->Move->up($this->Groups, $id); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.