Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Project $project, Request $request)
 {
     $user = JWTAuth::parseToken()->authenticate();
     $audience = User::whereIn('id', explode(',', $request->get('audience')))->get();
     $chat = $this->dispatch(new CreateChatRoom($user, $project, $request->all(), $audience));
     return response()->json(['success' => true, 'message' => 'Project Chat Created.', 'chat' => $chat]);
 }
 public function viewActivity($mode = 'default')
 {
     $subs = Sub::getSubs(self::userFp());
     $gsubs = Gsub::getSubs(self::userFp());
     $users = User::whereIn('user_fp', $subs)->orderBy('id', 'desc')->get();
     return View::make('board.activity', ['mode' => $mode, 'users' => $users, 'groups' => $gsubs, 'posts' => Post::activity($mode, self::userFp(), $subs, $gsubs, self::getBL())]);
 }
 public function promoteNow()
 {
     $returnResponse = array();
     $promote = Input::get('promote');
     if (count($promote) > 0) {
         $studentIdList = array();
         $studentDetailsList = array();
         while (list(, $value) = each($promote)) {
             $studentIdList[] = $value['id'];
         }
         $users = User::whereIn('id', $studentIdList)->get();
         foreach ($users as $value) {
             if (studentAcademicYears::where('studentId', $value->id)->where('academicYearId', $promote[$value->id]['acYear'])->count() > 0) {
                 $returnResponse[] = array("id" => $value->id, "fullName" => $value->fullName, "status" => "User already been in that academic year before");
             } else {
                 $studentAcademicYears = new studentAcademicYears();
                 $studentAcademicYears->studentId = $value->id;
                 $studentAcademicYears->academicYearId = $promote[$value->id]['acYear'];
                 $studentAcademicYears->classId = $promote[$value->id]['class'];
                 $studentAcademicYears->save();
                 User::where('id', $value->id)->update(['studentClass' => $promote[$value->id]['class'], 'studentAcademicYear' => $promote[$value->id]['acYear']]);
                 $returnResponse[] = array("id" => $value->id, "fullName" => $value->fullName, "status" => "User promoted successfully");
             }
         }
         return $returnResponse;
     }
 }
Example #4
0
 public function create()
 {
     $mailsms = new mailsms();
     if (Input::get('userType') == "users") {
         $mailsms->mailTo = json_encode(Input::get('selectedUsers'));
     } else {
         $mailsms->mailTo = Input::get('userType');
     }
     $mailsms->mailType = Input::get('sendForm');
     $messageData = " ";
     if (Input::get('messageTitle') != "") {
         $messageData .= Input::get('messageTitle');
     }
     if (Input::get('messageContent') != "") {
         $messageData .= htmlspecialchars(Input::get('messageContent'), ENT_QUOTES);
     }
     $mailsms->messageData = $messageData;
     $mailsms->messageDate = date("F j, Y, g:i a");
     $mailsms->messageSender = $this->data['users']->fullName . " [ " . $this->data['users']->id . " ] ";
     $mailsms->save();
     if (Input::get('userType') == "teachers") {
         $sedList = User::where('role', 'teacher')->get();
     }
     if (Input::get('userType') == "students") {
         if (!Input::get('classId') || Input::get('classId') == "" || Input::get('classId') == "0") {
             $sedList = User::where('role', 'student')->get();
         } else {
             $sedList = User::where('role', 'student')->where('studentClass', Input::get('classId'))->get();
         }
     }
     if (Input::get('userType') == "parents") {
         $sedList = User::where('role', 'parent')->get();
     }
     if (Input::get('userType') == "users") {
         $usersList = array();
         $selectedUsers = Input::get('selectedUsers');
         foreach ($selectedUsers as $user) {
             $usersList[] = $user['id'];
         }
         $sedList = User::whereIn('id', $usersList)->get();
     }
     $SmsHandler = new MailSmsHandler();
     if (Input::get('sendForm') == "email") {
         foreach ($sedList as $user) {
             $SmsHandler->mail($user->email, Input::get('messageTitle'), Input::get('messageContent'), $user->fullName);
         }
     }
     if (Input::get('sendForm') == "sms") {
         foreach ($sedList as $user) {
             if ($user->mobileNo != "") {
                 $SmsHandler->sms($user->mobileNo, strip_tags(Input::get('messageContent')));
             }
         }
     }
     return $this->listAll();
 }
 public function assignContributors($contributor_github_ids)
 {
     $users = User::whereIn('github_id', $contributor_github_ids)->get();
     $role = Role::where(['name' => $this->roleName])->first();
     foreach ($users as $user) {
         if ($user->roles()->count() > 0) {
             continue;
         }
         $user->roles()->attach($role->id);
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $blacklist = BlackList::where('user_id', $input['user_id'])->lists('black_id');
     $data = User::whereIn('id', $blacklist)->select(['avatar', 'username', 'id'])->get();
     foreach ($data as $key => $value) {
         $value->avatar = url(USER_AVATAR . '/' . $value->id . '/' . $value->avatar);
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $data);
 }
 public function sendAdminNotice(Vks $vks)
 {
     $vksArray = $vks->toArray();
     $admins = User::whereIn('role', [ROLE_ADMIN, ROLE_ADMIN_MODERATOR])->get(['login', 'email']);
     if (count($admins)) {
         foreach ($admins as $admin) {
             $message = App::$instance->twig->render('mails/v2/newVksAdminNotificate.twig', array('vks' => $vksArray, 'http_path' => HTTP_BASE_PATH, 'appHttpPath' => NODE_HTTP_PATH));
             Mail::sendMailToStack($admin->email, "Новая заявка на ВКС #{$vks['id']}", $message);
             App::$instance->log->logWrite(LOG_MAIL_SENDED, "Новая заявка на ВКС #{$vks['id']}");
         }
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $favorites = CommonFavorite::getFavorite(['model_name' => 'User', 'follow_id' => $input['user_id'], 'type_favorite' => TYPE_FAVORITE_LIKE]);
     $data = User::whereIn('id', $favorites)->select(listFieldUser())->get();
     foreach ($data as $value) {
         $value->avatar = url(USER_AVATAR . '/' . $value->id . '/' . User::find($value->id)->avatar);
     }
     // $data->avatar = url(USER_AVATAR . '/' . $value . '/' . User::find($value)->avatar);
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $data);
 }
Example #9
0
 public function getUsers($withMe = false)
 {
     $list = array();
     if (isset($this->id) && (int) $this->id > 0) {
         $ids = $this->getUsersIds();
         if (count($ids) > 0) {
             User::whereIn('id', $ids)->get()->each(function ($user) use(&$list, $withMe) {
                 if ($withMe || $user->id != Auth::user()->id) {
                     $list[] = $user;
                 }
             });
         }
     }
     return $list;
 }
Example #10
0
 public static function getDepartmentOperatorsWithAdmin($department_id)
 {
     $operator_ids = OperatorsDepartment::where('department_id', $department_id)->lists('user_id');
     if (sizeof($operator_ids) > 0) {
         $admin_id = DepartmentAdmins::where('department_id', $department_id)->pluck('user_id');
         $users = User::whereIn('id', $operator_ids)->get();
         if (!empty($admin_id)) {
             $user = User::where('id', $admin_id)->first();
             $user->name = $user->name . " - " . trans('msgs.department_admin');
             $users[] = $user;
         }
         return $users;
     } else {
         return [];
     }
 }
 public function store()
 {
     $users = explode(',', Input::get('users', ''));
     $users_ids = User::whereIn('username', $users)->get(['id']);
     $description = Input::get('description');
     foreach ($users_ids as $user) {
         $notification = new Notification();
         $notification->description = $description;
         $notification->user_id = $user->id;
         $notification->sender_id = Auth::user()->id;
         $notification->new = 1;
         $notification->save();
     }
     //foreach
     return Redirect::route('notifications')->with('message', 'Notification sent successfully.');
 }
 protected function users()
 {
     $role = Auth::user()->role;
     switch ($role) {
         case 'UL1':
             $users = User::get();
             break;
         case 'UL2':
             $users = User::whereIn('role', array('Cl1', 'CL2'))->get();
             break;
         case 'CL1':
             $users = User::where('role', 'CL2')->get();
             break;
         case 'CL2':
             break;
     }
     return $users;
 }
Example #13
0
 public function listUser()
 {
     $token = Input::get('token', '');
     $ids = Input::get('ids', '');
     $ids = explode(',', $ids);
     try {
         $user = User::chkUserByToken($token);
         $friends = User::whereIn('u_id', $ids)->get();
         // return all users without any restriction case IM will use all users
         $data = [];
         foreach ($friends as $key => $friend) {
             $data[] = $friend->showInImList();
         }
         $re = Tools::reTrue('获取信息成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取信息失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 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;
 }
Example #15
0
 public function getAuthorizedUserids($authorization_flag)
 {
     if ($authorization_flag === 0) {
         return [];
     }
     if ($authorization_flag === 1) {
         return [$this->id];
     }
     $key = implode('.', ['User', 'getAuthorizedUserids', $this->id, $authorization_flag]);
     $user = $this;
     return Cache::tags(['User', 'OrganizationUnit'])->rememberForever($key, function () use($authorization_flag, $user) {
         $result = [$user->id];
         if ($user->organizationunit->user_id === $user->id) {
             if ($authorization_flag == 2) {
                 $result = $user->organizationunit->users->lists('id');
             }
             if ($authorization_flag == 3) {
                 $result = User::whereIn('organization_unit_id', $user->organizationunit->descendantsAndSelf()->get()->lists('id'))->lists('id');
             }
         }
         return $result;
     });
 }
 public function all()
 {
     $group = Groups::where("name", "admin")->first();
     $user_ids = UsersGroups::where("group_id", $group->id)->lists("user_id");
     if (sizeof($user_ids) > 0) {
         $this->data["users"] = User::whereIn("id", $user_ids)->get();
     } else {
         $this->data["users"] = [];
     }
     return View::make('accounts.all', $this->data);
 }
 public function transfer($onlineusers_id)
 {
     $online_users = OnlineUsers::find($onlineusers_id);
     $companies = Company::all();
     $this->data['operators'] = [];
     if (sizeof($companies) > 0) {
         $departments = Department::where('company_id', $online_users->company_id)->get();
         $department_ids = Department::where('company_id', $online_users->company_id)->lists('id');
         if (sizeof($department_ids) > 0) {
             $operator_ids = OperatorsDepartment::whereIn('department_id', $department_ids)->lists('user_id');
             if (sizeof($operator_ids) > 0) {
                 $this->data['operators'] = User::whereIn('id', $operator_ids)->get();
             }
         }
     } else {
         $departments = [];
     }
     $this->data['companies'] = $companies;
     $this->data['departments'] = $departments;
     $this->data['online_users'] = $online_users;
     $this->data['company_id'] = $online_users->company_id;
     $this->data['department_id'] = $online_users->department_id;
     $this->data['customer'] = User::find($online_users->user_id);
     return View::make('conversations.transfer', $this->data);
 }
 public function start()
 {
     $response = [];
     $response['token'] = 0;
     if (Input::has('ip')) {
         //check ip_address in blocking table
         $blocking = Blocking::where('ip_address', Input::get('ip'))->first();
         if (!empty($blocking)) {
             if ($blocking->should_block_chat || $blocking->should_block_web_access) {
                 $response['blocked'] = 1;
                 $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
             }
         }
     } else {
         $response['blocked'] = 1;
         $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
     }
     $response['blocked'] = 0;
     $v_data = ["email" => Input::get('email'), "name" => Input::get('name'), "company_id" => Input::get('company_id'), "domain" => Input::get('domain'), "department" => Input::get('department'), "message" => Input::get('message')];
     $v_rules = ["email" => 'required|email', "name" => 'required', "company_id" => 'required', "domain" => 'required', "department" => 'required', "message" => 'required'];
     $v = Validator::make($v_data, $v_rules);
     if ($v->passes()) {
         $request_check = Company::where('id', Input::get('company_id'))->where('domain', Input::get('domain'))->get();
         if (sizeof($request_check) <= 0) {
             return $this->send(['result' => 0, 'errors' => trans('msgs.invalid_request_check_id_and_domain')]);
         }
         $company_customers = CompanyCustomers::where('company_id', Input::get('company_id'))->lists('customer_id');
         $user = null;
         if (sizeof($company_customers)) {
             $user = User::whereIn('id', $company_customers)->where('email', Input::get('email'))->first();
         }
         $operator_online = Company::operatorsOnline(Input::get('company_id'));
         $success_msg = trans('msgs.thanks_for_contacting_will_get_back');
         $response['is_online'] = $operator_online;
         $repo = new KodeInfo\Repo\MessageRepo();
         if (!empty($user) && !is_null($user)) {
             //user exists
             $count = OnlineUsers::where('user_id', $user->id)->first();
             if (sizeof($count) > 0) {
                 //user already online
                 $token = OnlineUsers::getToken();
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $count->thread_id;
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             } else {
                 $token = OnlineUsers::getToken();
                 $thread = $repo->createNewThread($user->id, Input::get("message"), true);
                 if ($response['is_online']) {
                     $online_user = new OnlineUsers();
                     $online_user->user_id = $user->id;
                     $online_user->thread_id = $thread['thread_id'];
                     $online_user->operator_id = 0;
                     $online_user->company_id = Input::get('company_id');
                     $online_user->department_id = Input::get('department');
                     $online_user->locked_by_operator = 0;
                     $online_user->requested_on = \Carbon\Carbon::now();
                     $online_user->token = $token;
                     $online_user->save();
                 }
                 $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
                 $geo_info = new ThreadGeoInfo();
                 $geo_info->thread_id = $thread['thread_id'];
                 $geo_info->ip_address = Input::get('ip');
                 $geo_info->country_code = Input::get('country');
                 $geo_info->country = !empty($country) ? $country->countryName : "";
                 $geo_info->provider = Input::get('provider');
                 $geo_info->current_page = Input::get('page');
                 $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
                 $geo_info->save();
                 if (!$response['is_online']) {
                     $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
                 }
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $thread['thread_id'];
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             }
         } else {
             $password = Str::random();
             //Is user in users table then get id and put in company-customers table
             $user = User::where('email', Input::get('email'))->first();
             if (!empty($user)) {
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
             } else {
                 $user = $this->userManager->createUser(["name" => Input::get('name'), "email" => Input::get('email'), "password" => $password, "password_confirmation" => $password], 'customer', false);
                 $user->avatar = "/assets/images/default-avatar.jpg";
                 $user->save();
                 $user->getActivationCode();
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
                 $this->mailer->welcome($user->email, $user->name, User::getWelcomeFields(false, $user->id, $password, $company_customer->company_id));
                 $this->mailer->activate($user->email, $user->name, User::getActivateFields(false, $user->id, $company_customer->company_id));
             }
             $token = OnlineUsers::getToken();
             $thread = $repo->createNewThread($user->id, Input::get("message"), true);
             if ($response['is_online']) {
                 $online_user = new OnlineUsers();
                 $online_user->user_id = $user->id;
                 $online_user->thread_id = $thread['thread_id'];
                 $online_user->operator_id = 0;
                 $online_user->company_id = Input::get('company_id');
                 $online_user->department_id = Input::get('department');
                 $online_user->locked_by_operator = 0;
                 $online_user->requested_on = \Carbon\Carbon::now();
                 $online_user->token = $token;
                 $online_user->save();
             }
             $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
             $geo_info = new ThreadGeoInfo();
             $geo_info->thread_id = $thread['thread_id'];
             $geo_info->ip_address = Input::get('ip');
             $geo_info->country_code = Input::get('country');
             $geo_info->country = !empty($country) ? $country->countryName : "";
             $geo_info->provider = Input::get('provider');
             $geo_info->current_page = Input::get('page');
             $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
             $geo_info->save();
             if (!$response['is_online']) {
                 $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
             }
             if ($operator_online > 0) {
                 $response['token'] = $token;
             }
             $response['result'] = 1;
             $response['user_id'] = $user->id;
             $response['thread_id'] = $thread['thread_id'];
             $response['success_msg'] = $success_msg;
             return $this->send($response);
         }
     } else {
         return $this->send(['result' => 0, 'errors' => Utils::buildMessages($v->messages()->all())]);
     }
 }
 public function all()
 {
     $customer_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();
         $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id');
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id');
     } else {
         $customer_ids = CompanyCustomers::lists('customer_id');
     }
     if (sizeof($customer_ids) > 0) {
         $this->data["customers"] = User::whereIn("id", $customer_ids)->orderBy('id', 'desc')->get();
     } else {
         $this->data["customers"] = [];
     }
     foreach ($this->data["customers"] as $customer) {
         $company_id = CompanyCustomers::where("customer_id", $customer->id)->pluck('company_id');
         $customer->company = Company::find($company_id);
         $customer->all_ticket_count = Tickets::where('customer_id', $customer->id)->count();
         $customer->pending_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_PENDING)->count();
         $customer->resolved_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_RESOLVED)->count();
     }
     return View::make('customers.all', $this->data);
 }
Example #20
0
 /**
  *  Update the project
  */
 public function updateProject($data, $userId)
 {
     //Find the project and update the fileds
     $project = Project::find($data['projectid']);
     $project->project_name = $data['project_name'];
     $project->description = $data['description'];
     $project->status = $data['status'];
     $tempStartDate = \DateTime::createFromFormat('j F, Y', $data['startdate']);
     $tempEndDate = \DateTime::createFromFormat('j F, Y', $data['enddate']);
     $project->start_date = $tempStartDate->format('Y-m-d');
     $project->end_date = $tempEndDate->format('Y-m-d');
     $project->project_client = $data['project_client'];
     $project->note = $data['note'];
     //If the project is marked completed fill the respective fields of database
     if ($data['status'] == 'completed') {
         $project->completed_on = date_create();
         $project->mark_completed_by = $userId;
         $project->updated_by = $userId;
         $project->save();
     } else {
         $project->updated_by = $userId;
         $project->save();
     }
     //Remove all the Collaborators of the project
     $prjtUsrs = ProjectUsers::where('project_id', $data['projectid'])->forceDelete();
     //New list of emails of collaborators
     $email = $data['tagsinput'];
     $emails = preg_split("/[\\s,]+/", $email);
     //Get the user Ids of the new collaborators
     $userIdList = \User::whereIn('email', $emails)->lists('id');
     //Add  collaborators
     foreach ($userIdList as $usrId) {
         $projectcollabs = new \Projectcollabs();
         $projectcollabs->user_id = $usrId;
         $projectcollabs->project_id = $data['projectid'];
         $projectcollabs->save();
     }
     //Get the project name and Id for the next view
     $projectName = $data['project_name'];
     $projectId = $data['projectid'];
     $files;
     $filesId = FileReference::where('parent_id', $projectId)->where('parent_type', 'project')->lists('attachment_id');
     if ($filesId == null) {
         $files = null;
     } else {
         $files = Files::whereIn('id', $filesId)->get(array('file_name', 'id', 'key', 'size', 'uploaded_date', 'uploaded_by'))->toArray();
     }
     //Wrap up data
     $returnData['projectName'] = $projectName;
     $returnData['projectId'] = $projectId;
     $returnData['files'] = $files;
     //Shoot back
     return $returnData;
 }
Example #21
0
 public static function getAllValidSponsors()
 {
     $userMeta = UserMeta::where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', 1)->get();
     $groups = Group::where('status', '=', Group::STATUS_ACTIVE)->get();
     $results = new Collection();
     $userIds = array();
     foreach ($userMeta as $m) {
         $userIds[] = $m->user_id;
     }
     if (!empty($userIds)) {
         $users = User::whereIn('id', $userIds)->get();
         foreach ($users as $user) {
             $row = array('display_name' => "{$user->fname} {$user->lname}", 'sponsor_type' => 'individual', 'id' => $user->id);
             $results->add($row);
         }
     }
     foreach ($groups as $group) {
         $row = array('display_name' => $group->display_name, 'sponsor_type' => 'group', 'id' => $group->id);
         $results->add($row);
     }
     return $results;
 }
 public function banlist()
 {
     $bl = Ban::where('user_fp', self::userFp())->lists('ban_fp');
     $users = User::whereIn('user_fp', $bl)->get();
     return View::make('user.banlist', ["users" => $users]);
 }
 function index()
 {
     if (\KodeInfo\Utilities\Utils::isCustomer(Auth::user()->id)) {
         return Redirect::to('/tickets/customer/all');
     }
     $past_hr = \Carbon\Carbon::now()->subHour();
     $today = \Carbon\Carbon::now()->subDay();
     $this_week = \Carbon\Carbon::now()->subWeek();
     $this_month = \Carbon\Carbon::now()->subMonth();
     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();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_operator->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } else {
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $companies = Company::all();
         foreach ($companies as $company) {
             $departments = Department::where('company_id', $company->id)->get();
             foreach ($departments as $department) {
                 $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
                 $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
                 $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
                 $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
                 if (sizeof($operator_ids) > 0) {
                     $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
                     $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
                 } else {
                     $department->operators_online = 0;
                     $department->operators_offline = 0;
                 }
             }
             $company->departments = $departments;
         }
         $this->data['department_stats'] = $companies;
     }
     return View::make('index', $this->data);
 }
 public function testIn()
 {
     $users = User::whereIn('age', array(13, 23))->get();
     $this->assertEquals(2, count($users));
     $users = User::whereIn('age', array(33, 35, 13))->get();
     $this->assertEquals(6, count($users));
     $users = User::whereNotIn('age', array(33, 35))->get();
     $this->assertEquals(4, count($users));
     $users = User::whereNotNull('age')->whereNotIn('age', array(33, 35))->get();
     $this->assertEquals(3, count($users));
 }
Example #25
0
 /**
  * 获取系统管理员信息
  *
  * @return array
  */
 public static function getSystemAdmin()
 {
     $founder = explode(',', str_replace(' ', '', Config('auth.founder')));
     $founders = User::whereIn('uid', $founder)->get();
     return $founders;
 }
 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);
 }
 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');
 }
Example #28
0
}
//dd($qid1);
$users1 = User::where('event', '=', $exceleve)->orderby('name')->with(array('answer' => function ($q) use($qid1) {
    $q->where('question_id', '=', $qid1)->orWhere('question_id', '=', $qid1 + 1);
}))->get();
$user_ids = array();
foreach ($users1 as $us) {
    if ($us->answer[0]->answer_text != '' && $us->role != 'admin_dd') {
        $user_ids[] = $us->id;
    }
}
//dd($user_ids);
$useransarr = array();
$users = User::whereIn('id', $user_ids)->get();
//dd($users);
$userswithanswers = User::whereIn('id', $user_ids)->with('answer')->with('categoryvendoranswer')->get();
//dd($userswithanswers);
foreach ($userswithanswers as $usa) {
    $tempansarr = array();
    $tempcatansarr = array();
    foreach ($usa->answer as $ansobj) {
        $tempansarr[$ansobj->question_id] = $ansobj->answer_text;
    }
    foreach ($usa->categoryvendoranswer as $catansobj) {
        $tempcatansarr[$catansobj->categoryvendor_id] = $catansobj->answer;
    }
    $useransarr[$usa->id]['login'] = $usa->email;
    $useransarr[$usa->id]['id'] = $usa->id;
    $useransarr[$usa->id]['answers'] = $tempansarr;
    $useransarr[$usa->id]['catanswers'] = $tempcatansarr;
    // dd($useransarr[]);
Example #29
0
 public function updateTask($data, $updateUserId)
 {
     try {
         $email = $data['users'];
         $emails = preg_split("/[\\s,]+/", $email);
         $usersId = \User::whereIn('email', $emails)->lists('id');
         $task = \Task::find((int) $data['taskId']);
         $task->name = $data['task_name'];
         $task->note = $data['note'];
         if ($data['project'] == 'null') {
             $task->project_id = null;
         } else {
             $task->project_id = (int) $data['project'];
         }
         \Log::info($data['startdate']);
         $tempStartDate = \DateTime::createFromFormat('j F, Y', $data['startdate']);
         $tempEndDate = \DateTime::createFromFormat('j F, Y', $data['enddate']);
         $task->start_date = $tempStartDate->format('Y-m-d');
         $task->end_date = $tempEndDate->format('Y-m-d');
         $task->updated_by = (int) $updateUserId;
         $task->save();
         $taskcollabs = \Taskcollabs::where('task_id', (int) $data['taskId'])->forceDelete();
         foreach ($usersId as $userId) {
             $taskCollabs = new \Taskcollabs();
             $taskCollabs->task_id = (int) $data['taskId'];
             $taskCollabs->user_id = $userId;
             $taskCollabs->updated_by = $updateUserId;
             $taskCollabs->save();
         }
         $result['status'] = 'success';
         $result['id'] = $task->id;
         return $result;
     } catch (Exception $e) {
         \Log::error('Something Went Wrong in Task Repository - updateTask():' . $e->getMessage());
         $result['status'] = 'error';
         return $result;
     }
 }
Example #30
0
 public function getDeleteAdminModal()
 {
     $ids = Input::get('ids');
     $users = User::whereIn('id', $ids)->get();
     $ids = json_encode($ids);
     return View::make('admin.modals.deleteAdmin')->with('ids', $ids)->with('users', $users);
 }