You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

130 lines
3.3 KiB

<?php
namespace App\Http\Controllers;
use App\Couple;
use App\User;
use Illuminate\Http\Request;
class UsersController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function show(User $user)
{
$usersMariageList = [];
foreach ($user->marriages as $spouse) {
$usersMariageList[$spouse->pivot->id] = $user->name.' & '.$spouse->name;
}
$allMariageList = [];
foreach (Couple::with('husband','wife')->get() as $couple) {
$allMariageList[$couple->id] = $couple->husband->name.' & '.$couple->wife->name;
}
$malePersonList = User::where('gender_id', 1)->pluck('nickname', 'id');
$femalePersonList = User::where('gender_id', 2)->pluck('nickname', 'id');
return view('users.show', [
'currentUser' => $user,
'usersMariageList' => $usersMariageList,
'malePersonList' => $malePersonList,
'femalePersonList' => $femalePersonList,
'allMariageList' => $allMariageList
]);
}
/**
* Display the user's family chart.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function chart(User $user)
{
$father = $user->father_id ? $user->father : null;
$mother = $user->mother_id ? $user->mother : null;
$fatherGrandpa = $father && $father->father_id ? $father->father : null;
$fatherGrandma = $father && $father->mother_id ? $father->mother : null;
$motherGrandpa = $mother && $mother->father_id ? $mother->father : null;
$motherGrandma = $mother && $mother->mother_id ? $mother->mother : null;
$childs = $user->childs;
$colspan = $childs->count();
$colspan = $colspan < 4 ? 4 : $colspan;
$siblings = $user->siblings();
return view('users.chart', compact('user', 'childs', 'father', 'mother', 'fatherGrandpa', 'fatherGrandma', 'motherGrandpa', 'motherGrandma', 'siblings', 'colspan'));
}
/**
* Show the form for editing the specified resource.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function edit(User $user)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function update(Request $request, User $user)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function destroy(User $user)
{
//
}
}