示例#1
0
 static function operatorsOnline($company_id)
 {
     $response = 0;
     $department_admin_ids = CompanyDepartmentAdmins::where('company_id', $company_id)->lists('user_id');
     $company = Company::find($company_id);
     $user = User::find($company->user_id);
     if ($user->is_online == 1) {
         return 1;
     } else {
         foreach ($department_admin_ids as $admin_id) {
             if ($response == 0) {
                 $user = User::find($admin_id);
                 if ($user->is_online == 1) {
                     return 1;
                 } else {
                     $department_admin = DepartmentAdmins::where('user_id', $admin_id)->first();
                     if (!empty($department_admin)) {
                         $operators_ids = OperatorsDepartment::where('department_id', $department_admin->department_id)->lists('user_id');
                         foreach ($operators_ids as $operators_id) {
                             if (sizeof(User::where('id', $operators_id)->get()) > 0) {
                                 $user = User::find($operators_id);
                                 if ($user->is_online == 1) {
                                     return 1;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
 static function getFreeDepartmentAdmins($company_id, array $exclude_admin = [])
 {
     $user_ids = CompanyDepartmentAdmins::where("company_id", $company_id)->lists("user_id");
     $department_admins_ids = [];
     if (sizeof($user_ids) > 0) {
         $department_admins_ids = DepartmentAdmins::whereIn('user_id', $user_ids)->lists('user_id');
     }
     $department_admins = [];
     if (sizeof($user_ids) > 0) {
         $admins = User::whereIn("id", $user_ids)->get();
         foreach ($admins as $admin) {
             if (!in_array($admin->id, $exclude_admin)) {
                 if (!in_array($admin->id, $department_admins_ids)) {
                     array_push($department_admins, $admin);
                 }
             } else {
                 array_push($department_admins, $admin);
             }
         }
     }
     return $department_admins;
 }
 public function delete($company_id)
 {
     $departments = Department::where('company_id', $company_id)->get();
     if (Config::get('site-config.is_demo') && $company_id == 1) {
         Session::flash('error_msg', 'Demo : Feature is disabled');
         return Redirect::to('/dashboard');
     }
     foreach ($departments as $department) {
         if (!empty($department)) {
             $tickets = Tickets::where('department_id', $department->id)->get();
             //Delete tickets
             foreach ($tickets as $ticket) {
                 TicketAttachments::where('thread_id', $ticket->id)->delete();
                 MessageThread::where('id', $ticket->thread_id)->delete();
                 ThreadMessages::where('thread_id', $ticket->thread_id)->delete();
             }
             Tickets::where('department_id', $department->id)->delete();
             //Delete Chat and Conversations
             $online_users = OnlineUsers::where('department_id', $department->id)->get();
             foreach ($online_users as $online_user) {
                 MessageThread::where('id', $online_user->thread_id)->delete();
                 ThreadMessages::where('thread_id', $online_user->thread_id)->delete();
             }
             OnlineUsers::where('department_id', $department->id)->delete();
             $closed_conversations = ClosedConversations::where('department_id', $department->id)->get();
             foreach ($closed_conversations as $closed_conversation) {
                 MessageThread::where('id', $closed_conversation->thread_id)->delete();
                 ThreadMessages::where('thread_id', $closed_conversation->thread_id)->delete();
             }
             ClosedConversations::where('department_id', $department->id)->delete();
             $operators = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
             if (sizeof($operators) > 0) {
                 User::whereIn('id', $operators)->delete();
                 UsersGroups::whereIn('user_id', $operators)->delete();
             }
             OperatorsDepartment::where('department_id', $department->id)->delete();
             $department_admin = DepartmentAdmins::where('department_id', $department->id)->first();
             if (!empty($department_admin)) {
                 UsersGroups::where('user_id', $department_admin->user_id)->delete();
                 User::where("id", $department_admin->user_id)->delete();
                 CompanyDepartmentAdmins::where("user_id", $department_admin->user_id)->delete();
                 CannedMessages::where('operator_id', $operators)->delete();
             }
         }
         DepartmentAdmins::where('department_id', $department->id)->delete();
         Department::where('id', $department->id)->delete();
     }
     $company = Company::where('id', $company_id)->first();
     RecentActivities::createActivity("Company <a href='/companies/all'>" . $company->name . "</a> deleted by User Name " . Auth::user()->name . " User ID " . Auth::user()->id);
     Company::where('id', $company_id)->delete();
     Session::flash('success_msg', trans('msgs.company_deleted_success'));
     return Redirect::to('/companies/all');
 }
 public function all()
 {
     $user_ids = [];
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $department_ids = Department::where('company_id', $department->company_id)->lists('id');
         $user_ids = DepartmentAdmins::whereIn('department_id', $department_ids)->lists('user_id');
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $department_ids = Department::where('company_id', $department->company_id)->lists('id');
         $user_ids = DepartmentAdmins::whereIn('department_id', $department_ids)->lists('user_id');
     } else {
         $group = Groups::where("name", "department-admin")->first();
         $user_ids = UsersGroups::where("group_id", $group->id)->lists("user_id");
     }
     if (sizeof($user_ids) > 0) {
         $this->data["admins"] = User::whereIn("id", $user_ids)->orderBy('id', 'desc')->get();
     } else {
         $this->data["admins"] = [];
     }
     foreach ($this->data["admins"] as $admin) {
         $department_admin = DepartmentAdmins::where('user_id', $admin->id)->first();
         if (!empty($department_admin)) {
             $admin->department = Department::find($department_admin->department_id);
         }
         $company_id = CompanyDepartmentAdmins::where("user_id", $admin->id)->pluck('company_id');
         $admin->company = Company::find($company_id);
     }
     return View::make('department_admins.all', $this->data);
 }