-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b6e02cc
Showing
16 changed files
with
647 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
/** | ||
* Provide any configuration items here | ||
*/ | ||
|
||
return [ | ||
'name' => 'CHFreeFlight' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Modules\CHFreeFlight\Http\Controllers\Admin; | ||
|
||
use App\Contracts\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Admin controller | ||
*/ | ||
class AdminController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
return view('chfreeflight::admin.index'); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function create(Request $request) | ||
{ | ||
return view('chfreeflight::admin.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param Request $request | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function edit(Request $request) | ||
{ | ||
return view('chfreeflight::admin.edit'); | ||
} | ||
|
||
/** | ||
* Show the specified resource. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function show(Request $request) | ||
{ | ||
return view('chfreeflight::admin.show'); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param Request $request | ||
*/ | ||
public function update(Request $request) | ||
{ | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param Request $request | ||
*/ | ||
public function destroy(Request $request) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Modules\CHFreeFlight\Http\Controllers\Frontend; | ||
|
||
use App\Contracts\Controller; | ||
use App\Models\Enums\PirepFieldSource; | ||
use App\Models\Flight; | ||
use App\Repositories\AirlineRepository; | ||
use App\Services\BidService; | ||
use App\Services\FlightService; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Session; | ||
use Modules\CHFreeFlight\Providers\CHFreeFlightProvider; | ||
|
||
/** | ||
* Class $CLASS$ | ||
* @package | ||
*/ | ||
class IndexController extends Controller | ||
{ | ||
public function __construct(public AirlineRepository $airlineRepository, | ||
public FlightService $flightService, | ||
public BidService $bidService) | ||
{ | ||
} | ||
|
||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function create(Request $request) | ||
{ | ||
return view('chfreeflight::create_flight', [ | ||
'airline_list' => $this->airlineRepository->selectBoxList(true) | ||
]); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param Request $request | ||
* | ||
* @return mixed | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$fields = $request->all(); | ||
|
||
// Add the owner of the flight | ||
$fields['owner_type'] = CHFreeFlightProvider::class; | ||
$fields['user_id'] = Auth::user()->id; | ||
$fields['visible'] = false; | ||
$fields['active'] = true; | ||
$fields['minutes'] = 0; | ||
$fields['hours'] = 0; | ||
// Create the flight | ||
try { | ||
$flight = $this->flightService->createFlight($fields); | ||
} catch (\Exception $exception) { | ||
//dd($exception); | ||
Session::flash('error', $exception->getMessage()); | ||
return to_route('chfreeflight.index'); | ||
} | ||
|
||
// Add the Bid to the User Account | ||
$this->bidService->addBid($flight, Auth::user()); | ||
|
||
return to_route('frontend.flights.bids'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
# This is the admin path. Comment this out if you don't have an admin panel component. | ||
Route::get('/', 'AdminController@index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* This is publicly accessible | ||
*/ | ||
Route::group(['middleware' => []], function() { | ||
Route::get('/', 'ApiController@index'); | ||
}); | ||
|
||
/** | ||
* This is required to have a valid API key | ||
*/ | ||
Route::group(['middleware' => [ | ||
'api.auth' | ||
]], function() { | ||
Route::get('/hello', 'ApiController@hello'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
/* | ||
* To register a route that needs to be authentication, wrap it in a | ||
* Route::group() with the auth middleware | ||
*/ | ||
Route::group(['middleware' => 'auth'], function() { | ||
Route::get('/', 'IndexController@create')->name('create'); | ||
Route::post('/', 'IndexController@store')->name('store'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Modules\CHFreeFlight\Listeners; | ||
|
||
use App\Contracts\Listener; | ||
use App\Models\Bid; | ||
use App\Models\Enums\FlightType; | ||
use App\Models\Enums\PirepState; | ||
use App\Models\Flight; | ||
use App\Models\Pirep; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Modules\CHFreeFlight\Providers\CHFreeFlightProvider; | ||
|
||
/** | ||
* Class DeleteFlights | ||
* @package Modules\CHFreeFlight\Listeners | ||
*/ | ||
class DeleteFlights extends Listener | ||
{ | ||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param object $event | ||
* @return void | ||
*/ | ||
public function handle($event) | ||
{ | ||
// Find all the flights | ||
$flights = Flight::where('owner_type', CHFreeFlightProvider::class)->get(); | ||
|
||
// We're going to only delete flights that don't have a bid, or a pirep that's completed. | ||
|
||
foreach ($flights as $flight) { | ||
// if Pirep is in progress, then don't do anything. | ||
$pirep = Pirep::where(['flight_id' => $flight->id, 'user_id' => $flight->user_id])->first(); | ||
if ($pirep->state == PirepState::IN_PROGRESS) { | ||
continue; | ||
} | ||
|
||
// Check if there's a bid. | ||
$bids = Bid::where('flight_id', $flight->id)->count(); | ||
if ($bids == 0) { | ||
$flight->delete(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Modules\CHFreeFlight\Providers; | ||
|
||
use App\Contracts\Modules\ServiceProvider; | ||
|
||
/** | ||
* @package $NAMESPACE$ | ||
*/ | ||
class CHFreeFlightProvider extends ServiceProvider | ||
{ | ||
private $moduleSvc; | ||
|
||
protected $defer = false; | ||
|
||
/** | ||
* Boot the application events. | ||
*/ | ||
public function boot(): void | ||
{ | ||
$this->moduleSvc = app('App\Services\ModuleService'); | ||
|
||
$this->registerTranslations(); | ||
$this->registerConfig(); | ||
$this->registerViews(); | ||
|
||
$this->registerLinks(); | ||
|
||
// Uncomment this if you have migrations | ||
// $this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$'); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Add module links here | ||
*/ | ||
public function registerLinks(): void | ||
{ | ||
// Show this link if logged in | ||
$this->moduleSvc->addFrontendLink('Free Flight', '/chfreeflight', '', $logged_in=true); | ||
|
||
// Admin links: | ||
//$this->moduleSvc->addAdminLink('CHFreeFlight', '/admin/chfreeflight'); | ||
} | ||
|
||
/** | ||
* Register config. | ||
*/ | ||
protected function registerConfig() | ||
{ | ||
$this->publishes([ | ||
__DIR__.'/../Config/config.php' => config_path('chfreeflight.php'), | ||
], 'chfreeflight'); | ||
|
||
$this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'chfreeflight'); | ||
} | ||
|
||
/** | ||
* Register views. | ||
*/ | ||
public function registerViews() | ||
{ | ||
$viewPath = resource_path('views/modules/chfreeflight'); | ||
$sourcePath = __DIR__.'/../Resources/views'; | ||
|
||
$this->publishes([$sourcePath => $viewPath],'views'); | ||
|
||
$this->loadViewsFrom(array_merge(array_map(function ($path) { | ||
return $path . '/modules/chfreeflight'; | ||
}, \Config::get('view.paths')), [$sourcePath]), 'chfreeflight'); | ||
} | ||
|
||
/** | ||
* Register translations. | ||
*/ | ||
public function registerTranslations() | ||
{ | ||
$langPath = resource_path('lang/modules/chfreeflight'); | ||
|
||
if (is_dir($langPath)) { | ||
$this->loadTranslationsFrom($langPath, 'chfreeflight'); | ||
} else { | ||
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'chfreeflight'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Modules\CHFreeFlight\Providers; | ||
|
||
use App\Events\CronNightly; | ||
use Modules\CHFreeFlight\Listeners\DeleteFlights; | ||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | ||
|
||
class EventServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* The event listener mappings for the application. | ||
*/ | ||
protected $listen = [ | ||
CronNightly::class => [DeleteFlights::class], | ||
]; | ||
|
||
/** | ||
* Register any events for your application. | ||
*/ | ||
public function boot() | ||
{ | ||
parent::boot(); | ||
} | ||
} |
Oops, something went wrong.