2018-09-09 04:03:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-09-14 15:52:07 +00:00
|
|
|
use \App\User;
|
2018-09-09 04:03:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2018-09-15 03:05:24 +00:00
|
|
|
/**
|
|
|
|
* Get a name from a specific id in a array
|
|
|
|
*
|
|
|
|
* @param array $array The array of objects with ID and Names
|
|
|
|
* @param int $id The ID of the user
|
|
|
|
*
|
|
|
|
* @return string The username of the specified id
|
|
|
|
*/
|
|
|
|
protected function findName($array, $id)
|
|
|
|
{
|
|
|
|
foreach ($array as $object) {
|
|
|
|
if ($object->id == $id) {
|
|
|
|
return $object->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-09 04:03:41 +00:00
|
|
|
/**
|
|
|
|
* Show the application dashboard.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2018-09-15 03:05:24 +00:00
|
|
|
$users = [];
|
|
|
|
$items = User::find(\Auth::id())->items()->with('users')->get();
|
2018-09-14 15:52:07 +00:00
|
|
|
|
2018-09-15 03:05:24 +00:00
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item->used_by && !isset($users[$item->used_by])) {
|
|
|
|
$users[$item->used_by] = $this->findName($item->users, $item->used_by);
|
|
|
|
}
|
2018-09-14 15:52:07 +00:00
|
|
|
|
2018-09-15 03:05:24 +00:00
|
|
|
if ($item->waiting_user_id && !isset($users[$item->waiting_user_id])) {
|
|
|
|
$users[$item->waiting_user_id] = $this->findName($item, $item->waiting_user_id);
|
2018-09-14 15:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return view('home', compact('items', 'users'));
|
2018-09-09 04:03:41 +00:00
|
|
|
}
|
|
|
|
}
|