| Total Complexity | 46 |
| Total Lines | 456 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ClientController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClientController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class ClientController extends Controller |
||
| 19 | { |
||
| 20 | public $user; |
||
| 21 | public $activate; |
||
| 22 | public $product; |
||
| 23 | |||
| 24 | public function __construct() |
||
| 25 | { |
||
| 26 | $this->middleware('auth'); |
||
| 27 | // $this->middleware('admin'); |
||
| 28 | $user = new User(); |
||
| 29 | $this->user = $user; |
||
| 30 | $activate = new AccountActivate(); |
||
| 31 | $this->activate = $activate; |
||
| 32 | $product = new \App\Model\Product\Product(); |
||
| 33 | $this->product = $product; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Display a listing of the resource. |
||
| 38 | * |
||
| 39 | * @return Response |
||
|
|
|||
| 40 | */ |
||
| 41 | public function index(Request $request) |
||
| 42 | { |
||
| 43 | $name = $request->input('name'); |
||
| 44 | $username = $request->input('username'); |
||
| 45 | $company = $request->input('company'); |
||
| 46 | $mobile = $request->input('mobile'); |
||
| 47 | $email = $request->input('email'); |
||
| 48 | $country = $request->input('country'); |
||
| 49 | $industry = $request->input('industry'); |
||
| 50 | $company_type = $request->input('company_type'); |
||
| 51 | $company_size = $request->input('company_size'); |
||
| 52 | $role = $request->input('role'); |
||
| 53 | $position = $request->input('position'); |
||
| 54 | |||
| 55 | $count_users = $this->user->get()->count(); |
||
| 56 | $pro_editions = $this->soldEdition('Faveo Helpdesk Pro'); |
||
| 57 | $community = $this->soldEdition('faveo helpdesk community'); |
||
| 58 | $product_count = $this->productCount(); |
||
| 59 | |||
| 60 | return view('themes.default1.user.client.index', compact('name', 'username', 'company', 'mobile', 'email', 'country', 'count_users', 'pro_editions', 'community', 'product_count', 'industry', 'company_type', 'company_size', 'role', 'position')); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get Clients for chumper datatable. |
||
| 65 | */ |
||
| 66 | public function GetClients(Request $request) |
||
| 126 | |||
| 127 | // ->searchColumns('email', 'first_name') |
||
| 128 | // ->orderColumns('email', 'first_name', 'created_at') |
||
| 129 | // ->make(); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Show the form for creating a new resource. |
||
| 134 | * |
||
| 135 | * @return Response |
||
| 136 | */ |
||
| 137 | public function create() |
||
| 138 | { |
||
| 139 | $timezones = new \App\Model\Common\Timezone(); |
||
| 140 | $timezones = $timezones->pluck('name', 'id')->toArray(); |
||
| 141 | $bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray(); |
||
| 142 | $managers = User::where('role', 'admin')->where('position', 'manager')->pluck('first_name', 'id')->toArray(); |
||
| 143 | |||
| 144 | return view('themes.default1.user.client.create', compact('timezones', 'bussinesses', 'managers')); |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Store a newly created resource in storage. |
||
| 149 | * |
||
| 150 | * @return Response |
||
| 151 | */ |
||
| 152 | public function store(ClientRequest $request) |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Display the specified resource. |
||
| 172 | * |
||
| 173 | * @param int $id |
||
| 174 | * |
||
| 175 | * @return Response |
||
| 176 | */ |
||
| 177 | public function show($id) |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Get total Amount paid for a particular invoice. |
||
| 203 | */ |
||
| 204 | public function getAmountPaid($userId) |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get total of the Invoices for a User. |
||
| 225 | */ |
||
| 226 | public function getTotalInvoice($invoices) |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Show the form for editing the specified resource. |
||
| 246 | * |
||
| 247 | * @param int $id |
||
| 248 | * |
||
| 249 | * @return Response |
||
| 250 | */ |
||
| 251 | public function edit($id) |
||
| 252 | { |
||
| 253 | try { |
||
| 254 | $user = $this->user->where('id', $id)->first(); |
||
| 255 | $timezones = new \App\Model\Common\Timezone(); |
||
| 256 | $timezones = $timezones->pluck('name', 'id')->toArray(); |
||
| 257 | |||
| 258 | $state = \App\Http\Controllers\Front\CartController::getStateByCode($user->state); |
||
| 259 | $managers = User::where('role', 'admin')->where('position', 'manager')->pluck('first_name', 'id')->toArray(); |
||
| 260 | |||
| 261 | $states = \App\Http\Controllers\Front\CartController::findStateByRegionId($user->country); |
||
| 262 | |||
| 263 | $bussinesses = \App\Model\Common\Bussiness::pluck('name', 'short')->toArray(); |
||
| 264 | |||
| 265 | return view('themes.default1.user.client.edit', compact('bussinesses', 'user', 'timezones', 'state', 'states', 'managers')); |
||
| 266 | } catch (\Exception $ex) { |
||
| 267 | app('log')->useDailyFiles(storage_path().'/laravel.log'); |
||
| 268 | app('log')->info($ex->getMessage()); |
||
| 269 | |||
| 270 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Update the specified resource in storage. |
||
| 276 | * |
||
| 277 | * @param int $id |
||
| 278 | * |
||
| 279 | * @return Response |
||
| 280 | */ |
||
| 281 | public function update($id, ClientRequest $request) |
||
| 282 | { |
||
| 283 | $user = $this->user->where('id', $id)->first(); |
||
| 284 | |||
| 285 | $user->fill($request->input())->save(); |
||
| 286 | // activity()->log('Look mum, I logged something'); |
||
| 287 | |||
| 288 | return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Remove the specified resource from storage. |
||
| 293 | * |
||
| 294 | * @param int $id |
||
| 295 | * |
||
| 296 | * @return Response |
||
| 297 | */ |
||
| 298 | public function destroy(Request $request) |
||
| 331 | </div>'; |
||
| 332 | //echo \Lang::get('message.select-a-row'); |
||
| 333 | } |
||
| 334 | } |
||
| 335 | |||
| 336 | public function getUsers(Request $request) |
||
| 344 | } |
||
| 345 | |||
| 346 | public function advanceSearch($name = '', $username = '', $company = '', $mobile = '', $email = '', $country = '', $industry = '', $company_type = '', $company_size = '', $role = '', $position = '') |
||
| 347 | { |
||
| 348 | $join = DB::table('users'); |
||
| 349 | $join = $this->getNamUserCom($join,$name,$username,$company); |
||
| 350 | $join = $this->getMobEmCoun($join,$mobile,$email,$country); |
||
| 351 | $join = $this->getInCtCs($join,$industry,$company_type,$company_size); |
||
| 352 | $join = $this->getRolPos($join,$role,$position); |
||
| 353 | |||
| 354 | $join = $join->orderBy('created_at', 'desc')->select('id', 'first_name', 'last_name', 'email', 'created_at', 'active', 'mobile_verified', 'role', 'position'); |
||
| 355 | |||
| 356 | return $join; |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Serach for Mobile,Email,Country |
||
| 361 | */ |
||
| 362 | public function getMobEmCoun($join,$mobile,$email,$country) |
||
| 363 | { |
||
| 364 | if ($mobile) { |
||
| 365 | $join = $join->where('mobile', $mobile); |
||
| 366 | } |
||
| 367 | if ($email) { |
||
| 368 | $join = $join->where('email', 'LIKE', '%'.$email.'%'); |
||
| 369 | } |
||
| 370 | if ($country) { |
||
| 371 | $join = $join->where('country', $country); |
||
| 372 | } |
||
| 373 | return $join; |
||
| 374 | } |
||
| 375 | |||
| 376 | |||
| 377 | /** |
||
| 378 | * Serach for industry,company_type,company_size |
||
| 379 | */ |
||
| 380 | public function getInCtCs($join,$industry,$company_type,$company_size) |
||
| 381 | { |
||
| 382 | if ($industry) { |
||
| 383 | $join = $join->where('bussiness', $industry); |
||
| 384 | } |
||
| 385 | if ($company_type) { |
||
| 386 | $join = $join->where('company_type', $company_type); |
||
| 387 | } |
||
| 388 | if ($company_size) { |
||
| 389 | $join = $join->where('company_size', $company_size); |
||
| 390 | } |
||
| 391 | return $join; |
||
| 392 | } |
||
| 393 | |||
| 394 | |||
| 395 | /** |
||
| 396 | * Serach for Role,Position |
||
| 397 | */ |
||
| 398 | public function getRolPos($join,$role,$position) |
||
| 399 | { |
||
| 400 | if ($role) { |
||
| 401 | $join = $join->where('role', $role); |
||
| 402 | } |
||
| 403 | if ($position) { |
||
| 404 | $join = $join->where('position', $position); |
||
| 405 | } |
||
| 406 | return $join; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Serach for Name,UserName,Company |
||
| 411 | */ |
||
| 412 | public function getNamUserCom($join,$name,$username,$company) |
||
| 413 | { |
||
| 414 | if ($name) { |
||
| 415 | $join = $join->where('first_name', 'LIKE', '%'.$name.'%') |
||
| 416 | ->orWhere('last_name', 'LIKE', '%'.$name.'%'); |
||
| 417 | } |
||
| 418 | if ($username) { |
||
| 419 | $join = $join->where('user_name', 'LIKE', '%'.$username.'%'); |
||
| 420 | } |
||
| 421 | if ($company) { |
||
| 422 | $join = $join->where('company', 'LIKE', '%'.$company.'%'); |
||
| 423 | } |
||
| 424 | return $join; |
||
| 425 | } |
||
| 426 | |||
| 427 | public function soldEdition($name) |
||
| 435 | } |
||
| 436 | |||
| 437 | public function productCount() |
||
| 438 | { |
||
| 439 | $products = $this->product->get()->count(); |
||
| 440 | |||
| 441 | return $products; |
||
| 442 | } |
||
| 443 | |||
| 444 | public function sendWelcomeMail($user) |
||
| 474 | } |
||
| 475 | } |
||
| 476 |