parent
151f188886
commit
193fbd369d
@ -5,6 +5,8 @@ namespace App\Contracts;
|
||||
use App\Support\Database;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Class Migration
|
||||
@ -60,4 +62,22 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an award from the migrations (for example, if you're adding an award module)
|
||||
*
|
||||
* @param array $award See \App\Models\Awardv
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function addAward(array $award)
|
||||
{
|
||||
$validator = Validator::make($award, \App\Models\Award::$rules);
|
||||
if ($validator->fails()) {
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
|
||||
$awardModel = new \App\Models\Award($award);
|
||||
$awardModel->save();
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,15 @@
|
||||
use App\Contracts\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Awards\Awards\PilotFlightAwards;
|
||||
|
||||
class CreateAwardsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
@ -23,7 +26,6 @@ class CreateAwardsTable extends Migration
|
||||
// EG, the airports has an internal expense for gate costs
|
||||
$table->string('ref_model')->nullable();
|
||||
$table->text('ref_model_params')->nullable();
|
||||
//$table->string('ref_model_id', 36)->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
@ -38,6 +40,18 @@ class CreateAwardsTable extends Migration
|
||||
|
||||
$table->index(['user_id', 'award_id']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a default, sample award
|
||||
*/
|
||||
$award = [
|
||||
'name' => 'Pilot 50 flights',
|
||||
'description' => 'When a pilot has 50 flights, give this award',
|
||||
'ref_model' => PilotFlightAwards::class,
|
||||
'ref_model_params' => 50,
|
||||
];
|
||||
|
||||
$this->addAward($award);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,30 +1,10 @@
|
||||
|
||||
#airlines:
|
||||
# - id: 1
|
||||
# icao: VMS
|
||||
# iata: VM
|
||||
# name: phpvms airlines
|
||||
# country: us
|
||||
# active: 1
|
||||
# created_at: now
|
||||
# updated_at: now
|
||||
|
||||
roles:
|
||||
id_column: name
|
||||
data:
|
||||
- name: fleet-only
|
||||
display_name: Edit Fleet
|
||||
|
||||
awards:
|
||||
- id: 1
|
||||
name: Pilot 50 flights
|
||||
description: When a pilot has 50 flights, give this award
|
||||
image_url:
|
||||
ref_model: Modules\Awards\Awards\PilotFlightAwards
|
||||
ref_model_params: 50
|
||||
created_at: now
|
||||
updated_at: now
|
||||
|
||||
news:
|
||||
- id: 1
|
||||
user_id: 1
|
||||
|
@ -92,3 +92,10 @@ user_field_values:
|
||||
user_field_id: 2
|
||||
user_id: 1
|
||||
value: 'Nobody did'
|
||||
|
||||
user_awards:
|
||||
- id: 1
|
||||
user_id: 1
|
||||
award_id: 1
|
||||
created_at: now
|
||||
updated_at: now
|
||||
|
@ -8,6 +8,7 @@ use App\Http\Requests\UpdateUserRequest;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Models\UserAward;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
@ -143,7 +144,7 @@ class UserController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$user = $this->userRepo
|
||||
->with(['fields', 'rank'])
|
||||
->with(['awards', 'fields', 'rank'])
|
||||
->findWithoutFail($id);
|
||||
|
||||
if (empty($user)) {
|
||||
@ -265,6 +266,28 @@ class UserController extends Controller
|
||||
return redirect(route('admin.users.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the award from a user
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param mixed $id
|
||||
* @param mixed $award_id
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy_user_award($id, $award_id, Request $request)
|
||||
{
|
||||
$userAward = UserAward::where(['user_id' => $id, 'award_id' => $award_id]);
|
||||
if (empty($userAward)) {
|
||||
Flash::error('The user award could not be found');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$userAward->delete();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the user's API key
|
||||
*
|
||||
|
@ -61,27 +61,14 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to show() since only a single page gets shown and the template controls
|
||||
* the other items that are/aren't shown
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
if (setting('pilots.home_hubs_only')) {
|
||||
$airports = $this->airportRepo->findWhere(['hub' => true]);
|
||||
} else {
|
||||
$airports = $this->airportRepo->all();
|
||||
}
|
||||
|
||||
$userFields = $this->userRepo->getUserFields($user);
|
||||
|
||||
return view('profile.index', [
|
||||
'acars' => $this->acarsEnabled(),
|
||||
'user' => $user,
|
||||
'airports' => $airports,
|
||||
'userFields' => $userFields,
|
||||
]);
|
||||
return $this->show(Auth::user()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +78,8 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$user = User::with(['fields', 'fields.field'])
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::with(['awards', 'fields', 'fields.field'])
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
|
@ -208,9 +208,12 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Airline::class, 'airline_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \App\Models\Award[]|mixed
|
||||
*/
|
||||
public function awards()
|
||||
{
|
||||
return $this->hasMany(UserAward::class, 'user_id');
|
||||
return $this->belongsToMany(Award::class, 'user_awards');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -356,10 +356,17 @@ class RouteServiceProvider extends ServiceProvider
|
||||
|
||||
Route::resource('subfleets', 'SubfleetController')->middleware('ability:admin,fleet');
|
||||
|
||||
Route::resource('users', 'UserController')->middleware('ability:admin,users');
|
||||
/**
|
||||
* USERS
|
||||
*/
|
||||
Route::delete('users/{id}/award/{award_id}', 'UserController@destroy_user_award')
|
||||
->name('users.destroy_user_award')->middleware('ability:admin,users');
|
||||
|
||||
Route::get('users/{id}/regen_apikey', 'UserController@regen_apikey')
|
||||
->name('users.regen_apikey')->middleware('ability:admin,users');
|
||||
|
||||
Route::resource('users', 'UserController')->middleware('ability:admin,users');
|
||||
|
||||
// defaults
|
||||
Route::get('', ['uses' => 'DashboardController@index'])
|
||||
->middleware('update_pending', 'ability:admin,admin-access');
|
||||
|
@ -4,7 +4,8 @@ return [
|
||||
'avatarresize' => 'This avatar will be resized to :width x :height pixels',
|
||||
|
||||
'newapikey' => 'New API Key',
|
||||
'yourprofile' => 'Your Profile',
|
||||
'your-profile' => 'Your Profile',
|
||||
'your-awards' => 'Your Awards',
|
||||
'apikey' => 'API Key',
|
||||
'apikey-show' => 'Show key',
|
||||
'dontshare' => 'don\'t share this!',
|
||||
|
@ -4,7 +4,8 @@ return [
|
||||
'avatarresize' => 'Este avatar será redimensionado a :width x :height pixeles',
|
||||
|
||||
'newapikey' => 'Nueva clave API',
|
||||
'yourprofile' => 'Tu perfil',
|
||||
'your-profile' => 'Tu Perfil',
|
||||
'your-awards' => 'Tus Premios',
|
||||
'apikey' => 'Clave API',
|
||||
'apikey-show' => 'Mostrar clave',
|
||||
'dontshare' => '¡No compartas esto!',
|
||||
|
@ -3,7 +3,8 @@
|
||||
return [
|
||||
'avatarresize' => 'Questo avatar sarà ridimensionato a :width x :height pixels',
|
||||
'newapikey' => 'Nuova Chiave API',
|
||||
'yourprofile' => 'Il Tuo Profilo',
|
||||
'your-profile' => 'Il Tuo Profilo',
|
||||
'your-awards' => 'I Tuoi Premi',
|
||||
'apikey' => 'Chiave API',
|
||||
'apikey-show' => 'Mostra chiave',
|
||||
'dontshare' => 'non condividerla!',
|
||||
|
@ -4,7 +4,8 @@ return [
|
||||
'avatarresize' => 'Este avatar será redimensionado para :width x :height pixels',
|
||||
|
||||
'newapikey' => 'Nova Chave API',
|
||||
'yourprofile' => 'Seu Perfil',
|
||||
'your-profile' => 'Seu Perfil',
|
||||
'your-awards' => 'Seus Prêmios',
|
||||
'apikey' => 'Chave API',
|
||||
'apikey-show' => 'Mostrar chave',
|
||||
'dontshare' => 'Não compartilhe isso!',
|
||||
|
23
resources/views/admin/users/awards.blade.php
Normal file
23
resources/views/admin/users/awards.blade.php
Normal file
@ -0,0 +1,23 @@
|
||||
@if($user->awards->count() > 0)
|
||||
<table class="table table-hover">
|
||||
@foreach($user->awards as $award)
|
||||
<tr>
|
||||
<td>{{ $award->name }}</td>
|
||||
<td>{{ $award->description }}</td>
|
||||
<td>
|
||||
{{ Form::open(['url' => url('/admin/users/'.$user->id.'/award/'.$award->id),
|
||||
'method' => 'delete', 'class' => 'pjax_form form-inline']) }}
|
||||
{{ Form::button('<i class="fa fa-times"></i>', ['type' => 'submit',
|
||||
'class' => 'btn btn-danger btn-small',
|
||||
'onclick' => "return confirm('Are you sure?')",
|
||||
]) }}
|
||||
{{ Form::close() }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@else
|
||||
<div class="jumbotron">
|
||||
<p class="text-center">This user has no awards</p>
|
||||
</div>
|
||||
@endif
|
@ -9,6 +9,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
<h3>Awards</h3>
|
||||
</div>
|
||||
@include('admin.users.awards')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
|
@ -11,9 +11,6 @@
|
||||
<h2 class="description">@lang('common.newestpilots')</h2>
|
||||
@foreach($users as $user)
|
||||
<div class="card card-signup blue-bg">
|
||||
{{--<div class="card-bg">--}}
|
||||
{{--<i class="fa fa-user-o" style="opacity: .1;"></i>--}}
|
||||
{{--</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_private }}</a>
|
||||
|
@ -14,24 +14,24 @@
|
||||
<div><br/></div>
|
||||
<div class="social-description">
|
||||
<h2>{{ $user->name_private }}</h2>
|
||||
<p>{{ $user->ident }}</p>
|
||||
<p>
|
||||
{{ $user->ident }}
|
||||
<span class="flag-icon flag-icon-{{ $user->country }}"></span>
|
||||
</p>
|
||||
</div>
|
||||
<p class="description" style="color: #9A9A9A;">
|
||||
{{ $user->airline->name }}
|
||||
</p>
|
||||
<h6><span class="flag-icon flag-icon-{{ $user->country }}"></span></h6>
|
||||
<p class="description" style="color: #9A9A9A;">
|
||||
{{ $user->airline->name }}
|
||||
</p>
|
||||
<div class="social-description">
|
||||
@if (!empty($user->rank->image_url))
|
||||
<img src="{{ $user->rank->image_url }}" style="width: 160px;">
|
||||
@endif
|
||||
<h2>{{ $user->rank->name }}</h2>
|
||||
<p>{{ $user->rank->name }} <br />
|
||||
@if($user->home_airport)
|
||||
@lang('airports.home'): {{ $user->home_airport->icao }}
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
@if($user->home_airport)
|
||||
<div class="social-description">
|
||||
<h2>{{ $user->home_airport->icao }}</h2>
|
||||
<p>@lang('airports.home')</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-md-8 content-center">
|
||||
<div class="content">
|
||||
@ -88,6 +88,41 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Show the user's award if they have any --}}
|
||||
@if ($user->awards)
|
||||
<div class="clearfix" style="height: 50px;"></div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h3 class="description">@lang('profile.your-awards')</h3>
|
||||
@foreach($user->awards->chunk(3) as $awards)
|
||||
<div class="row">
|
||||
@foreach($awards as $award)
|
||||
<div class="card card-signup">
|
||||
<div class="header header-primary text-center">
|
||||
<h4 class="title title-up">{{ $award->name }}</h4>
|
||||
@if ($award->image_url)
|
||||
<div class="photo-container">
|
||||
<img src="{{ $award->image_url }}" alt="{{ $award->description }}" style="width: 123px;">
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="content content-center">
|
||||
<div class="social-description text-center">
|
||||
{{ $award->description }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer text-center">
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="clearfix" style="height: 20px;"></div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endif
|
||||
|
||||
{{--
|
||||
show the details/edit fields only for the currently logged in user
|
||||
--}}
|
||||
@ -108,7 +143,7 @@
|
||||
class="btn btn-primary">@lang('common.edit')</a>
|
||||
</div>
|
||||
|
||||
<h3 class="description">@lang('profile.yourprofile')</h3>
|
||||
<h3 class="description">@lang('profile.your-profile')</h3>
|
||||
<table class="table table-full-width">
|
||||
<tr>
|
||||
<td>@lang('common.email')</td>
|
||||
|
Loading…
Reference in New Issue
Block a user