Overview

Namespaces

  • App
    • Http
      • Controllers
        • Auth
      • Middleware
  • PHP

Classes

  • App\Ad
  • App\AdClick
  • App\AdLocation
  • App\Comment
  • App\Driver
  • App\Emergency
  • App\Http\Controllers\AdController
  • App\Http\Controllers\ApiController
  • App\Http\Controllers\Auth\AuthController
  • App\Http\Controllers\Auth\PasswordController
  • App\Http\Controllers\CommentController
  • App\Http\Controllers\Controller
  • App\Http\Controllers\EmergencyController
  • App\Http\Controllers\NewspaperController
  • App\Http\Controllers\RouteController
  • App\Http\Controllers\TaxiController
  • App\Http\Controllers\UserController
  • App\Http\Kernel
  • App\Http\Middleware\AddHeaders
  • App\Http\Middleware\AdminMiddleware
  • App\Newspaper
  • App\Route
  • App\Tablet
  • App\Taxi
  • App\Taxibase
  • App\User
  • Closure
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace App\Http\Controllers;
  4: use App\Emergency;
  5: use Illuminate\Http\Request;
  6: use App\Http\Requests;
  7: use App\Http\Controllers\Controller;
  8: use Route, View;
  9: use App\Taxi;
 10: use App\Driver;
 11: use App\User;
 12: use App\Taxibase;
 13: use Illuminate\Support\Facades\Validator;
 14: use Illuminate\Support\Facades\Hash;
 15: use Image;
 16: 
 17: class TaxiController extends Controller
 18: {
 19:     /**
 20:      * @author Stefano Groenland
 21:      * @return mixed
 22:      *
 23:      * Makes the taxi location view and passes a variable with it.
 24:      */
 25:     public function showTaxiLocation(){
 26:         $cars = Taxi::with('driver','emergency')->where('in_shift',1)->where('last_latitude','!=','')->where('last_longtitude','!=','')->get();
 27:         $taxis = Taxi::with('driver','emergency')->where('in_shift',1)->get();
 28:         $bases = Taxibase::all();
 29:         return View::make('/taxilocatie', compact('bases','taxis','cars'));
 30:     }
 31: 
 32:     /**
 33:      * @author Stefano Groenland
 34:      * @return mixed
 35:      *
 36:      * Makes the taxi overview view and passes 2 variables with it.
 37:      */
 38:     public function showTaxiOverview(){
 39:         $taxis = Taxi::all();
 40:         $drivers = Driver::with('user')->get();
 41:         return View::make('/taxioverzicht', compact('taxis', 'drivers'));
 42:     }
 43: 
 44:     /**
 45:      * @author Richard Perdaan
 46:      * @return mixed
 47:      *
 48:      *  TODO : fill in func description
 49:      */
 50:     public function showTaxiEdit(){
 51:         $id = Route::current()->getParameter('id');
 52:         $taxi = Taxi::where('id',$id)->first();
 53:         $user = Taxi::with('driver')->where('id',$id)->first();
 54:         $drivers = Driver::with('user')->where('taxi_id','0')->orWhere('taxi_id',$id)->get();
 55:         $driverCount   = count($drivers);
 56:        return View::make('/taxiwijzigen', compact('id','taxi','user','drivers','driverCount'));
 57:      }
 58: 
 59:     /**
 60:      * @author Richard Perdaan
 61:      * @return mixed
 62:      *
 63:      *  TODO : fill in func description
 64:      */
 65:     public function showTaxiAdd(){
 66:         $drivers = Driver::with('user')->where('taxi_id','0')->get();
 67:         $driverCount = count($drivers);
 68:         return View::make('/taxitoevoegen', compact('drivers','driverCount'));
 69:     }
 70: 
 71:     /**
 72:      * @author Stefano Groenland
 73:      * @param Request $request
 74:      * @return \Illuminate\Http\RedirectResponse
 75:      *
 76:      * If the radio button create_driver is set to create driver it will create a new taxi with a driver and instantly links them together.
 77:      * If the create_driver radio button is set to assign it will pick a driver from the select and after creating the taxi it links them together.
 78:      */
 79:     public function addTaxi(Request $request){
 80: 
 81:         if($request['create_driver'] == 'create'){
 82:             $request['driver'] = 0;
 83:         }
 84:         $data = array(
 85:             'license_plate'     => strtoupper($request['license_plate']),
 86:             'car_brand'         => $request['car_brand'],
 87:             'car_color'         => $request['car_color'],
 88:             'car_model'         => $request['car_model'],
 89:             'driver_id'         => $request['driver']
 90:         );
 91:         $rules = array(
 92:             'license_plate'     => 'required',
 93:             'car_model'         => 'required',
 94:             'car_color'         => 'required',
 95:             'car_model'         => 'required'
 96:         );
 97: 
 98:         $validator = Validator::make($data, $rules);
 99:         if ($validator->fails()){
100:             return redirect('taxitoevoegen')->withErrors($validator)->withInput($data);
101:         }
102:         $taxi = Taxi::create($data);
103:         Emergency::create(array(
104:             'taxi_id'   =>  $taxi->id,
105:             'seen'      =>  '1'
106:         ));
107:         if($request['create_driver'] == 'create'){
108:             $userData = array(
109:                 'email'                 => $request['email'],
110:                 'phone_number'          => $request['phonenumber'],
111:                 'firstname'             => $request['firstname'],
112:                 'lastname'              => $request['lastname'],
113:                 'password'              => $request['password'],
114:                 'password_confirmation' => $request['password_confirmation'],
115:                 'sex'                   => $request['sex'],
116:                 'drivers_exp'           => $request['driver_exp'],
117:                 'global_information'    => $request['global_information'],
118:                 'user_rank' => 'driver'
119:             );
120: 
121:             $userRules = array(
122:                 'email'                 =>'required|email|unique:user',
123:                 'phone_number'          =>'required|numeric|digits:10',
124:                 'firstname'             =>'required',
125:                 'lastname'              =>'required',
126:                 'password'              => 'required|min:4|confirmed',
127:                 'password_confirmation' => 'required|min:4',
128:                 'drivers_exp'           => 'numeric',
129:                 'sex'                   => 'required|in:man,vrouw'
130:             );
131:             $validator = Validator::make($userData, $userRules);
132:             $merge = array_merge($data, $userData);
133: 
134:             if ($validator->fails()){
135:                 return redirect('/taxitoevoegen')->withErrors($validator)->withInput($merge);
136:             }
137:             array_forget($userData, 'password_confirmation');
138:             $userData['password'] = Hash::make($request['password']);
139:             $user = User::create($userData);
140: 
141:             $this->upload($request,$user->id);
142: 
143:             $driverData = array(
144:                 'user_id'               => $user->id,
145:                 'taxi_id'               => $taxi->id,
146:                 'drivers_exp'           => $request['driver_exp'],
147:                 'global_information'    => $request['global_information']
148:             );
149:             $driver = Driver::create($driverData);
150: 
151:             $taxi->where('id',$taxi->id)->update(['driver_id' => $driver->id]);
152:         }else{
153:             Driver::where('id',$data['driver_id'])->update(['taxi_id' => $taxi->id]);
154:         }
155:         session()->flash('alert-success','De taxi is aangemaakt.');
156:         return redirect()->route('taxioverzicht');
157:     }
158: 
159:     /**
160:      * @author Stefano Groenland
161:      * @return \Illuminate\Http\RedirectResponse
162:      *
163:      * Grabs the ID of the taxi, And deletes the corresponding rows from the Database.
164:      */
165:     public function deletetaxi(){
166:         $id = Route::current()->getparameter('id');
167:         $find = Taxi::find($id);
168:         Emergency::where('taxi_id',$find->id)->delete();
169:         $find->delete();
170:         session()->flash('alert-success','De Taxi is verwijderd.');
171:         return redirect()->route('taxioverzicht');
172:     }
173: 
174:     public function editTaxi(Request $request){
175:         $id = Route::current()->getParameter('id');
176: 
177:         $data = array(
178:             'license_plate'     => strtoupper($request['license_plate']),
179:             'car_brand'         => $request['car_brand'],
180:             'car_color'         => $request['car_color'],
181:             'car_model'         => $request['car_model'],
182:             'driver_id'         => $request['driver']
183:         );
184:         $rules = array(
185:             'license_plate'     => 'required',
186:             'car_model'         => 'required',
187:             'car_color'         => 'required',
188:         );
189: 
190:         $validator = Validator::make($data, $rules);
191:         if ($validator->fails()){
192:             return redirect('taxiwijzigen')->withErrors($validator)->withInput($data);
193:         }
194:         $taxi = Taxi::find($id);
195:         $taxi->update($data);
196:             Driver::where('id',$taxi->driver_id)->update(['taxi_id' => $taxi->id]);
197:         session()->flash('alert-success','De taxi is gewijzigd.');
198:         return redirect()->route('taxioverzicht');
199:     }
200: 
201:     /**
202:      * @authors Stefano Groenland, Richard Perdaan
203:      * @param Request $request
204:      * @param $id
205:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
206:      *
207:      * Grabs the file named 'profile_photo' from the request and uploads it onto the server,
208:      * It updates the corresponding user with the link to the uploaded picture as their profile_photo in the User table.
209:      */
210:     public function upload(Request $request , $id){
211:         $x = $request['x'];
212:         $y = $request['y'];
213:         $h = $request['h'];
214:         $w = $request['w'];
215: 
216:         $file = array('profile_photo' => $request->file('profile_photo'));
217:         $rules = array('profile_photo' => 'required|mimes:jpeg,bmp,png,jpg',);
218:         $validator = Validator::make($file, $rules);
219:         if ($validator->fails()) {
220:             if ($file) {
221:                 //$request->session()->flash('alert-danger', 'U heeft geen bestand / geen geldig bestand gekozen om te uploaden, voeg een foto toe.');
222:             }
223:             return redirect('/taxitoevoegen');
224:         } else {
225:             if ($request->file('profile_photo')->isValid()) {
226:                 $destinationPath = 'assets/uploads';
227:                 $extension = $request->file('profile_photo')->getClientOriginalExtension();
228:                 $fileName = rand(1111, 9999) . '.' . $extension;
229:                 $request->file('profile_photo')->move($destinationPath, $fileName);
230:                 $ava = $destinationPath . '/' . $fileName;
231:                 $img = Image::make($ava)->fit(200)->crop($w, $h, $x, $y)->save();
232:                 $final = $destinationPath . '/' . $img->basename;
233:                 User::uploadPicture($id, $final);
234: 
235:             } else {
236:                 $request->session()->flash('alert-danger', 'Er is een fout opgetreden tijdens het uploaden van uw bestand.');
237:             }
238:         }
239:         return redirect('/taxioverzicht');
240:     }
241: }
242: 
APIv1 API documentation generated by ApiGen