1
+ <?php
2
+
3
+ class GameController extends BaseController {
4
+
5
+ public function subLinks ($ gameSlug )
6
+ {
7
+ $ this ->addSubMenu ('Manage Game ' ,'game/manage/ ' . $ gameSlug );
8
+ $ this ->addSubMenu ('Manage Details ' , 'game/manageDetails/ ' . $ gameSlug );
9
+ }
10
+
11
+ public function getIndex ($ gameId = null , $ property = null , $ value = null )
12
+ {
13
+ // If passed values, handle them first
14
+ if ($ gameId != null ) {
15
+ $ game = Game::where ('uniqueId ' , $ gameId )->first ();
16
+ $ game ->{$ property } = $ value ;
17
+ $ game ->save ();
18
+ $ this ->redirect ('games ' , null );
19
+ }
20
+
21
+ // Set the template details
22
+ $ games = Game::with (array ('storytellers ' , 'storytellers.user ' , 'forum ' ))->orderByNameAsc ()->get ();
23
+ $ this ->setViewData ('games ' , $ games );
24
+ }
25
+
26
+ public function action_manageDetails ($ gameSlug )
27
+ {
28
+ // Add links
29
+ $ this ->subLinks ($ gameSlug );
30
+
31
+ $ game = Game::where ('slug ' , '= ' , $ gameSlug )->first ();
32
+
33
+ $ this ->setTemplate (array ('gameId ' => $ game ->id ));
34
+ }
35
+
36
+ public function action_manage ($ gameSlug = null )
37
+ {
38
+ // Add links
39
+ $ this ->subLinks ($ gameSlug );
40
+
41
+ // Set the template details
42
+ if ($ gameSlug != null ) {
43
+ $ game = Game::with (array ('storytellers ' , 'storytellers.user ' , 'characters ' , 'notes ' ))->where ('slug ' , '= ' , $ gameSlug )->first ();
44
+ $ forum = new Forum ;
45
+ if ($ game ->forum != null ) {
46
+ $ recentPosts = $ forum ->recentCategoryPosts ($ game ->forum ->id );
47
+ } else {
48
+ $ recentPosts = array ();
49
+ }
50
+ $ this ->setTemplate (array ('game ' => $ game , 'recentPosts ' => $ recentPosts ));
51
+ } else {
52
+ $ this ->setTemplate ();
53
+ }
54
+
55
+ // Handle form input
56
+ $ input = Input::all ();
57
+
58
+ if ($ input != null ) {
59
+ $ character = Character::find ($ input ['character_id ' ]);
60
+ if (isset ($ input ['exp ' ])) {
61
+ $ character ->addExperience ($ input ['exp ' ], $ this ->activeUser ->id , $ input ['reason ' ]);
62
+ }
63
+ return Redirect::to (URI ::current ())->with ('message ' , $ character ->name .' has been granted ' . $ input ['exp ' ] .' experience points. ' );
64
+ }
65
+ }
66
+
67
+ public function action_update ($ resourceId , $ property , $ value , $ type = 'character ' )
68
+ {
69
+ switch ($ type ) {
70
+ case 'character ' :
71
+ $ resource = Character::find ($ resourceId );
72
+ break ;
73
+ case 'post ' :
74
+ $ resource = Forum \Post::find ($ resourceId );
75
+ break ;
76
+ case 'reply ' :
77
+ $ resource = Forum \Reply::find ($ resourceId );
78
+ break ;
79
+ case 'tree ' :
80
+ $ resource = Game \Template \Magic \Tree::find ($ resourceId );
81
+ break ;
82
+ case 'spell ' :
83
+ $ resource = Game \Template \Spell::find ($ resourceId );
84
+ break ;
85
+ case 'characterSpell ' :
86
+ $ resource = Character \Spell::find ($ resourceId );
87
+ break ;
88
+ }
89
+ $ resource ->{$ property } = $ value ;
90
+ $ resource ->save ();
91
+ return Redirect::back ()->with ('message ' , $ resource ->name .' successfully updated. ' );
92
+ }
93
+
94
+ public function action_denySpell ($ spellId )
95
+ {
96
+ $ spell = Game \Template \Spell::find ($ spellId );
97
+ $ spell ->delete ();
98
+ return Redirect::back ()->with ('message ' , 'Spell has been denied. ' );
99
+ }
100
+
101
+ public function action_denyCharacterSpell ($ spellId )
102
+ {
103
+ $ spell = Character \Spell::find ($ spellId );
104
+ $ spell ->delete ();
105
+ return Redirect::back ()->with ('message ' , 'Spell has been denied. ' );
106
+ }
107
+
108
+ public function getAdd ()
109
+ {
110
+ // Set the template details
111
+ $ types = $ this ->arrayToSelect (Game_Type::orderByNameAsc ()->get (), 'id ' , 'name ' , 'Select a game type ' );
112
+ $ this ->setViewData ('types ' , $ types );
113
+ }
114
+
115
+ public function postAdd ()
116
+ {
117
+ // Handle any form inputs
118
+ $ input = Input::all ();
119
+ if ($ input != null ) {
120
+ $ game = new Game ;
121
+ $ game ->game_type_id = $ input ['game_type_id ' ];
122
+ $ game ->name = $ input ['name ' ];
123
+ $ game ->keyName = Str::slug ($ input ['name ' ]);
124
+ $ game ->description = $ input ['description ' ];
125
+ $ game ->activeFlag = (isset ($ input ['activeFlag ' ]) ? 1 : 0 );
126
+
127
+ $ game ->save ();
128
+
129
+ $ this ->checkErrorsRedirect ($ game );
130
+
131
+ $ storyTeller = new Game_StoryTeller (array ('game_id ' => $ game ->id , 'user_id ' => $ this ->activeUser ->id ));
132
+
133
+ $ game ->storytellers ()->save ($ storyTeller );
134
+
135
+ return Redirect::to ('game ' )->with ('message ' , $ game ->name .' has been created. ' );
136
+ }
137
+ }
138
+
139
+ public function action_edit ($ gameId )
140
+ {
141
+ // Set the template details
142
+ $ game = Game::find ($ gameId );
143
+ $ templates = $ this ->arrayToSelect (Game \Template::order_by ('name ' , 'asc ' )->get (), 'id ' , 'name ' , 'Select a template ' );
144
+ $ this ->setTemplate (array ('game ' => $ game , 'templates ' => $ templates ));
145
+
146
+ // Handle any form inputs
147
+ $ input = Input::all ();
148
+ if ($ input != null ) {
149
+ $ game ->game_template_id = $ input ['game_template_id ' ];
150
+ $ game ->name = $ input ['name ' ];
151
+ $ game ->description = $ input ['description ' ];
152
+ $ game ->activeFlag = (isset ($ input ['activeFlag ' ]) ? 1 : 0 );
153
+ $ game ->hitPointsName = $ input ['hitPointsName ' ];
154
+ $ game ->magicPointsName = $ input ['magicPointsName ' ];
155
+
156
+ $ game ->save ();
157
+
158
+ if (count ($ game ->errors ->all ()) > 0 ){
159
+ return Redirect::to (URI ::current ())->with_errors ($ game ->errors ->all ());
160
+ } else {
161
+ return Redirect::to ('game ' )->with ('message ' , $ game ->name .' has been edited. ' );
162
+ }
163
+ }
164
+ }
165
+
166
+ public function action_delete ($ gameId )
167
+ {
168
+ $ game = Game::find ($ gameId );
169
+ $ game ->delete ();
170
+ $ storyTellers = Game \StoryTeller::where ('game_id ' , '= ' , $ game ->id )->get ();
171
+ if (count ($ storyTellers ) > 0 ) {
172
+ foreach ($ storyTellers as $ storyTeller ) {
173
+ $ storyTeller ->delete ();
174
+ }
175
+ }
176
+ $ notes = Game \Note::where ('game_id ' , '= ' , $ game ->id )->get ();
177
+ if (count ($ notes ) > 0 ) {
178
+ foreach ($ notes as $ note ) {
179
+ $ note ->delete ();
180
+ }
181
+ }
182
+ return Redirect::to ('game ' )->with ('message ' , $ game ->name .' has been deleted. ' );
183
+ }
184
+
185
+ public function action_denyTree ($ treeId )
186
+ {
187
+ $ tree = Game \Template \Magic \Tree::find ($ treeId );
188
+ $ tree ->delete ();
189
+ return Redirect::back ()->with ('message ' , $ tree ->name .' has been denied. ' );
190
+ }
191
+
192
+ public function action_memberlist ($ gameId )
193
+ {
194
+ // Get the characters
195
+ $ game = Game::find ($ gameId );
196
+ $ characters = Character::where ('game_id ' , '= ' , $ gameId )->where ('activeFlag ' , '= ' , 1 )->where ('npcFlag ' , '= ' , 0 )->order_by ('name ' , 'ASC ' )->get ();
197
+ $ this ->setTemplate (array ('game ' => $ game , 'characters ' => $ characters ));
198
+ }
199
+ }
0 commit comments