Controller.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. public function pass($data = null): array
  63. {
  64. return [
  65. 'success' => true,
  66. 'data' => $data,
  67. ];
  68. }
  69. public function fail($message): array
  70. {
  71. return [
  72. 'success' => false,
  73. 'message' => $message
  74. ];
  75. return null;
  76. }
  77. }