Browse Source

Update proper siblings query and added person gender on chart page

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
fb3c214077
  1. 25
      app/User.php
  2. 12
      resources/views/users/chart.blade.php

25
app/User.php

@ -37,7 +37,7 @@ class User extends Authenticatable
public function getGenderAttribute() public function getGenderAttribute()
{ {
return $this->gender_id == 1 ? 'Laki-laki' : 'Perempuan';
return $this->gender_id == 1 ? 'L' : 'P';
} }
public function setFather(User $father) public function setFather(User $father)
@ -136,16 +136,19 @@ class User extends Authenticatable
public function siblings() public function siblings()
{ {
// TODO: research for fit siblings query
return User::where(function ($query) {
$query->where('id', '!=', $this->id);
if ($this->father_id != null)
$query->where('father_id', $this->father_id);
// if ($this->mother_id != null)
// $query->where('mother_id', $this->mother_id);
// if ($this->parent_id != null)
// $query->where('parent_id', $this->parent_id);
})->get();
if (is_null($this->father_id) && is_null($this->mother_id) && is_null($this->parent_id))
return collect([]);
return User::where('id', '!=', $this->id)
->where(function ($query) {
if (!is_null($this->father_id))
$query->where('father_id', $this->father_id);
if (!is_null($this->mother_id))
$query->orWhere('mother_id', $this->mother_id);
if (!is_null($this->parent_id))
$query->orWhere('parent_id', $this->parent_id);
})
->get();
} }
public function parent() public function parent()

12
resources/views/users/chart.blade.php

@ -30,16 +30,16 @@
</tr> </tr>
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th class="text-center" colspan="{{ $colspan }}">{{ $user->profileLink('chart') }}</th>
<th class="text-center" colspan="{{ $colspan }}">{{ $user->profileLink('chart') }} ({{ $user->gender }})</th>
</tr> </tr>
<tr> <tr>
<th>Anak-Anak & Cucu-Cucu</th> <th>Anak-Anak & Cucu-Cucu</th>
@foreach($childs as $child) @foreach($childs as $child)
<td> <td>
{{ $child->profileLink('chart') }}
{{ $child->profileLink('chart') }} ({{ $child->gender }})
<ul style="padding-left: 18px"> <ul style="padding-left: 18px">
@foreach($child->childs as $grand) @foreach($child->childs as $grand)
<li>{{ $grand->profileLink('chart') }}</li>
<li>{{ $grand->profileLink('chart') }} ({{ $grand->gender }})</li>
@endforeach @endforeach
</ul> </ul>
</td> </td>
@ -57,7 +57,7 @@
<tbody> <tbody>
<tr> <tr>
<th style="width: 35%">Saudara</th> <th style="width: 35%">Saudara</th>
<th class="text-center" colspan="{{ $sibling->childs->count() }}">{{ $sibling->profileLink('chart') }}</th>
<th class="text-center" colspan="{{ $sibling->childs->count() }}">{{ $sibling->profileLink('chart') }} ({{ $sibling->gender }})</th>
</tr> </tr>
<tr> <tr>
<th>Keponakan & Cucu-Cucu</th> <th>Keponakan & Cucu-Cucu</th>
@ -65,10 +65,10 @@
<ol style="padding-left: 15px"> <ol style="padding-left: 15px">
@foreach($sibling->childs as $child) @foreach($sibling->childs as $child)
<li> <li>
{{ $child->profileLink('chart') }}
{{ $child->profileLink('chart') }} ({{ $child->gender }})
<ul style="padding-left: 18px"> <ul style="padding-left: 18px">
@foreach($child->childs as $grand) @foreach($child->childs as $grand)
<li>{{ $grand->profileLink('chart') }}</li>
<li>{{ $grand->profileLink('chart') }} ({{ $grand->gender }})</li>
@endforeach @endforeach
</ul> </ul>
</li> </li>

Loading…
Cancel
Save