Controller.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\Note;
  5. use App\Models\NoteTemplate;
  6. use App\Models\Pro;
  7. use App\Models\ProProAccess;
  8. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  9. use Illuminate\Foundation\Bus\DispatchesJobs;
  10. use Illuminate\Foundation\Validation\ValidatesRequests;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Routing\Controller as BaseController;
  13. use Illuminate\Support\Facades\Cookie;
  14. class Controller extends BaseController
  15. {
  16. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  17. protected $performer = null;
  18. protected $pro = null;
  19. protected $pros = null;
  20. public function __construct()
  21. {
  22. $this->performer = get_current_session();
  23. if($this->performer && $this->performer->pro) {
  24. $this->pro = $this->performer->pro;
  25. view()->share('pro', $this->performer->pro);
  26. }
  27. view()->share('performer', $this->performer);
  28. $this->pros = [];
  29. /*$this->pros = Pro::all();
  30. if($this->pro && $this->pro->pro_type != 'ADMIN'){
  31. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
  32. $accessibleProIds = [];
  33. foreach($accessiblePros as $accessiblePro){
  34. $accessibleProIds[] = $accessiblePro->id;
  35. }
  36. $accessibleProIds[] = $this->pro->id;
  37. $this->pros = Pro::whereIn('id', $accessibleProIds)->get();
  38. }*/
  39. view()->share('pros',$this->pros);
  40. // view()->share('notes', Note::all());
  41. // $noteTemplates = NoteTemplate::all();
  42. // view()->share('noteTemplates', $noteTemplates);
  43. $initiatives = ['LHI', 'BHI'];
  44. view()->share('intiatives', $initiatives);
  45. $rmCodes = ['RMB','RM20', 'RM40','RM60'];
  46. view()->share('rmCodes', $rmCodes);
  47. }
  48. public function performer(){
  49. $sessionKey = Cookie::get('sessionKey');
  50. if ($sessionKey == null){
  51. throw new \Exception('No session key in cookie.');
  52. }
  53. $performer = AppSession::where('session_key', $sessionKey)->first();
  54. return $performer;
  55. }
  56. public function getMyClientIds(){
  57. if($this->pro == null){
  58. return [];
  59. }
  60. return $this->pro->getMyClientIds();
  61. }
  62. }