@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user