Example #1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Project $project, User $user)
 {
     $admin = JWTAuth::parseToken()->authenticate();
     $audience = User::whereIn('id', explode(',', $request->get('audience')))->get();
     $this->dispatch(new RemoveUserFromProject($admin, $project, $user, $audience));
     return response()->json(['success' => true, 'message' => 'User Left Project.']);
 }
 public function index()
 {
     $classes = StudyClass::all();
     $teacher_ids = array();
     $assist_ids = array();
     foreach ($classes as $class) {
         if ($class->teach != null) {
             $teacher_ids[] = $class->teach->id;
         }
         if ($class->assist != null) {
             $assist_ids[] = $class->assist->id;
         }
     }
     $teachers = User::whereIn('id', $teacher_ids)->get();
     foreach ($teachers as &$teacher) {
         $class_ids = array();
         foreach ($teacher->teach as $t) {
             $class_ids[] = $t->id;
         }
         $teacher->rating_number = Register::whereIn('class_id', $class_ids)->where('rating_teacher', '>', -1)->count();
         $teacher->rating_avg = Register::whereIn('class_id', $class_ids)->where('rating_teacher', '>', -1)->avg('rating_teacher');
     }
     $assistants = User::whereIn('id', $assist_ids)->get();
     foreach ($assistants as &$assistant) {
         $class_ids = array();
         foreach ($assistant->assist as $t) {
             $class_ids[] = $t->id;
         }
         $assistant->rating_number = Register::whereIn('class_id', $class_ids)->where('rating_ta', '>', -1)->count();
         $assistant->rating_avg = Register::whereIn('class_id', $class_ids)->where('rating_ta', '>', -1)->avg('rating_ta');
     }
     $this->data['teachers'] = $teachers;
     $this->data['assistants'] = $assistants;
     return view('manage.personal_rating.all', $this->data);
 }
Example #3
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();
     $forum = $this->dispatch(new PostForum($user, $project, $request->all(), $audience));
     return response()->json(['success' => true, 'message' => 'Forum Posted.', 'forum' => $forum]);
 }
Example #4
0
 public function refresh()
 {
     if (!\Session::get('user')->is_admin()) {
         abort(401);
     }
     $group_id = config('gapper.group_id');
     $members = Client::getMembers($group_id);
     if (count($members)) {
         $deleted_users = User::all()->lists('gapper_id', 'id')->toArray();
         foreach ($members as $member) {
             $id = $member['id'];
             $user = User::where('gapper_id', $id)->first();
             if (!$user) {
                 $user = new \App\User();
                 $user->gapper_id = $member['id'];
                 $user->name = $member['name'];
                 $user->icon = $member['icon'];
             } else {
                 $user->name = $member['name'];
                 $user->icon = $member['icon'];
                 //从 deleted_users 中删除当前 gapper_id 对应的用户
                 //最后剩下的, 就是 User 中不包含 gapper_id 的用户
                 if (array_key_exists($member['id'], $deleted_users)) {
                     unset($deleted_users[$id]);
                 }
             }
             $user->save();
         }
         //发现有需要删除的 User
         if (count($deleted_users)) {
             $to_deleted_users = User::whereIn('id', array_values($deleted_users))->delete();
         }
     }
     return redirect()->to('users')->with('message_content', '同步成功!')->with('message_type', 'info');
 }
 public function postGroupList(Request $request)
 {
     //新增职务
     if ($request->has('new_cp_group_name')) {
         $new_cp_group_name = $request->input('new_cp_group_name');
         if (in_array($new_cp_group_name, array('系统管理员', '超级管理员')) || AdminGroup::where('cp_group_name', '=', $new_cp_group_name)->first()) {
             return redirect($this->redirectPath('/user/groups'))->withErrors([Lang::get('access.addNewCpGroupFailed')]);
         }
         $adminGroup = new AdminGroup();
         $adminGroup->cp_group_name = strip_tags($new_cp_group_name);
         $adminGroup->save();
     }
     //更新职务
     if ($request->has('name')) {
         foreach ($request->input('name') as $cp_group_id => $cp_group_name) {
             $adminGroup = AdminGroup::find($cp_group_id);
             $adminGroup->cp_group_name = $cp_group_name;
             $adminGroup->save();
         }
     }
     //删除职务
     if ($request->has('delete')) {
         AdminAccess::destroy($request->input('delete'));
         User::whereIn('cp_group_id', $request->input('delete'))->delete();
         AdminGroup::destroy($request->input('delete'));
     }
     return redirect($this->redirectPath('/user/groups'))->with($this->statusVar, Lang::get('access.updateCpGroupSuccess'));
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(Mailer $mail)
 {
     $group = $this->ticket->group_id;
     $customers = Group::where('id', $group)->first()->customers()->get();
     $_customers = [];
     foreach ($customers as $customer) {
         $_customers[] = $customer->id;
     }
     $sys_name = Settings::where('name', 'sys_name')->first();
     $user = User::whereIn('customer_id', $_customers)->get();
     foreach ($user as $_user) {
         $mail->send('emails.updateticket', ['user' => $_user, 'ticket' => $this->ticket, 'response' => $this->response, 'sys_name' => $sys_name], function ($m) use($_user) {
             $m->to($_user->email, $_user->first_name . ' ' . $_user->last_name)->subject('Ticket updated - ' . $this->ticket->track_id . ' [' . $this->ticket->status->name . ']');
             if (count($this->response->attachments()->get()) > 0) {
                 foreach ($this->response->attachments as $attachment) {
                     $m->attach(storage_path() . '/attachments/' . $this->ticket->id . '/' . $attachment->name);
                 }
             }
         });
     }
     // Cleanup variables
     unset($this->ticket);
     unset($this->response);
     unset($group);
     unset($customers);
     unset($user);
     unset($sys_name);
     unset($_customers);
 }
Example #7
0
 public static function notify($idArr = array(), $body, $type, $to_all = 0, $is_system = 0)
 {
     $currentId = auth()->id();
     if (!$currentId) {
         return;
     }
     $data = $notifiedUidArr = [];
     $now = \Carbon\Carbon::now();
     if ($to_all) {
         $data = ['user_id' => 0, 'body' => $body, 'type' => $type, 'to_all' => $to_all, 'is_system' => $is_system, 'created_at' => $now, 'updated_at' => $now];
     } elseif (!empty($idArr)) {
         $idArr = array_unique($idArr);
         foreach ($idArr as $id) {
             if ($id == $currentId) {
                 return;
             }
             $data[] = ['user_id' => $id, 'body' => $body, 'type' => $type, 'to_all' => $to_all, 'is_system' => $is_system, 'created_at' => $now, 'updated_at' => $now];
             $notifiedUidArr[] = $id;
         }
     }
     if (!empty($data)) {
         Notify::insert($data);
         if ($to_all) {
             \DB::table('users')->increment('notice_count');
         } elseif ($notifiedUidArr) {
             User::whereIn('id', $notifiedUidArr)->increment('notice_count');
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $projectdetails = ['name' => 'shitzu', 'description' => 'frickzena oah auhsdoh vgos'];
     $taskdetails = ['name' => 'joozie', 'description' => 'ahioihd poaiy7u ascihogyfcd pouaou'];
     $taskdetails2 = ['name' => 'ambroze', 'description' => 'shitzu prickzen la frickzen'];
     $statusdetails = ['message' => 'hello wazzup?'];
     DB::table('projects')->delete();
     DB::table('users_projects')->delete();
     DB::table('stories')->delete();
     DB::table('sprints')->delete();
     DB::table('backlogs')->delete();
     // optional
     DB::table('comments')->delete();
     DB::table('statuses')->delete();
     $user1 = User::firstOrFail();
     $user2 = User::all()->last();
     $project = Bus::dispatch(new CreateProject($user1, $projectdetails));
     Bus::dispatch(new AddUserToProject($user1, $project, $user2, 'developer'));
     $users = User::whereIn('id', [$user1->id, $user2->id])->get();
     $backlog = App\Backlog::create(['name' => 'Release Elixir']);
     $user1->backlogs()->save($backlog);
     $project->backlogs()->save($backlog);
     $sprint = App\Sprint::create(['name' => 'Sprint Shikku']);
     $project->sprints()->save($sprint);
     $backlog->sprints()->save($sprint);
     $user1->sprints()->save($sprint);
     $datas = [['name' => 'Refactoring Iceblocks', 'description' => 'Cool tasks are always cool. So do this !!', 'priority' => 1, 'work_hours' => '7'], ['name' => 'Streaming section', 'description' => 'This is one of the besttask ever i ve seen in my life time => )', 'priority' => 0, 'work_hours' => '2'], ['name' => 'Urgent Completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '8'], ['name' => 'Elangent Model shift', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 2, 'work_hours' => '5'], ['name' => 'Bug trakking system', 'description' => 'This task is for powerful people.. Yeah you..! ', 'priority' => 1, 'work_hours' => '2'], ['name' => 'Featured blog completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '6'], ['name' => 'Quick finish', 'description' => 'Super awesome task you will love it i know it, can you just finish this.. ? sothat we can move On..', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Trapped module refactoring', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 3, 'work_hours' => '2'], ['name' => 'Smooth UI Design', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 2, 'work_hours' => '4'], ['name' => 'Refactoring Iceblocks', 'description' => 'Major refactor needed in the sublimentory section of zylanfuzku Masked version.Its all about the stuffs and stone of the rechard steven.', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Urgent Completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '8'], ['name' => 'Elangent Model shift', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 2, 'work_hours' => '5'], ['name' => 'Bug trakking system', 'description' => 'This task is for powerful people.. Yeah you..! ', 'priority' => 1, 'work_hours' => '2'], ['name' => 'Featured blog completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '6'], ['name' => 'Quick finish', 'description' => 'Super awesome task you will love it i know it, can you just finish this.. ? sothat we can move On..', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Trapped module refactoring', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 3, 'work_hours' => '2'], ['name' => 'Quick finish', 'description' => 'Super awesome task you will love it i know it, can you just finish this.. ? sothat we can move On..', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Trapped module refactoring', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 3, 'work_hours' => '2'], ['name' => 'Smooth UI Design', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 2, 'work_hours' => '4'], ['name' => 'Refactoring Iceblocks', 'description' => 'Major refactor needed in the sublimentory section of zylanfuzku Masked version.Its all about the stuffs and stone of the rechard steven.', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Urgent Completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '8'], ['name' => 'Elangent Model shift', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 2, 'work_hours' => '5'], ['name' => 'Bug trakking system', 'description' => 'This task is for powerful people.. Yeah you..! ', 'priority' => 1, 'work_hours' => '2'], ['name' => 'Featured blog completion', 'description' => 'This is a urgent task . U should make the system flow for ever', 'priority' => 3, 'work_hours' => '6'], ['name' => 'Quick finish', 'description' => 'Super awesome task you will love it i know it, can you just finish this.. ? sothat we can move On..', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Trapped module refactoring', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 3, 'work_hours' => '2'], ['name' => 'Quick finish', 'description' => 'Super awesome task you will love it i know it, can you just finish this.. ? sothat we can move On..', 'priority' => 0, 'work_hours' => '7'], ['name' => 'Trapped module refactoring', 'description' => 'Super awesome task you will love it i know ...!!', 'priority' => 3, 'work_hours' => '2']];
     foreach ($datas as $data) {
         $story = App\Story::create($data);
         $project->stories()->save($story);
         $user1->createdStories()->save($story);
     }
 }
Example #9
0
 public function parse($body)
 {
     $this->body_original = $body;
     $this->usernames = $this->getMentionedUsername();
     count($this->usernames) > 0 && ($this->users = User::whereIn('name', $this->usernames)->get());
     $this->replace();
     return $this->body_parsed;
 }
Example #10
0
 public static function dependentsOkay($dependentIDList)
 {
     $accountID = Auth::user()->id;
     $matchCount = User::whereIn('id', $dependentIDList)->where(function ($query) use($accountID) {
         $query->where('accountId', '=', $accountID)->where('approved', '<>', 'false');
     })->count();
     return $matchCount == sizeof($dependentIDList);
 }
 public static function getUsersString($id)
 {
     $result = "";
     $_users = ConversationUser::where(['conversation_id' => $id])->get(['user_id']);
     $users = User::whereIn('id', $_users)->get();
     foreach ($users as $user) {
         if ($user->id != Auth::id()) {
             $result = $result . $user->name . " " . $user->surname . ", ";
         }
     }
     return rtrim($result, ", ");
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $images = Picture::where('user_id', '=', Auth::user()->id)->where('isDish', '=', false)->orderBy('id', 'desc')->take(5)->get();
     $profile = User::find(Auth::user()->id);
     $favoriteDish = explode(';', $profile->favoriteDish);
     $time = explode("-", $profile->dateOfBirth);
     $dt = Carbon::createFromDate($time[0], $time[1], $time[2], 'Europe/Brussels');
     $now = Carbon::today();
     $age = $now->diffInYears($dt);
     $profile->age = $age;
     foreach ($favoriteDish as $key => $value) {
         if ($value == "") {
             unset($favoriteDish[$key]);
         }
     }
     $profile->favoriteDishArray = $favoriteDish;
     $friends = User::where('id', '=', Auth::user()->id)->first()->friends()->get();
     $friendRequests = Friend::where('friend_id', '=', Auth::user()->id)->where('accepted', '=', false)->get();
     $mayLike = array();
     foreach ($profile->tastes as $taste) {
         $othersTaste = $taste->users()->where('user_id', '<>', Auth::user()->id)->where('taste_id', $taste->id)->get();
         foreach ($othersTaste as $user) {
             $mayLike[] = $user->id;
         }
     }
     //count how many times an id apears in array
     $CountMayLikes = array_count_values($mayLike);
     //sort from high to low
     arsort($CountMayLikes);
     //var_dump($CountMayLikes);
     $sortedArray = [];
     foreach ($CountMayLikes as $id => $value) {
         $sortedArray[] = $id;
     }
     //var_dump($sortedArray);
     //give te first 10z
     $pYML = array_slice($sortedArray, 0, 10);
     $people = User::whereIn('id', $pYML)->select('id', 'name', 'surname', 'country', 'city', 'dateOfBirth')->get();
     foreach ($people as $person) {
         // var_dump($person->id);
         $picture_url = Picture::where('user_id', $person->id)->select('picture_url')->first();
         // echo '<pre>';
         // var_dump($picture_url['picture_url']);
         $person->picture_url = $picture_url['picture_url'];
     }
     $smaken = Taste::select('id', 'tastes')->get();
     $tasts = array();
     foreach ($smaken as $smaak) {
         $tasts[$smaak->id] = $smaak->tastes;
     }
     $data = ['profile' => $profile, 'friends' => $friends, 'friendRequests' => $friendRequests, 'images' => $images, 'tasts' => $tasts, 'peoples' => $people];
     return View('dashboard')->with($data);
 }
 public function index(Request $request)
 {
     // 获取排序条件
     $orderColumn = $request->get('sort_up', $request->get('sort_down', 'created_at'));
     $direction = $request->get('sort_up') ? 'asc' : 'desc';
     $members = User::whereIn('level', ['003', '002'])->whereHas('roles', function ($query) {
         $query->where('slug', 'member');
     })->orderBy($orderColumn, $direction)->paginate(8);
     $nonMembers = User::where('level', '001')->whereHas('roles', function ($query) {
         $query->where('slug', 'member');
     })->orderBy($orderColumn, $direction)->paginate(8);
     return view('admin.user.list', compact('members', 'nonMembers', 'query'));
 }
Example #14
0
 function getTask()
 {
     $user = \Auth::user();
     $events = Event::all();
     $event = Event::latest('id')->first();
     $tasks = Task::all();
     $categories = array('Pending', 'In-progress', 'Delayed', 'Finished');
     //Array of head->id of user
     $heads_comm = Head::where('event_id', $event->id)->where('user_id', $user->id)->get(array('comm_id'))->toArray();
     //members of committee
     $mem = Member::whereIn('comm_id', $heads_comm)->get(array('user_id'))->toArray();
     $members = User::whereIn('id', $mem)->get();
     //committees where user is head
     $committees = Committee::whereIn('id', $heads_comm)->get();
     return view('pages/task', compact('user', 'members', 'events', 'event', 'committees', 'tasks', 'categories'));
 }
 public function addMember(AddMemberToProjectRequest $request)
 {
     $owner = Auth::user();
     $users_id = $request->users;
     // 傳進來的資料再做一次搜尋,確定傳進來的資料在資料庫都存在
     $users = User::whereIn('id', $users_id)->get();
     $projectId = $request->project_id;
     $project = $owner->projects()->find($projectId);
     $relationshipData = [];
     foreach ($users as $user) {
         $relationshipData[] = $user->id;
     }
     // 為project加入關聯
     $project->users()->attach($relationshipData, ['role' => $request->role]);
     return $project->users()->whereIn('id', $users_id)->get();
 }
Example #16
0
 /**
  * 사용자를 json형태로 가져옴
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 private function getUserCollection(Request $request)
 {
     $type = $request->get('type', 'dept_id');
     $value = $request->get('value', '0');
     $list = collect([]);
     switch ($type) {
         case 'dept_id':
             $dept = Department::find($value);
             if ($dept) {
                 $allDepts = $dept->allChildDepartments();
                 $list = User::whereIn('dept_id', $allDepts->pluck('id')->toArray())->get();
             }
             break;
     }
     return $list;
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('partials.navigation', function ($view) {
         if (Auth::guest()) {
             //とりあえず
             $rooms = Room::take(10)->get();
             $friends = User::all();
             $view->with(['rooms' => $rooms, 'friends' => $friends]);
         } else {
             $user_id = Auth::user()->id;
             $rooms = User::find($user_id)->room;
             $friends_id_lists = User::find($user_id)->friends->lists('friends_id');
             $friends = User::whereIn('id', $friends_id_lists)->get();
             $friends_request = Friends::where('friends_id', $user_id)->where('friends_request', 1)->get();
             //$friends_request = Friends::whereIn('user_id' , $friends_request_lists)->get();
             $view->with(['rooms' => $rooms, 'friends' => $friends, 'friends_request' => $friends_request]);
         }
     });
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = $this->getRestrictions();
     $validator = Validator::make($request->all(), $rules);
     // process the login
     if ($validator->fails()) {
         return redirect('/families/create')->withErrors($validator)->withInput($request->all());
     } else {
         // store
         $family = new Family();
         $family = $this->assignValues($request, $family);
         $family->save();
         User::whereIn("id", $request->input('members'))->update(["family_id" => $family->id]);
         Session::flash('status', 'Successfully created the Family!');
         return redirect('/families');
     }
 }
Example #19
0
 /**
  * Display the friends of the User
  *
  * @param  int  $id
  * @param  int	$level
  * @return Response
  */
 public function show($id, $level = 1)
 {
     try {
         $friends_by_level = [];
         $names = ["User_" . $id];
         for ($i = 1; $i <= $level; $i++) {
             $cur_level = User::whereIn("name", $names)->get();
             foreach ($cur_level as $cur) {
                 $friends = $cur->friend()->get()->toArray();
                 foreach ($friends as $friend) {
                     if (!in_array($friend['name'], $names) && $friend['name'] != "User_" . $id) {
                         $names[] = $friend['name'];
                         $friends_by_level[$i][] = $friend;
                     }
                 }
             }
         }
         return response()->json($friends_by_level);
     } catch (Exception $e) {
         dd($e->getMessage());
     }
 }
 /**
  * Shows a message thread
  *
  * Example URL: GET /api/v1/messages/1?api_key=30ce6864e2589b01bc002b03aa6a7923
  *
  * @param MessageTransformer $messageTransformer
  * @param $id
  * @return mixed
  */
 public function show(MessageTransformer $messageTransformer, $id)
 {
     $userId = $this->user->id;
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return $this->respondNotFound('Sorry, the message thread was not found.');
     }
     $thread->markAsRead($userId);
     $messageData = $thread->toArray();
     // Get messages
     $messages = $thread->messages()->with('user')->get();
     $messageData['messages'] = $messages->toArray();
     // Get participants
     $participants = User::whereIn('id', $thread->participantsUserIds())->get();
     $messageData['participants'] = $participants->toArray();
     // Get non-participants
     $nonParticipants = User::whereNotIn('id', $thread->participantsUserIds())->get();
     $messageData['non_participants'] = $nonParticipants->toArray();
     $data = $messageTransformer->transform($messageData);
     $response = ['data' => $data];
     return $this->respondWithSuccess($response);
 }
 public function shifts_progress($gen_id = null)
 {
     if ($gen_id) {
         $current_gen = Gen::find($gen_id);
     } else {
         $current_gen = Gen::getCurrentGen();
     }
     $weeks = $current_gen->shifts()->get()->pluck('week')->unique()->sortByDesc(function ($week, $key) {
         return $week;
     });
     $return_arr = [];
     foreach ($weeks as $week) {
         $week_shifts = $current_gen->shifts()->where('week', $week)->get();
         $user_ids = $week_shifts->pluck('user_id');
         $users = User::whereIn('id', $user_ids)->get();
         $shift_count_arr = [];
         $max_count = 0;
         foreach ($users as $user) {
             $count = $user_ids->filter(function ($item) use($user) {
                 return $item == $user->id;
             })->count();
             if ($count > $max_count) {
                 $max_count = $count;
             }
             $shift_count_arr[] = ['count' => $count, 'user' => ['name' => $user->name, 'url' => url('profile/' . get_first_part_of_email($user->email))]];
         }
         $return_arr[] = ['week' => $week, 'progresses' => $shift_count_arr, 'max_count' => $max_count];
     }
     return response()->json($return_arr);
 }
 public function editTeam($id)
 {
     if (!$this->auth()) {
         return "You have no Permissions!";
     }
     $team = team::where('teamID', '=', $id)->first();
     $students = team_contents::where('teamID', '=', $id)->get(array('studentID'));
     $s = array();
     foreach ($students as $a) {
         array_push($s, $a->studentID);
     }
     $teamContents = User::whereIn('id', $s)->get();
     $allStudents = User::whereNotIn('id', $s)->get();
     return view('editTeam', compact('team', 'teamContents', 'allStudents'));
 }
Example #23
0
 public function testTaskOwnership()
 {
     $project = Project::has('users', '>', 1)->first();
     $user1 = $project->users()->wherePrivilegeLevel('1')->first();
     $user2 = $project->users()->where('id', '!=', $user1->id)->first();
     // echo "users {$user1->id} {$user2->id}";
     $users = User::whereIn('id', [$user1->id, $user2->id])->get();
     $this->assertNotNull($users);
     $this->assertEquals(2, $users->count());
     $task = Bus::dispatch(new CreateTask($user1, ['name' => 'poopech'], $project, null, $users));
     $this->assertTrue($task->users->contains($user1->id));
     $this->assertTrue($task->users->contains($user2->id));
 }
Example #24
0
 /**
  * Update users to lead
  * 
  * @param  AdminShowRequest $request
  * @param  Integer $id
  * @return Redirect
  */
 public function putUpdateLeadUsers(AdminShowRequest $request, $id)
 {
     $lead = Lead::find($id);
     // Update roles
     if ($request->has('role')) {
         $roles = $request->get('role');
         $users = User::whereIn('id', array_keys($roles))->where('id', '!=', Auth::id())->get();
         foreach ($users as $user) {
             $role = strtolower($roles[$user->id]);
             $current_role = $lead->users()->where('user_id', $user->id)->first()->pivot->type;
             if ($role != $current_role) {
                 $lead->users()->updateExistingPivot($user->id, ['lead_id' => $lead->id, 'type' => $role]);
             }
         }
     }
     // Update deletes
     if ($request->has('delete')) {
         $users = User::whereIn('id', array_keys($request->get('delete')))->get();
         // Remove user pivots as necessary
         foreach ($users as $user) {
             $role = $lead->users()->where('user_id', $user->id)->first()->pivot->type;
             $lead->users()->newPivotStatementForId($user->id)->where('lead_id', $id)->delete();
         }
     }
     return redirect('leads/' . $id . '/assign_lead')->with('status', \Lang::get('lead.updated_users'));
 }
 /**
  * Update users for campaign
  * 
  * @param  AdminUpdateUsersRequest $request
  * @param  Integer $id
  * @return Redirect
  */
 public function putUpdateUsers(AdminUpdateUsersRequest $request, $id)
 {
     // Update roles
     if ($request->has('role')) {
         $roles = $request->get('role');
         $users = User::whereIn('id', array_keys($roles))->where('id', '!=', Auth::id())->get();
         foreach ($users as $user) {
             $role_id = (int) $roles[$user->id];
             $current_role_id = $user->roles()->where('campaign_id', $id)->first()->id;
             if ($role_id != $current_role_id) {
                 $user->roles()->updateExistingPivot($user->id, ['role_id' => $role_id]);
             }
         }
     }
     // Update deletes
     if ($request->has('delete')) {
         $users = User::whereIn('id', array_keys($request->get('delete')))->where('id', '!=', Auth::id())->get();
         // Remove user pivots as necessary
         foreach ($users as $user) {
             $role_id = $user->roles()->where('campaign_id', $id)->first()->id;
             $user->roles()->newPivotStatementForId($role_id)->where('campaign_id', $id)->delete();
         }
     }
     return redirect('campaigns/' . $id . '/add_users')->with('status', \Lang::get('campaign.updated_users'));
 }
 public function scopeGetActiveUsersCount($query, $id)
 {
     $count = User::whereIn('status', array('NEW', 'ACTIVE', 'RESET'))->where('company_id', '=', $id)->count();
     return $count . " users";
 }
Example #27
0
 public function deleteByIds($ids)
 {
     $result = User::whereIn('id', $ids)->delete();
     return $result;
 }
 public function update(DepartmentRequest $request, $id)
 {
     $allWorker = DB::table('department_worker')->where('department_id', '!=', \Crypt::decrypt($request->id))->get(['user_id']);
     $duplicateWorker = [];
     $leader = $request->department_leader;
     $departmentUsers = $request->department_worker;
     array_push($departmentUsers, $request->department_leader);
     $departmentUsers = array_unique($departmentUsers);
     foreach ($allWorker as $aw) {
         if (in_array($aw->user_id, $request->department_worker)) {
             array_push($duplicateWorker, $aw->user_id);
         }
     }
     if (!empty($duplicateWorker)) {
         $users = User::whereIn('id', $duplicateWorker)->select(DB::raw('CONCAT(first_name," ",last_name) as full_name'))->get();
         $usersString = '';
         foreach ($users as $u) {
             $usersString .= $u->full_name . ',';
         }
         return response()->json(['messages' => $usersString . ' Kişileri Başka Bir Departmana Bağlıdır.'], 422);
     } else {
         foreach ($departmentUsers as $key => $value) {
             $value == $leader ? $departmentUsers[$key] = ['user_id' => $value, 'is_senior' => 1] : ($departmentUsers[$key] = ['user_id' => $value, 'is_senior' => 0]);
         }
         $this->permissionSection(function () use($request, $departmentUsers) {
             DB::transaction(function () use($request, $departmentUsers) {
                 $department = Department::where('id', '=', \Crypt::decrypt($request->id))->first();
                 $department->slug = $request->slug_name;
                 $department->name = $request->department_name;
                 $department->save();
                 $department->worker()->detach();
                 $department->worker()->sync($departmentUsers);
             });
         }, 'wts.department.edit');
         return response()->json($this->editResponseMessage);
     }
 }
Example #29
0
 /**
  * A list is users from company 'company' with permission to 'permission'
  *
  * @return collection
  */
 public function usersWithPermissionTo($permission, $company = '')
 {
     if ($company == 'all') {
         $user_list = $this->userList;
     } elseif ($company) {
         $user_list = $company->staff;
     } else {
         $user_list = $this->staff;
     }
     $user_can_list = [];
     foreach ($user_list as $user) {
         if ($user->can($permission)) {
             $user_can_list[] = $user->id;
         }
     }
     return User::whereIn('id', $user_can_list)->get();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \DB::table('laraboard_posts')->truncate();
     $faker = \Faker\Factory::create();
     //  create some categories
     foreach (range(1, rand(3, 7)) as $c) {
         $category = new \Christhompsontldr\Laraboard\Models\Post();
         $category->name = ucwords(str_replace('.', '', $faker->sentence(rand(1, 3))));
         $category->body = rand(1, 6) == 6 ? $faker->sentence : null;
         $category->type = 'Category';
         $category->user_id = \App\User::whereIn('id', collect(\DB::select('SELECT id FROM users'))->pluck('id')->toArray())->get()->random()->id;
         $category->ip = $faker->ipv4;
         $category->created_at = \Carbon\Carbon::now()->subMonths(rand(6, 24))->subHours(rand(1, 24))->subMinutes(rand(1, 59));
         $category->updated_at = $category->created_at;
         $category->save();
         //  1 in 10 chance there are no boards
         if (rand(1, 10) == 10) {
             continue;
         }
         $previous_board = $previous_thread = $previous_reply = $category;
         //  make some boards
         foreach (range(1, rand(2, 3)) as $b) {
             $board = new \Christhompsontldr\Laraboard\Models\Post();
             $board->name = ucwords(str_replace('.', '', $faker->sentence(rand(1, 5))));
             $board->body = rand(1, 6) == 6 ? $faker->sentence : null;
             $board->type = 'Board';
             $board->user_id = \App\User::whereIn('id', collect(\DB::select('SELECT id FROM users'))->pluck('id')->toArray())->get()->random()->id;
             $board->ip = $faker->ipv4;
             $board->created_at = \Carbon\Carbon::parse($previous_board->created_at)->addMinutes(rand(1, 500));
             $board->updated_at = $board->created_at;
             $board->save();
             $board->makeChildOf($category);
             //  1 in 10 chance there are no threads
             if (rand(1, 10) == 10) {
                 continue;
             }
             $previous_board = $previous_thread = $previous_reply = $board;
             //  make some threads
             foreach (range(1, rand(1, 20)) as $b) {
                 $rand = $b == 1 ? rand(1, 60) : rand(1, 300);
                 $thread = new \Christhompsontldr\Laraboard\Models\Post();
                 $thread->name = $faker->sentence(rand(3, 10));
                 $thread->body = implode("\n\n", $faker->paragraphs($faker->randomDigitNotNull));
                 $thread->type = 'Thread';
                 $thread->user_id = \App\User::get()->random()->id;
                 $thread->ip = $faker->ipv4;
                 $thread->created_at = \Carbon\Carbon::parse($previous_thread->created_at)->addMinutes($rand);
                 $thread->updated_at = $thread->created_at;
                 $thread->save();
                 $thread->makeChildOf($board);
                 $previous_thread = $previous_reply = $thread;
                 //  1 in 10 chance there are no replies
                 if (rand(1, 10) == 10) {
                     continue;
                 }
                 //  make some replies
                 foreach (range(1, rand(1, 50)) as $r) {
                     $reply = new \Christhompsontldr\Laraboard\Models\Post();
                     $reply->body = file_get_contents('https://jaspervdj.be/lorem-markdownum/markdown.txt?num-blocks=' . rand(1, 6) . '&no-headers=true');
                     $reply->type = 'Reply';
                     $reply->user_id = \App\User::get()->random()->id;
                     $reply->ip = $faker->ipv4;
                     $reply->created_at = \Carbon\Carbon::parse($previous_reply->created_at)->addMinutes($rand);
                     $reply->updated_at = $reply->created_at;
                     $reply->save();
                     $reply->makeChildOf($thread);
                     $previous_reply = $reply;
                 }
             }
         }
     }
 }