1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15
16 17 18
19 class UserSoldiersController extends AppController {
20
21 22 23 24 25
26 public $components = array(
27 'RequestHandler'
28 );
29
30
31
32 33 34 35 36
37 public function index() {
38 $this->redirect(array('plugin' => null, 'admin' => false, 'controller' => 'pages', 'action' => 'display', 'server' => Configure::read('server_id'), 'home'));
39 }
40
41
42
43 44 45 46 47 48 49
50 public function view($id = null) {
51 $this->UserSoldier->id = $id;
52 if (!$this->UserSoldier->exists()) {
53 throw new NotFoundException(__('Invalid user soldier'));
54 }
55 $this->set('userSoldier', $this->UserSoldier->read(null, $id));
56 }
57
58
59
60 61 62 63 64 65 66
67 public function listing($id = null) {
68 $data = $this->UserSoldier->listUserSoldiers($id);
69
70 if ($this->request->is('requested')) {
71 return $data;
72 } else {
73 $this->set('userSoldiers', $data);
74 }
75 return null;
76 }
77
78
79
80 81 82 83 84
85 public function add() {
86
87 if ($this->request->is('post')) {
88 if ($this->request->data['UserSoldier']['user_id'] == $this->user['User']['id']) {
89 $this->UserSoldier->create();
90 if ($this->UserSoldier->save($this->request->data)) {
91 $this->Session->setFlash(__('"My Soldier" has been saved'));
92 $this->redirect(array(
93 'plugin' => null,
94 'controller' => 'player_stats',
95 'action' => 'view',
96 'server' => Configure::read('server_id'),
97 $this->request->data['UserSoldier']['playerstats_id']
98 ));
99 } else {
100 $this->Session->setFlash(__('"My Soldier" could not be saved. Please, try again.'));
101 }
102 } else {
103 $this->Session->setFlash(__('User Id Invalid!'));
104 }
105 } else {
106 $this->Session->setFlash(__('Request not valid!'));
107 }
108 }
109
110
111
112 113 114 115 116 117 118
119 public function edit($id = null) {
120 $this->UserSoldier->id = $id;
121 if (!$this->UserSoldier->exists()) {
122 throw new NotFoundException(__('Invalid soldier'));
123 }
124 if ($this->request->is('post') || $this->request->is('put')) {
125 if ($this->UserSoldier->save($this->request->data)) {
126 $this->Session->setFlash(__('The soldier has been saved'));
127 $this->redirect(array('action' => 'index', 'server' => Configure::read('server_id')));
128 } else {
129 $this->Session->setFlash(__('The soldier could not be saved. Please, try again.'));
130 }
131 } else {
132 $this->request->data = $this->UserSoldier->read(null, $id);
133 }
134 }
135
136
137
138 139 140 141 142 143 144 145
146 public function delete($id = null) {
147 if (!$this->request->is('post')) {
148 throw new MethodNotAllowedException();
149 }
150 $this->UserSoldier->id = $id;
151 if (!$this->UserSoldier->exists()) {
152 throw new NotFoundException(__('Invalid user soldier'));
153 }
154
155 if ($this->UserSoldier->delete()) {
156 $this->Session->setFlash(__('Soldier deleted'));
157 $this->redirect(array(
158 'plugin' => 'users',
159 'controller' => 'users',
160 'action' => 'edit'));
161 }
162
163 $this->Session->setFlash(__('Soldier was not deleted'));
164 $this->redirect(array(
165 'plugin' => 'users',
166 'controller' => 'users',
167 'action' => 'edit'));
168 }
169
170 }
171