1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15
16 App::uses('DashboardAppController', 'Dashboard.Controller');
17
18 19 20
21 class PlayerSoldiersController extends DashboardAppController {
22
23 24 25 26 27
28 public $components = array(
29 'RequestHandler'
30 );
31
32
33
34 35 36 37 38
39 public function admin_index() {
40 $this->PlayerSoldier->recursive = 2;
41
42 $this->set('playerSoldiers', $this->paginate());
43 }
44
45
46
47 48 49 50 51 52 53
54 public function admin_view($id = null) {
55 $this->PlayerSoldier->id = $id;
56 $this->PlayerSoldier->recursive = 2;
57
58 if (!$this->PlayerSoldier->exists()) {
59 throw new NotFoundException(__('Invalid user soldier'));
60 }
61 $this->set('playerSoldier', $this->PlayerSoldier->read(null, $id));
62 }
63
64
65
66 67 68 69 70
71 public function admin_add() {
72 $this->PlayerSoldier->recursive = 2;
73
74 $this->set('users', $this->PlayerSoldier->User->find('list', array(
75 'fields' => 'User.username', 'User.id',
76 'order' => 'User.username ASC'
77 )));
78 $this->set('servers', $this->PlayerSoldier->Server->find('list', array(
79 'fields' => 'Server.servername', 'Server.id',
80 'order' => 'Server.servername ASC'
81 )));
82 $this->set('playerstats', $this->PlayerSoldier->PlayerStat->find('list', array(
83 'fields' => 'Player.name', 'PlayerStat.id',
84 'recursive' => 2,
85 'order' => 'Player.name ASC'
86 )));
87
88 if ($this->request->is('post')) {
89 $this->PlayerSoldier->create();
90 if ($this->PlayerSoldier->save($this->request->data)) {
91 $this->Session->setFlash(__('The user soldier has been saved'));
92 $this->redirect(array('action' => 'index'));
93 } else {
94 $this->Session->setFlash(__('The user soldier could not be saved. Please, try again.'));
95 }
96 }
97 }
98
99
100
101 102 103 104 105 106 107
108 public function admin_edit($id = null) {
109 $this->PlayerSoldier->id = $id;
110 $this->PlayerSoldier->recursive = 2;
111
112 $this->set('users', $this->PlayerSoldier->User->find('list', array(
113 'fields' => 'User.username', 'User.id',
114 'order' => 'User.username ASC'
115 )));
116 $this->set('servers', $this->PlayerSoldier->Server->find('list', array(
117 'fields' => 'Server.servername', 'Server.id',
118 'order' => 'Server.servername ASC'
119 )));
120 $this->set('playerstats', $this->PlayerSoldier->PlayerStat->find('list', array(
121 'fields' => 'Player.name', 'PlayerStat.id',
122 'recursive' => 2,
123 'order' => 'Player.name ASC'
124 )));
125
126 if (!$this->PlayerSoldier->exists()) {
127 throw new NotFoundException(__('Invalid user soldier'));
128 }
129 if ($this->request->is('post') || $this->request->is('put')) {
130 if ($this->PlayerSoldier->save($this->request->data)) {
131 $this->Session->setFlash(__('The user soldier has been saved'));
132 $this->redirect(array('action' => 'index'));
133 } else {
134 $this->Session->setFlash(__('The user soldier could not be saved. Please, try again.'));
135 }
136 } else {
137 $this->request->data = $this->PlayerSoldier->read(null, $id);
138 }
139 }
140
141
142
143 144 145 146 147 148 149 150
151 public function admin_delete($id = null) {
152 if (!$this->request->is('post')) {
153 throw new MethodNotAllowedException();
154 }
155 $this->PlayerSoldier->id = $id;
156 if (!$this->PlayerSoldier->exists()) {
157 throw new NotFoundException(__('Invalid user soldier'));
158 }
159 if ($this->PlayerSoldier->delete()) {
160 $this->Session->setFlash(__('User soldier deleted'));
161 $this->redirect(array('action' => 'index'));
162 }
163 $this->Session->setFlash(__('User soldier was not deleted'));
164 $this->redirect(array('action' => 'index'));
165 }
166
167 }
168