Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add privatized version of name #656 #658

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions app/Http/Controllers/Frontend/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\UserRepository;
use Illuminate\Http\Request;
use Log;
use Illuminate\Support\Facades\Log;
use League\ISO3166\ISO3166;
use Prettus\Repository\Exceptions\RepositoryException;

/**
* Class UserController
*/
class UserController extends Controller
{
private $userRepo;

/**
* UserController constructor.
*
* @param UserRepository $userRepo
*/
public function __construct(
UserRepository $userRepo
) {
public function __construct(UserRepository $userRepo)
{
$this->userRepo = $userRepo;
}

Expand All @@ -49,11 +44,11 @@ public function index(Request $request)

$users = $this->userRepo
->with(['airline', 'current_airport'])
->orderBy('name', 'desc')
->orderBy('pilot_id', 'asc')
->paginate();

return view('users.index', [
'country' => new \League\ISO3166\ISO3166(),
'country' => new ISO3166(),
'users' => $users,
]);
}
Expand Down
22 changes: 21 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @property int pilot_id
* @property int airline_id
* @property string name
* @property string name_private Only first name, rest are initials
* @property string email
* @property string password
* @property string api_key
Expand Down Expand Up @@ -110,13 +111,32 @@ class User extends Authenticatable
/**
* @return string
*/
public function getIdentAttribute()
public function getIdentAttribute(): string
{
$length = setting('pilots.id_length');

return $this->airline->icao.str_pad($this->pilot_id, $length, '0', STR_PAD_LEFT);
}

/**
* Return a "privatized" version of someones name - First name full, rest of the names are initials
*
* @return string
*/
public function getNamePrivateAttribute(): string
{
$name_parts = explode(' ', $this->attributes['name']);
$count = count($name_parts);
if ($count === 1) {
return $name_parts[0];
}

$first_name = $name_parts[0];
$last_name = $name_parts[$count - 1];

return $first_name.' '.$last_name[0];
}

/**
* Shorthand for getting the timezone
*
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/default/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{--</div>--}}
<div class="header header-primary text-center blue-bg">
<h3 class="title title-up text-white">
<a href="{{ route('frontend.profile.show', [$user->id]) }}" class="text-white">{{ $user->name }}</a>
<a href="{{ route('frontend.profile.show', [$user->id]) }}" class="text-white">{{ $user->name_private }}</a>
</h3>
<div class="photo-container">
@if ($user->avatar == null)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/default/profile/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<div><br/></div>
<div class="social-description">
<h2>{{ $user->name }}</h2>
<h2>{{ $user->name_private }}</h2>
<p>{{ $user->ident }}</p>
</div>
<p class="description" style="color: #9A9A9A;">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/default/users/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</td>
<td>
<a href="{{ route('frontend.profile.show.public', [$user->id]) }}">
{{ $user->name }}
{{$user->ident}}&nbsp;{{ $user->name_private }}
</a>
</td>
<td align="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@foreach($news as $item)
<h4 style="margin-top: 0px;">{{ $item->subject }}</h4>
<p class="category">{{ $item->user->name }}
<p class="category">{{ $item->user->name_private }}
- {{ show_datetime($item->created_at) }}</p>

{{ $item->body }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<td style="padding-right: 10px;">
<span class="title">{{ $u->ident }}</span>
</td>
<td>{{ $u->name }}</td>
<td>{{ $u->name_private }}</td>
</tr>
@endforeach
</table>
17 changes: 17 additions & 0 deletions tests/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,21 @@ public function testUserPilotIdAdded()
$user3 = factory(App\Models\User::class)->create();
$this->assertEquals(4, $user3->pilot_id);
}

/**
* Test that a user's name is private
*/
public function testUserNamePrivate()
{
$vals = [
'Firstname' => 'Firstname',
'Firstname Lastname' => 'Firstname L',
'Firstname Middlename Lastname' => 'Firstname L',
];

foreach ($vals as $input => $expected) {
$user = new User(['name' => $input]);
$this->assertEquals($expected, $user->name_private);
}
}
}