IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Teacher/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Teacher/VideoConfController.php

<?php

namespace App\Http\Controllers\Teacher;

use Redirect;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Carbon\Carbon;
use App\Http\SendNotificationApi;
use Session;

class VideoConfController extends TeacherController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool','=',$teacher->idSchool)->first();
        $classes = DB::table('teacher_classes')
                        ->join('classes', 'teacher_classes.idClass', '=', 'classes.idClass')
                        ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                        ->where('idEmployee', '=', $teacher->idEmployee)
                        ->orderBy('classes.idClass')->get()->pluck('className', 'idClass')->toArray();            
        $classes = ['' => '--Select Class --'] + $classes;
       
        if ($request->ajax()) {
        $liveClass = DB::table('video_confernce')->join('classes', 'video_confernce.idClass', '=', 'classes.idClass')->where('idTeacher',$teacher->idEmployee)->where('idFinancialYear',Session::get('idFinancialYear'));

        $search = $request->input('search.value'); 
        $start = $request->input('start');
        $length = $request->input('length');
        $totalFiltered = 0;
        $totalData = 0;
        if (isset($search)) {
           $filter = DB::table('video_confernce')->where('idTeacher',$teacher->idEmployee)->where('idFinancialYear',Session::get('idFinancialYear'))->where('title','LIKE',"%{$search}%")->orderBy('idConference',"DESC")->count(); 
           $liveClass = $liveClass->where('title','LIKE',"%{$search}%")->orderBy('idConference',"DESC")->skip($start)->take($length)->get();
           $totalFiltered = $filter;
        }else{
            $liveClass = $liveClass->orderBy('idConference',"DESC")->skip($start)->take($length)->get();
            $totalData = DB::table('video_confernce')->where('idTeacher',$teacher->idEmployee)->where('idFinancialYear',Session::get('idFinancialYear'))->count();
            $totalFiltered = $totalData;
        }
        
        
        $data = array();
        $i = 1;
        foreach($liveClass as $value){
            $nestedData = array();
            array_push($nestedData, $i++);
            array_push($nestedData, $value->created_on);
            array_push($nestedData, $value->title);
            array_push($nestedData, $value->description);
            array_push($nestedData, $value->className);
            if (isset($value->idSection)) {
                $section = \App\Section::where('idSection', '=', $value->idSection)->first(); 
                array_push($nestedData,  $section->sectionName);
            }else array_push($nestedData, "All Section");
            
            array_push($nestedData, strtoupper($value->type));
            array_push($nestedData, $value->videoKey);

            if($value->isActive == "Y" && $value->videoType != 0 && $value->videoType != 3)
            array_push($nestedData, '<a href="'.$value->videoKey.'" class="btn btn-raised btn-info waves-effect btn-round" target="_blank">Open Link</a> <a href="https://online-login.online/teacher/end/videoconference/'.base64_encode($value->idConference).'" class="btn btn-raised btn-info waves-effect btn-round">End Class</a>'); 
            else if($value->isActive == "W")
            array_push($nestedData, "Class Ended");
            else array_push($nestedData, '<a href="https://online-login.online/teacher/init/videoconference/'.base64_encode($value->idConference).'" class="btn btn-raised btn-info waves-effect btn-round">Start Class</a>'); 
            

            if($value->videoType == 0)
            array_push($nestedData, '<a href="https://www.youtube.com/embed/'.$value->videoKey.'" class="btn btn-raised btn-info waves-effect btn-round">Play</a><button class="btn btn-raised btn-danger waves-effect btn-round js-sweetalert" data-id="'.$value->idConference.'" data-type="confirm">DELETE</button>'); 
            else array_push($nestedData, '<button class="btn btn-raised btn-danger waves-effect btn-round js-sweetalert" data-id="'.$value->idConference.'" data-type="confirm">DELETE</button>'); 
            array_push($data, $nestedData);   
        }
                                       
        $json_data = array(
            "draw" => intval($request->input('draw')),
            "recordsTotal" => intval($totalData),
            "recordsFiltered" => intval($totalFiltered),
            "data" => $data
        );

        
           return json_encode($json_data);
        }else
        return view('teachers.videoconf', compact('classes','school'));
    }

    public function createRoom($id){
       $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
       $school = \App\School::where('idSchool','=',$teacher->idSchool)->first();
       $liveClass = DB::table('video_confernce')->where('idTeacher',$teacher->idEmployee)->where('idFinancialYear',Session::get('idFinancialYear'))->where('idConference',base64_decode($id))->first();
       $key = $liveClass->videoKey;
       $affected = DB::table('video_confernce')
              ->where('idConference', base64_decode($id))
              ->update(['isActive' => "Y"]);
        
              $reg_ids=DB::table('students')
                    ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $liveClass->idClass);

             if($liveClass->idSection != null)      
        $reg_ids=$reg_ids->where('students.idSection', $liveClass->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool',$school->idSchool)
                    ->get()->pluck('idFirebase')->toArray();

            SendNotificationApi::sendNotification( $reg_ids,"Live Video Class : ".$liveClass->title." has been started click here to join or go to the app click on live video class menu");

            $reg_ids=DB::table('students')
                    ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $liveClass->idClass);

            if($liveClass->idSection != null)       
            $reg_ids=$reg_ids->where('students.idSection', $liveClass->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool', $school->idSchool)
                    ->get()->pluck('idFirebase')->toArray();
            SendNotificationApi::sendNotification( $reg_ids,"Live Video Class : ".$liveClass->title." has been started click here to join or go to the app click on live video class menu");       

       if($liveClass->videoType == 3)     
       return view('teachers.videoconf_start', compact('school','key','id','teacher'));
       else return Redirect::to('/teacher/videoconf');
    }

    public function endRoom($id,Request $request){
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
        $school = \App\School::where('idSchool','=',$teacher->idSchool)->first();
        $liveClass = DB::table('video_confernce')->where('idTeacher',$teacher->idEmployee)->where('idFinancialYear',Session::get('idFinancialYear'))->where('idConference',base64_decode($id))->first();
        $affected = DB::table('video_confernce')
              ->where('idConference', base64_decode($id))
              ->update(['isActive' => "W"]);
        $reg_ids=DB::table('students')
                    ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $liveClass->idClass);

             if($liveClass->idSection != null)      
        $reg_ids=$reg_ids->where('students.idSection', $liveClass->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool',$school->idSchool)
                    ->get()->pluck('idFirebase')->toArray();

            SendNotificationApi::sendNotification( $reg_ids,"Live Video Class : ".$liveClass->title." has been ended");

            $reg_ids=DB::table('students')
                    ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $liveClass->idClass);

            if($liveClass->idSection != null)       
            $reg_ids=$reg_ids->where('students.idSection', $liveClass->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool', $school->idSchool)
                    ->get()->pluck('idFirebase')->toArray();
            SendNotificationApi::sendNotification( $reg_ids,"Live Video Class : ".$liveClass->title." has been ended");
                  
        if ($request->ajax()) {
            return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
        }else{
            return Redirect::to('/teacher/videoconf');
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        $rules = [
            'idClass' => 'required',
//            'description' => 'required',
            'title' => 'required|max:120',
            'key' => 'required|max:500'
        ];
        if ($request->has('schedule')) {
            $rules += ['publishDate' => 'required'];
        }
        if(is_array($request->sections)){
            if (count($request->sections) == 0) {
                $rules += ['idSection' => 'required'];
            }
        }

        if(is_array($request->sections)){
            if (count($request->sections) > 1) {
                $rules += ['idSection' => 'More than one is not allowed'];
            }
        }

         

        $messages = [
            'idClass.required' => 'Class must be selected.',
            'idSection.required' => 'Section must be selected.'
        ];
        $this->Validate($request, $rules, $messages);
        $teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();

        $description =  $request->startdate . ' ' . $request->starttime;
        if($request->idTechType == 1 || $request->idTechType == 2){
            if (!str_contains($request->key, 'https://')) {
                $request->key = 'https://'.$request->key;
            }
        }
        if ($request->idSection == "All") {
          
           $id = DB::table('video_confernce')->insertGetId(
                [
                    'idSchool' => $teacher->idSchool,
                    'idFinancialYear' =>Session::get('idFinancialYear'),
                    'idClass' =>$request->idClass,
                    'idTeacher' =>$teacher->idEmployee,
                    'title' =>$request->title,
                    'description' =>$description,
                    'videoType' => $request->idTechType,
                    'type' => $request->idType,
                    'videoKey' => $request->key
                ]
            );
        }else
        $id = DB::table('video_confernce')->insertGetId(
                [
                    'idSchool' => $teacher->idSchool,
                    'idFinancialYear' =>Session::get('idFinancialYear'),
                    'idClass' =>$request->idClass,
                    'idSection' =>$request->idSection,
                    'idTeacher' =>$teacher->idEmployee,
                    'title' =>$request->title,
                    'videoType' => $request->idTechType,
                    'description' =>$description,
                    'type' => $request->idType,
                    'videoKey' => $request->key
                ]
            );


        $reg_ids=DB::table('students')
                    ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $request->idClass);

             if($request->idSection != null)      
        $reg_ids=$reg_ids->where('students.idSection', $request->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool',$teacher->idSchool)
                    ->get()->pluck('idFirebase')->toArray();

            SendNotificationApi::sendNotification( $reg_ids,"Video Live Class : ".$request->title." has been added go to the app click on live video class menu to view");

        $reg_ids=DB::table('students')
                    ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
                    ->select('parents.idFirebase')->where('students.idClass', $request->idClass);

            if($request->idSection != null)       
            $reg_ids=$reg_ids->where('students.idSection', $request->idSection);

            $reg_ids=$reg_ids->where('students.idFinancialYear', Session::get('idFinancialYear'))
                       ->where('students.idSchool', $teacher->idSchool)
                    ->get()->pluck('idFirebase')->toArray();
            SendNotificationApi::sendNotification( $reg_ids,"Live Video Class : ".$request->title." has been added go to the app click on live video class menu to view");
        
        if ($request->ajax()) {
            return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
        }
        return redirect('teacher/videoconf');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        return view('teachers.homework', compact('classes', 'homeworks', 'homework', 'section', 'student','school'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        return redirect('teacher/videoconf');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        $liveClass = DB::table('video_confernce')->where('idConference',$id)->delete();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

}

Copyright © 2021 - 2025 IMMREX7