ProController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\ClientMemo;
  5. use App\Models\Meeting;
  6. use App\Models\MeetingParticipant;
  7. use App\Models\Ticket;
  8. use Illuminate\Http\Request;
  9. use App\Models\Pro;
  10. use Illuminate\Support\Facades\DB;
  11. class ProController extends Controller
  12. {
  13. public function dashboard(Request $request){
  14. $memos = ClientMemo::where('is_cancelled', false)->orderBy('created_at', 'desc')->get();
  15. $appointments = Appointment::orderBy('start_time', 'desc')->get();
  16. $tickets = Ticket::where('is_open', true)->orderBy('created_at', 'desc')->get();
  17. return view('pro.dashboard', [
  18. 'sessionKey' => $request->cookie('sessionKey'),
  19. 'memos' => $memos,
  20. 'appointments' => $appointments,
  21. 'tickets' => $tickets
  22. ]);
  23. }
  24. public function index(){
  25. $pros = Pro::all();
  26. return view('pro.index', compact('pros'));
  27. }
  28. public function create(){
  29. return view('pro.create');
  30. }
  31. public function show($uid, Request $request){
  32. $pro = Pro::where('uid', $uid)->first();
  33. return view('pro.show', compact('pro'));
  34. }
  35. public function meeting(Request $request, $meetingID) {
  36. $meeting = Meeting::where('uid', $meetingID)->first();
  37. if(!$meeting) {
  38. return abort(404, "Meeting no longer active");
  39. }
  40. $participants = MeetingParticipant::where('meeting_id', $meeting->id)->get();
  41. foreach ($participants as $participant) {
  42. $participant->proName = $participant->proName(); // eager-fill proName
  43. }
  44. return view('meeting', [
  45. 'meetingID' => $meetingID,
  46. 'participants' => $participants,
  47. 'guest' => false
  48. ]);
  49. }
  50. public function meet(Request $request, $uid = false) {
  51. $session = DB::table('app_session')->where('session_key', $request->cookie('sessionKey'))->first();
  52. $pro = false;
  53. if($session && $session->pro_id) {
  54. $pro = DB::table('pro')->where('id', $session->pro_id)->first();
  55. }
  56. $client = null;
  57. if(!empty($uid)) {
  58. $client = DB::table('client')->where('uid', $uid)->first();
  59. }
  60. else if($pro->in_meeting_with_client_id) {
  61. $client = DB::table('client')->where('id', $pro->in_meeting_with_client_id)->first();
  62. }
  63. return view('pro-call', [
  64. 'guest' => false,
  65. 'session' => $session,
  66. 'pro' => $pro,
  67. 'client' => $client
  68. ]);
  69. }
  70. public function getOpentokSessionKey(Request $request, $uid) {
  71. $client = DB::table('client')->where('uid', $uid)->first();
  72. return json_encode([
  73. "data" => $client->opentok_session_id
  74. ]);
  75. }
  76. }