public function getUsersByRole($role) { $users = User::whereHas('userRole', function ($q) use($role) { return $q->where('user_role_name', $role); })->get()->toArray(); return $users; }
public function index() { $season = $_REQUEST['season'] ?: $this->season; $activity = $_REQUEST['activity'] ?: 'Poker'; $venue_id = $_REQUEST['venue_id'] ?: League::where('season', $season)->where('activity', $activity)->value('venue_id'); $league = League::where('season', $season)->where('activity', $activity)->where('venue_id', $venue_id)->first(); if (!$league->id) { $_SESSION['ALERT'] = alert("No League Found!", "There were no leagues found matching the specified parameters.", "warning"); return sizeof($_REQUEST) ? redirect("/rankings") : redirect("/"); } $rankings_query = ' select s.player_id as id, concat(p.lastname, ", ", p.forename) as name, concat(p.forename, " ", p.lastname) as fullname, count(*) as games, sum(s.points) as total '; $rankings_query .= ' from t_scores s '; $rankings_query .= ' join t_events e on e.id = s.event_id '; $rankings_query .= ' join t_players p on p.id = s.player_id '; $rankings_query .= ' where e.league_id=? '; $rankings_query .= ' group by s.player_id '; $rankings = DB::select($rankings_query, [$league->id]); $points_query = ' select points '; $points_query .= ' from t_scores '; $points_query .= ' where player_id=? '; $points_query .= ' and event_id in ( '; $points_query .= ' select id '; $points_query .= ' from t_events '; $points_query .= ' where league_id=? '; $points_query .= ' ) '; $points_query .= ' order by points desc '; $points_query .= ' limit ' . $league->ranked_at; array_walk($rankings, function (&$ranking) use($points_query, $league) { $ranking->points = DB::select($points_query, [$ranking->id, $league->id]); $ranking->points = array_map(function ($p) { return $p->points; }, $ranking->points); $ranking->value = $ranking->games >= $league->ranked_at ? $league->ranking == 'AVG' ? floor(array_sum($ranking->points) / $league->ranked_at) : array_sum($ranking->points) : -1; }); $ranked = array_filter($rankings, function ($ranking) { return $ranking->value !== -1; }); usort($ranked, function ($a, $b) { return $b->value - $a->value; }); $unranked = array_filter($rankings, function ($ranking) { return $ranking->value === -1; }); usort($unranked, function ($a, $b) { return $b->total - $a->total; }); $seasonPointsLeaders = array_filter($rankings, function ($ranking) { return $ranking->total > 0; }); usort($seasonPointsLeaders, function ($a, $b) { return $b->total - $a->total; }); $seasonPointsLeaders = array_slice($seasonPointsLeaders, 0, 1); $wildCardWinners = User::whereHas('scores', function ($query) use($league) { $query->where('finished', '1')->whereHas('event', function ($query) use($league) { $query->where('league_id', $league->id)->where('week_num', 'Wild Card'); }); })->get(); return view('pages.rankings', compact('league', 'ranked', 'unranked', 'seasonPointsLeaders', 'wildCardWinners')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $auctions = Auction::all(); foreach ($auctions as $auction) { $enddate = new DateTime($auction->enddate); $now = new Datetime(); if ($enddate < $now) { $highest_bid = $auction->highest_bid; $auction_id = $auction->id; $highest_bidder = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) { $q->where('amount', '=', $highest_bid)->where('auction_id', '=', $auction_id); })->first(); if ($highest_bidder) { $bidders = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) { $q->where('auction_id', $auction_id)->where('amount', '>', $highest_bid); })->get(); foreach ($bidders as $bidder) { $this->info($auction->title . ' was not sold to ' . $bidder->email); Mail::send('mails.loser', ['user' => $bidder], function ($ms) use($bidder) { $ms->to($bidder->email, $bidder->company)->subject('Too bad!'); }); } Mail::send('mails.winner', ['user' => $highest_bidder], function ($ms) use($highest_bidder) { $ms->to($highest_bidder->email, $highest_bidder->company)->subject('Congratulations!'); }); $this->info($auction->title . ' was sold to ' . $highest_bidder->company); } else { $auction->active = false; $auction->expired = true; $auction->save(); $this->info($auction->title . ' is expired.'); } } } }
public function mapa() { $vendedores = User::whereHas('PerfilUsuario', function ($query) { $query->where('tipo', '=', 'Vendedor'); })->with('PerfilUsuario')->get(); return view('Vendedor.Mapa')->with('vendedores', $vendedores); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { //listing all farmer when no search is done $allfarmer = User::where('user_type_id', 3)->paginate(10); //$allfarmer = User::where('user_type_id', 3)->get(); /previous code //listing Farmerpoint for dropdown $farmerPointList = FarmerPoint::Lists('name', 'id'); $cropList = Crop::Lists('name', 'id'); //recieving data from search field $farmer_name = $request->input('name'); $farmer_phone = $request->input('phone'); $farmerInPoint = $request->input('id'); $farmerWithCrop = $request->input('crop'); if (!empty($farmer_name)) { $allfarmer = User::where('user_type_id', 3)->where('name', 'LIKE', '%' . $farmer_name . '%')->paginate(10); } if (!empty($request->phone)) { $allfarmer = User::where('user_type_id', 3)->where('phone', 'LIKE', '%' . $farmer_phone . '%')->paginate(10); } if (!empty($farmerInPoint)) { if (!empty($farmerWithCrop)) { $allfarmer = User::whereHas('farmerCrop', function ($query) use($farmerWithCrop) { $query->where('crop_id', $farmerWithCrop); })->where('user_type_id', 3)->where('farmer_point_id', $farmerInPoint)->paginate(10); } else { $allfarmer = User::where('user_type_id', 3)->where('farmer_point_id', $farmerInPoint)->paginate(10); } } if (!empty($farmerWithCrop)) { $allfarmer = User::whereHas('farmerCrop', function ($query) use($farmerWithCrop) { $query->where('crop_id', $farmerWithCrop); })->where('user_type_id', 3)->paginate(10); } return view('farmer.FarmerList', ['allfarmer' => $allfarmer, 'farmerPointList' => $farmerPointList, 'cropList' => $cropList]); }
public function getAssignedUsersToGroup($groupId) { $users = User::whereHas('groups', function ($q) use($groupId) { $q->where('group_id', $groupId); })->where('role', '<', 2)->paginate(5); return $users; }
public function postAddUserAsFriend($username) { $user = User::whereHas('profile', function ($q) use($username) { $q->whereUsername($username); })->first(); $user->friends()->attach(auth()->user()); redirect()->to('/'); }
public function testUserRestore() { $UserAdmin = \App\User::whereHas('role', function ($q) { $q->where('admin', true); })->first(); $this->be($UserAdmin); $User = \App\User::create(['email' => str_random(5) . '@' . str_random(3) . '.com']); $id = $User->id; $User = \App\User::withTrashed()->where('id', $id)->first(); $this->call('GET', route('admin.users.restore', $User->id)); $User->forceDelete(); $this->assertRedirectedToRoute('admin.users.list'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $start = Carbon::createFromTimeStamp(Input::get('start'), 'America/Chicago'); $end = Carbon::createFromTimeStamp(Input::get('end'), 'America/Chicago'); //All Timecards for the period $timecards = \App\Timecard::with('user')->timecardsForPeriod($start, $end)->get(); return $timecards; //Users with at least 1 timecard for period $users = \App\User::whereHas('timecards', function ($q) use($timecards) { $q->whereIn('id', $timecards); })->with('timecards')->get(); //must do this to remove extra timecards included with wherehas statement return $this->groupTimecardsByUser($users, $timecards); }
public static function users($company_id, $start, $end) { if ($company_id == null) { return null; } $arr = []; $users = User::whereHas('company', function ($q) use($company_id) { $q->where('companies.id', $company_id); })->with('info')->get(); foreach ($users as $user) { array_push($arr, self::singleUser($user, $start, $end, $company_id)); } return $arr; }
public function statistics() { $users = User::whereHas('trials', function ($query) { $query->where('complete', true); })->get(); $totalUsers = $users->count(); $totalTrials = Trial::whereComplete(true)->count(); $totalHits = Trial::whereComplete(true)->has('hits', '>', 0)->count(); $totalSelections = Selection::whereHas('trial', function ($query) { $query->where('complete', true); })->count(); $totalChoices = $totalTrials * 5; $targets = Target::has('expiredExperiment')->get(); // $targets = Target return view('pages.statistics')->with(compact('totalUsers', 'totalTrials', 'totalHits', 'totalSelections', 'totalChoices', 'targets')); }
public function getTypeUsers(request $request, $type) { $users = User::whereHas('roles', function ($q) use($type) { $q->where('name', $type); })->orderby('id', 'DESC')->paginate(15); $output = array('users' => $users); return view('admin.users', $output); }
public function examinees() { $user = auth()->user(); if ($user->isExaminer()) { $quizzes = Quiz::with('tests')->where('user_id', $user->id)->lists('id'); $examinees = User::whereHas('tests', function ($query) use($quizzes) { $query->whereIn('quiz_id', $quizzes); })->get(); } else { if ($user->isExaminee()) { $examinees = User::where('id', $user->id)->get(); } else { $examinees = User::has('tests')->get(); } } return view('tests.examinees', compact('examinees')); }
public function teammate() { $admins = User::whereHas('group', function ($q) { $q->where('group_id', 1); })->get(); $mods = User::whereHas('group', function ($q) { $q->where('group_id', 2); })->get(); $gms = User::whereHas('group', function ($q) { $q->where('group_id', 3); })->get(); return view('main.teammate', compact('admins', 'mods', 'gms')); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('results')->delete(); DB::table('group_indicator')->delete(); DB::table('group_user')->delete(); DB::table('indicator_organization')->delete(); DB::table('indicator_report')->delete(); DB::table('report_user')->delete(); DB::table('users')->delete(); DB::table('organizations')->delete(); DB::table('roles')->delete(); DB::table('indicators')->delete(); DB::table('groups')->delete(); DB::table('reports')->delete(); $roles = array(['name' => 'admin', 'display_name' => 'Admin'], ['name' => 'manager', 'display_name' => 'Manager'], ['name' => 'employee', 'display_name' => 'Employee']); foreach ($roles as $role) { Role::create($role); } $faker = Faker::create('pl_PL'); $indicators = array(['name' => 'Wydane skierowania', 'function_name' => 'wyd_skier_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba skierowań wydanych przez pracownika w badanym okresie.'], ['name' => 'Obsłużone wizyty', 'function_name' => 'obsluz_wiz_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba wizyt obsłużonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone ind. porady zawodowe', 'function_name' => 'ind_por_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych porad zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone grupowe porady zawodowe', 'function_name' => 'grup_por_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba grupowych porad zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone indywidualne inf. zawodowe', 'function_name' => 'ind_inf_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych informacji zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Zorganizowane grupowe inf. zawodowe', 'function_name' => 'grup_inf_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba grupowych informacji zawodowych zorganizowanych przez pracownika w badanym okresie.'], ['name' => 'Badania kwest. do profilowania', 'function_name' => 'bad_kwest_prof_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba badań kwestionariuszem do profilowania przeprowadzonych przez pracownika w badanym okresie.'], ['name' => 'Sporządzone IPD', 'function_name' => 'sporz_ipd_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych planów działania sporządzonych przez pracownika w badanym okresie.'], ['name' => 'Zarejestrowani kontrahenci', 'function_name' => 'zarej_kontr_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba kontrahentów zarejestrowanych przez pracownika w badanym okresie.'], ['name' => 'Kontakty z kontrahentami', 'function_name' => 'kont_kontr_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba kontaktów z kontrahentami zrealizowanych przez pracownika w badanym okresie.']); foreach ($indicators as $indicator) { Indicator::create($indicator); } $organizations = array(['code' => 'demo', 'name' => 'Powiatowy Urząd Pracy Demo', 'active' => true], ['code' => '24780', 'name' => 'Powiatowy Urząd Pracy w Zabrzu', 'active' => true]); foreach ($organizations as $organization) { $newOrganization = Organization::create($organization); foreach (Indicator::all() as $indicator) { $newOrganization->indicators()->attach($indicator->id, ['coefficient' => $faker->randomFloat(3, 0, 10)]); } } foreach (range(1, 50) as $index) { $organization = Organization::all()->random(1); $gender = $faker->randomElement(['male', 'female']); $lastName = $faker->lastName($gender); $user = User::create(['login' => $organization->code . '_' . $faker->numerify($lastName . '###'), 'name' => $faker->firstName($gender), 'surname' => $lastName, 'password' => Hash::make('secret'), 'active' => $faker->boolean(), 'organization_id' => $organization->id]); $role = Role::all()->random(1); $user->attachRole($role); } foreach (Organization::all() as $organization) { foreach (range(1, rand(5, 10)) as $index) { $group = Group::create(['organization_id' => $organization->id, 'name' => $faker->numerify('Grupa testowa ####')]); $users = $organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get(); foreach ($users as $user) { $group->users()->attach($user->id); } $indicators = Indicator::all()->random(rand(3, 7)); foreach ($indicators as $indicator) { $group->indicators()->attach($indicator->id); } } } $managers = User::whereHas('roles', function ($role) { $role->where('name', 'manager'); })->get(); foreach ($managers as $manager) { foreach (range(1, rand(3, 6)) as $index) { $endDate = $faker->dateTimeThisDecade(); $report = Report::create(['owner_id' => $manager->id, 'name' => $faker->numerify('Raport testowy ####'), 'start_date' => $faker->dateTimeThisDecade($endDate), 'end_date' => $endDate]); $indicators = Indicator::all()->random(rand(2, 5)); foreach ($indicators as $indicator) { $report->indicators()->attach($indicator->id, ['show_value' => $faker->boolean(), 'show_points' => $faker->boolean()]); } $users = $manager->organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get(); foreach ($users as $user) { $report->users()->attach($user->id, ['view_self' => $faker->boolean(), 'view_all' => $faker->boolean()]); } } } Model::reguard(); }
public function sendMailToUsers() { $users = User::whereHas('workActivities', function ($query) { $query->where('active', '=', true)->havingRaw('sum(hours) < 10'); })->get(); $endDate = Input::get('date'); $events = Input::get('events'); foreach ($users as $user) { $openWorkHours = 10 - $user->workActivities()->sum('hours'); Mail::send('emails.userReminder', ['user' => $user, 'openWorkHours' => $openWorkHours, 'date' => $endDate, 'events' => $events], function ($m) use($user) { $m->from('*****@*****.**', 'HC Niesky Arbeitsstundenverwaltung'); $m->to($user->email)->subject('Dir fehlen noch Arbeitsstunden!'); }); } Session::flash('message', "Mails wurden gesendet!"); return back(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('results')->delete(); DB::table('group_indicator')->delete(); DB::table('group_user')->delete(); DB::table('indicator_organization')->delete(); DB::table('indicator_report')->delete(); DB::table('report_user')->delete(); DB::table('users')->delete(); DB::table('organizations')->delete(); DB::table('roles')->delete(); DB::table('indicators')->delete(); DB::table('groups')->delete(); DB::table('reports')->delete(); $roles = array(['name' => 'admin', 'display_name' => 'Admin'], ['name' => 'manager', 'display_name' => 'Manager'], ['name' => 'employee', 'display_name' => 'Employee']); foreach ($roles as $role) { Role::create($role); } $faker = Faker::create(); foreach (range(1, 5) as $index) { Indicator::create(['name' => $faker->sentence(3), 'function_name' => $faker->numerify($faker->sentence(3) . '###'), 'type' => $faker->randomElement(['value', 'ratio']), 'default_coefficient' => $faker->randomFloat(3, 0, 1), 'description' => $faker->text()]); } foreach (range(1, 5) as $index) { $organization = Organization::create(['code' => $faker->randomNumber(6), 'name' => $faker->company, 'active' => $faker->boolean()]); foreach (Indicator::all() as $indicator) { $organization->indicators()->attach($indicator->id, ['coefficient' => $faker->randomFloat(3, 0, 10)]); } } foreach (range(1, 100) as $index) { $organization = Organization::all()->random(1); $user = User::create(['login' => $organization->code . '_' . $faker->userName, 'name' => $faker->firstName, 'surname' => $faker->lastName, 'password' => Hash::make('secret'), 'active' => $faker->boolean(), 'organization_id' => $organization->id]); $role = Role::all()->random(1); $user->attachRole($role); } foreach (Organization::all() as $organization) { foreach (range(1, rand(5, 10)) as $index) { $group = Group::create(['organization_id' => $organization->id, 'name' => $faker->sentence(3)]); $users = $organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get(); foreach ($users as $user) { $group->users()->attach($user->id); } $indicators = Indicator::all()->random(rand(2, 5)); foreach ($indicators as $indicator) { $group->indicators()->attach($indicator->id); } } } $managers = User::whereHas('roles', function ($role) { $role->where('name', 'manager'); })->get(); foreach ($managers as $manager) { foreach (range(1, rand(3, 6)) as $index) { $endDate = $faker->date('Y-m-d'); $report = Report::create(['owner_id' => $manager->id, 'name' => $faker->sentence(4), 'start_date' => $faker->date('Y-m-d', $endDate), 'end_date' => $endDate]); $indicators = Indicator::all()->random(rand(2, 5)); foreach ($indicators as $indicator) { $report->indicators()->attach($indicator->id, ['show_value' => $faker->boolean(), 'show_points' => $faker->boolean()]); } $users = $manager->organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get(); foreach ($users as $user) { $report->users()->attach($user->id, ['view_self' => $faker->boolean(), 'view_all' => $faker->boolean()]); } } } Model::reguard(); }
public function reports() { $this->data['input'] = Input::all(); $users = []; if (!empty($this->data['input'])) { $users = User::whereHas('assessment', function ($query) { return $query->where('status', 1); }); if (!empty($this->data['input']['key'])) { $users = $users->where('fullname', 'LIKE', '%' . trim($this->data['input']['key']) . '%'); } if (!empty($this->data['input']['type'])) { $users = $users->whereHas('assessment', function ($query) { return $query->whereHas('exam', function ($qq) { return $qq->where('type', strtolower($this->data['input']['type'])); }); }); } if (!empty($this->data['input']['from']) && !empty($this->data['input']['to'])) { $users = $users->whereHas('assessment', function ($query) { return $query->whereBetween('created_at', [Carbon::createFromFormat('Y-m-d', $this->data['input']['from'])->subDays(1)->toDateTimeString(), Carbon::createFromFormat('Y-m-d', $this->data['input']['to'])->addDays(1)->toDateTimeString()]); }); } $users = $users->get(); } $this->data['users'] = $users; return view('home.reports', $this->data); }
/** * Role filter */ public function userRoleFilter(Request $request) { $role = $request->role; if ($role === "Role") { $users = User::with('userRoles')->orderBy('users.created_at', 'desc')->paginate(50); } else { $users = User::whereHas('UserRoles', function ($query) use($role) { $query->where('role', $role); })->with('UserRoles')->paginate(50); } return $users; }
/** * Get users that have loaned this book * @return User collection */ public function getLoan() { return User::whereHas('transact', function ($query) { $query->where('type', 'loan')->where('book_id', $this->attributes['id'])->where('expires', '>', Carbon::now()); })->get(); }
public function events($company_id, Request $request) { $google_calendars = []; $users = Auth::user(); if (Auth::user()->role != "worker") { $users = User::whereHas('company', function ($q) use($company_id) { $q->where('companies.id', '=', $company_id); })->select('id', 'events_color')->get(); $users = array_column($users->toArray(), 'events_color', 'id'); foreach ($users as $user_id => $event_color) { $google_calendars[$user_id] = GoogleUserCalendar::freeBusy($user_id, $request->get('start'), $request->get('end')); } $jsonResponse = Roster::eventsJSON($company_id, ['start' => $request->get('start'), 'end' => $request->get('end')]); } else { $jsonResponse = User::events(Auth::user()->id, ['start' => $request->get('start'), 'end' => $request->get('end')]); $google_calendars[Auth::user()->id] = GoogleUserCalendar::freeBusy(Auth::user()->id, $request->get('start'), $request->get('end')); } foreach ($google_calendars as $user_id => $google_calendar_list) { foreach ($google_calendar_list as $calendar) { $events = $calendar->busy; if (count($events) > 0) { foreach ($events as $event) { array_push($jsonResponse, (object) ["id" => "google_" . rand(100, 700), "resourceId" => $user_id, "start" => $event->start, "end" => $event->end, "rendering" => "background", "color" => $users[$user_id]]); } } } } return response()->json($jsonResponse); }