コード例 #1
0
 /** @test */
 public function demo_efficient_eager_loading_eloquent_relationship_query(FunctionalTester $I)
 {
     // given ... 3 tasks, each belonging to a user
     // when ... we get tasks "with" their user
     //          it would result in only 2 SQL queries in total (which is efficient)
     $tasks = Task::with('user')->get();
     // then ... should return all tasks with their user
     $I->assertSame(3, count($tasks));
     $I->assertSame("Sherlock Holmes", $tasks[0]->user['name']);
     // task 1
     $I->assertSame("Sherlock Holmes", $tasks[1]->user['name']);
     // task 2
     $I->assertSame("Dr Watson", $tasks[2]->user['name']);
     // task 3
 }
コード例 #2
0
ファイル: DisplayTasks.php プロジェクト: LakyLak/Projects
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $issues = Issue::with('company', 'company.person')->has('task', '<', 1)->get();
     foreach ($issues as $issue) {
         $task = new Task();
         $task->issue_id = $issue->id;
         $task->person_id = $issue->company->person->id;
         $task->priority = $issue->level * $issue->company->score;
         $task->save();
     }
     $tasks = Task::with('issue', 'issue.company', 'person')->orderBy('priority', 'DESC')->get();
     echo 'ID | Name | Company | Priority | Assigned Person', PHP_EOL;
     foreach ($tasks as $task) {
         echo sprintf('%d | %s | %s | %d | %s', $task->id, $task->issue->name, $task->issue->company->name, $task->priority, $task->person->name), PHP_EOL;
     }
 }
コード例 #3
0
ファイル: TaskController.php プロジェクト: cclass/taskboard
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$tasks = Task::take(100)->get();
     //$tasks = Task::with('assignees')->get();
     // TODO MAKE SURE YOU CAN'T DUPLICATE ASSIGNEES
     $tasks = Task::with(['assignees' => function ($query) {
         // Puts the current user first in the array of assignees
         $query->orderByRaw('id = ? DESC', Auth::user()->id);
     }, 'tags'])->get();
     // DB::table('users')->chunk(100, function($users) {
     //     foreach ($users as $user) {
     //         //
     //     }
     // });
     $users = User::all();
     $tags = Tag::all();
     return view('tasks/tasks')->with(array('tasks' => $tasks, 'users' => $users, 'tags' => $tags));
 }
コード例 #4
0
 /**
  * GET /api/dashboard
  *
  * @param $userId
  * @param $partnerId
  * @param Request $request
  *
  * @return
  */
 public function get($userId, $partnerId, Request $request)
 {
     // Get current room
     $room = $request->room;
     $progressions = Progression::where('room_id', '=', $room->id)->get();
     $tasksIds = [];
     $tasks = [];
     // Get all tasks use in the room
     foreach ($progressions as $value) {
         if (!in_array($value->task_id, $tasksIds)) {
             $tasksIds[] = $value->task_id;
             $task = Task::with('category')->where('id', '=', $value->task_id)->first();
             $userProgression = Progression::where('room_id', '=', $room->id)->where('user_id', '=', $userId)->where('task_id', '=', $task->id)->first(['count']);
             $partnerProgression = Progression::where('room_id', '=', $room->id)->where('user_id', '=', $partnerId)->where('task_id', '=', $task->id)->first(['count']);
             $tasks[] = ['id' => $task->id, 'category' => $task->category, 'name' => $task->name, 'difference' => $userProgression->count - $partnerProgression->count];
         }
     }
     // Return response
     return Response::json(['status_code' => 200, 'tasks' => $tasks]);
 }
コード例 #5
0
 public function taskexcel($id)
 {
     Excel::create('Excel ', function ($excel) use($id) {
         $excel->sheet('new Sheet', function ($sheet) use($id) {
             $taskforms = TaskForm::where('task_id', $id)->with('device')->get();
             $task = Task::with('company')->find($id);
             $sheet->setAllBorders('thin');
             $sheet->setStyle(array('font' => array('name' => 'Calibri', 'size' => 10, 'bold' => false)));
             // Set border for cells
             $sheet->loadView('report.taskexcel')->with('taskforms', $taskforms)->with('task', $task);
         });
     })->download('xls');
 }
コード例 #6
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     return Task::with('tasklist')->findOrFail($id)->toJson();
 }
コード例 #7
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     return response()->json(Task::with('user', 'category')->get());
 }
コード例 #8
0
 /**
  * @param User $user
  * @return App\Task[]
  */
 public function forUser(User $user)
 {
     //        return $user->tasks()->getResults();
     return Task::with('user')->withTrashed()->where('user_id', $user->id)->orderBy('created_at', 'asc')->get();
 }
コード例 #9
0
ファイル: TaskController.php プロジェクト: Rhenan/tasks
 /**
  * History page
  */
 public function history()
 {
     //get timezone offset for scoreboard
     $offset = new DateTime('now', new DateTimeZone(Auth::user()->timezone));
     $time = time() + $offset->getOffset();
     //get last six days' totals
     $days = $weeks = [];
     for ($i = 0; $i < 6; $i++) {
         $day = $time - 60 * 60 * 24 * $i;
         $end = $time - 60 * 60 * 24 * 7 * $i;
         $start = $time - 60 * 60 * 24 * 7 * ($i + 1) + 60 * 60 * 24;
         $weeks[date('M j', $start) . '–' . date('M j', $end)] = Task::where('closed_at', '>=', date('Y-m-d', $start))->where('closed_at', '<=', date('Y-m-d', $end))->sum('hours');
         $days[date('l', $day)] = Task::where('closed_at', date('Y-m-d', $day))->sum('hours');
     }
     //$days = array_reverse($days);
     //dd($weeks);
     //get tasks
     $tasks = Task::with('project')->whereNotNull('closed_at')->orderBy('closed_at', 'desc')->orderBy('updated_at', 'desc')->paginate(20);
     return view('task.history', compact('days', 'weeks', 'tasks'));
 }
コード例 #10
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $tasks = Task::with('company', 'step', 'category', 'log')->where('step_id', '<', 7)->get();
     return view('task.list', compact('tasks'));
 }
コード例 #11
0
 public function index()
 {
     //
     $tasks = Task::with(['company', 'step'])->orderBy('created_at', 'DESC')->get();
     return view('task.index', compact('tasks'));
 }
コード例 #12
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Task $task, TaskRequest $request)
 {
     Log::info("[App\\TaskController]: Get a Task");
     $task = Task::with('priority', 'tags')->where('id', $task->id)->first();
     return response()->json($task);
 }
コード例 #13
0
ファイル: TaskController.php プロジェクト: andbet39/things
 public function apitasks()
 {
     $tasks = Task::with('owner', 'assigned')->get();
     return $tasks;
 }
コード例 #14
0
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * List all available tasks and output in json
  */
 public function index()
 {
     $Tasks = Task::with('task_done')->get();
     return response()->json($Tasks);
 }