11<?php
22
3- use Locker \Repository \User \UserRepository as User ;
4- use Locker \Repository \Lrs \LrsRepository as Lrs ;
5- use Locker \Repository \Client \ClientRepository as Client ;
3+ use Locker \Repository \User \UserRepository as UserRepo ;
4+ use Locker \Repository \Lrs \Repository as LrsRepo ;
5+ use Locker \Repository \Client \ClientRepository as ClientRepo ;
66
77class ClientController extends BaseController {
88
9- /**
10- * User
11- */
12- protected $ user ;
13-
14- /**
15- * Lrs
16- **/
17- protected $ lrs ;
9+ protected $ user , $ lrs , $ client ;
1810
1911 /**
20- * Client
21- **/
22- protected $ client ;
23-
24-
25- /**
26- * Construct
27- *
28- * @param User $user
29- * @param Lrs $lrs
30- * @param Client $client
12+ * Constructs a new ClientController.
13+ * @param UserRepo $user
14+ * @param LrsRepo $lrs
15+ * @param ClientRepo $client
3116 */
32- public function __construct (User $ user , Lrs $ lrs , Client $ client ){
33-
17+ public function __construct (UserRepo $ user , LrsRepo $ lrs , ClientRepo $ client ) {
3418 $ this ->user = $ user ;
35- $ this ->lrs = $ lrs ;
36- $ this ->client = $ client ;
37- $ this ->logged_in_user = Auth::user ();
38-
19+ $ this ->lrs = $ lrs ;
20+ $ this ->client = $ client ;
3921 }
4022
4123 /**
42- * Load the manage clients page
43- *
44- * @param int $id
24+ * Load the manage clients page.
25+ * @param String $lrs_id
4526 * @return View
4627 */
47- public function manage ($ id ){
48-
49- $ lrs = $ this ->lrs ->find ( $ id );
50- $ lrs_list = $ this ->lrs ->all ();
51-
52- $ clients = \Client::where ('lrs_id ' , $ lrs ->id )->get ();
53-
54-
55- return View::make ('partials.client.manage ' , array ('clients ' => $ clients ,
56- 'lrs ' => $ lrs ,
57- 'list ' => $ lrs_list
58- ));
28+ public function manage ($ lrs_id ) {
29+ $ opts = ['user ' => \Auth::user ()];
30+ $ lrs = $ this ->lrs ->show ($ lrs_id , $ opts );
31+ $ lrs_list = $ this ->lrs ->index ($ opts );
32+ $ clients = \Client::where ('lrs_id ' , $ lrs ->id )->get ();
33+ return View::make ('partials.client.manage ' , [
34+ 'clients ' => $ clients ,
35+ 'lrs ' => $ lrs ,
36+ 'list ' => $ lrs_list
37+ ]);
5938 }
6039
6140 /**
62- * Load the manage clients page
63- *
64- * @param int $lrs_id
65- * @param int $id
41+ * Load the manage clients page.
42+ * @param String $lrs_id
43+ * @param String $id
6644 * @return View
6745 */
68- public function edit ($ lrs_id , $ id ){
69-
70- $ lrs = $ this ->lrs ->find ( $ lrs_id );
71- $ lrs_list = $ this ->lrs ->all ();
72-
73- $ client = $ this ->client ->find ( $ id );
74-
75-
76- return View::make ('partials.client.edit ' , array ('client ' => $ client ,
77- 'lrs ' => $ lrs ,
78- 'list ' => $ lrs_list
79- ));
46+ public function edit ($ lrs_id , $ id ) {
47+ $ opts = ['user ' => \Auth::user ()];
48+ $ lrs = $ this ->lrs ->show ($ lrs_id , $ opts );
49+ $ lrs_list = $ this ->lrs ->index ($ opts );
50+ $ client = $ this ->client ->find ($ id );
51+ return View::make ('partials.client.edit ' , [
52+ 'client ' => $ client ,
53+ 'lrs ' => $ lrs ,
54+ 'list ' => $ lrs_list
55+ ]);
8056 }
8157
82- /**
83- * Create a new client
84- *
85- * @param int $id
58+ /**
59+ * Create a new client.
60+ * @param String $lrs_id
8661 * @return View
87- **/
88-
89- public function create ($ id ){
90-
91- $ lrs = $ this ->lrs ->find ( $ id );
92-
93- $ data = array ('lrs_id ' => $ lrs ->id );
62+ */
63+ public function create ($ lrs_id ) {
64+ $ opts = ['user ' => \Auth::user ()];
65+ $ lrs = $ this ->lrs ->show ($ lrs_id , $ opts );
66+ $ data = ['lrs_id ' => $ lrs ->id ];
9467
95- if ( $ this ->client ->create ( $ data ) ) {
68+ if ( $ this ->client ->create ($ data)) {
9669 $ message_type = 'success ' ;
97- $ message = Lang:: get ( ' update_key ' );
98- }else {
70+ $ message = trans ( ' lrs.client.created_sucecss ' );
71+ } else {
9972 $ message_type = 'error ' ;
100- $ message = Lang:: get ( ' update_key_error ' );
73+ $ message = trans ( ' lrs.client.created_fail ' );
10174 }
10275
10376 return Redirect::back ()->with ($ message_type , $ message );
10477 }
10578
10679 /**
10780 * Update the specified resource in storage.
108- *
109- * @param int $id
81+ * @param String $lrs_id Id of the LRS.
82+ * @param String $id Id of the client.
11083 * @return View
11184 */
11285 public function update ($ lrs_id , $ id ){
113-
114- /*$data = Input::all();
115-
116- //TODO :client input validation This may be able to re-use some of the statement validator
117- $rules['title'] = 'required|alpha_spaces';
118- $rules['description'] = 'alpha_spaces';
119- $validator = Validator::make($data, $rules);
120- if ($validator->fails()) return Redirect::back()->withErrors($validator);
121- */
122-
123-
124- //{{ URL() }}/lrs/{{ $lrs->_id }}/client/manage#{{ $client->_id }}
125-
126- if ($ this ->client ->update ( $ id , Input::all () )){
127- return Redirect::to ('/lrs/ ' .$ lrs_id .'/client/manage# ' .$ id )->with ('success ' , Lang::get ('lrs.client.updated ' ));
86+ if ($ this ->client ->update ($ id , Input::all ())) {
87+ $ redirect_url = '/lrs/ ' .$ lrs_id .'/client/manage# ' .$ id ;
88+ return Redirect::to ($ redirect_url )->with ('success ' , trans ('lrs.client.updated ' ));
12889 }
12990
13091 return Redirect::back ()
131- ->withInput ()
132- ->withErrors ($ this ->client ->errors ());
133-
92+ ->withInput ()
93+ ->withErrors ($ this ->client ->errors ());
13494 }
13595
136-
13796 /**
13897 * Remove the specified resource from storage.
139- *
140- * @param int $lrs_id
141- * @param int $id
98+ * @param String $lrs_id
99+ * @param String $id
142100 * @return View
143101 */
144102 public function destroy ($ lrs_id , $ id ){
145-
146- if ( $ this ->client ->delete ($ id ) ){
103+ if ($ this ->client ->delete ($ id )) {
147104 $ message_type = 'success ' ;
148- $ message = Lang:: get ( ' delete_client_success ' );
149- }else {
105+ $ message = trans ( ' lrs.client. delete_client_success ' );
106+ } else {
150107 $ message_type = 'error ' ;
151- $ message = Lang:: get ( ' delete_client_error ' );
108+ $ message = trans ( ' lrs.client. delete_client_error ' );
152109 }
153110
154- return Redirect::back ()->with ($ message_type , $ message );
155-
111+ return Redirect::back ()->with ($ message_type , $ message );
156112 }
157-
158- }
113+ }
0 commit comments