diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php index 6539c9bb..c302d5af 100644 --- a/app/Console/Commands/DevCommands.php +++ b/app/Console/Commands/DevCommands.php @@ -7,7 +7,7 @@ use App\Models\Acars; use App\Models\Airline; use App\Models\Pirep; use App\Models\User; -use App\Services\AwardsService; +use App\Services\AwardService; use DB; use PDO; use Symfony\Component\Yaml\Yaml; @@ -51,7 +51,7 @@ class DevCommands extends BaseCommand */ protected function listAwardClasses() { - $awardSvc = app(AwardsService::class); + $awardSvc = app(AwardService::class); $awards = $awardSvc->findAllAwardClasses(); $headers = ['Award Name', 'Class']; diff --git a/app/Database/migrations/2018_01_28_180522_create_awards_table.php b/app/Database/migrations/2018_01_28_180522_create_awards_table.php index c35b2689..e8645762 100644 --- a/app/Database/migrations/2018_01_28_180522_create_awards_table.php +++ b/app/Database/migrations/2018_01_28_180522_create_awards_table.php @@ -15,7 +15,7 @@ class CreateAwardsTable extends Migration { Schema::create('awards', function (Blueprint $table) { $table->increments('id'); - $table->string('title', 50); + $table->string('name'); $table->text('description')->nullable(); $table->text('image_url')->nullable(); diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index 45870c04..8683cf29 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -93,6 +93,16 @@ ranks: auto_approve_manual: 1 auto_promote: 0 +awards: + - id: 1 + name: Pilot 50 flights + description: When a pilot has 50 flights, give this award + image_url: + ref_class: App\Awards\PilotFlightAwards + ref_class_params: 50 + created_at: now + updated_at: now + news: - id: 1 user_id: 1 diff --git a/app/Http/Controllers/Admin/AwardController.php b/app/Http/Controllers/Admin/AwardController.php index c7f6804f..bfda770a 100755 --- a/app/Http/Controllers/Admin/AwardController.php +++ b/app/Http/Controllers/Admin/AwardController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateAwardRequest; use App\Http\Requests\UpdateAwardRequest; use App\Repositories\AwardRepository; +use App\Services\AwardService; use Illuminate\Http\Request; use Flash; use Prettus\Repository\Criteria\RequestCriteria; @@ -13,11 +14,39 @@ use Response; class AwardController extends BaseController { /** @var AwardRepository */ - private $awardRepository; + private $awardRepository, + $awardSvc; - public function __construct(AwardRepository $awardRepo) + public function __construct( + AwardRepository $awardRepo, + AwardService $awardSvc + ) { $this->awardRepository = $awardRepo; + $this->awardSvc = $awardSvc; + } + + /** + * @return array + */ + protected function getAwardClassesAndDescriptions(): array + { + $awards = [ + '' => '', + ]; + + $descriptions = []; + + $award_classes = $this->awardSvc->findAllAwardClasses(); + foreach($award_classes as $class_ref => $award) { + $awards[$class_ref] = $award->name; + $descriptions[$class_ref] = $award->param_description; + } + + return [ + 'awards' => $awards, + 'descriptions' => $descriptions, + ]; } /** @@ -42,7 +71,11 @@ class AwardController extends BaseController */ public function create() { - return view('admin.awards.create'); + $class_refs = $this->getAwardClassesAndDescriptions(); + return view('admin.awards.create', [ + 'award_classes' => $class_refs['awards'], + 'award_descriptions' => $class_refs['descriptions'], + ]); } /** @@ -91,8 +124,11 @@ class AwardController extends BaseController return redirect(route('admin.awards.index')); } + $class_refs = $this->getAwardClassesAndDescriptions(); return view('admin.awards.edit', [ 'award' => $award, + 'award_classes' => $class_refs['awards'], + 'award_descriptions' => $class_refs['descriptions'], ]); } diff --git a/app/Http/Requests/UpdateAwardRequest.php b/app/Http/Requests/UpdateAwardRequest.php index 390076b8..7f695573 100755 --- a/app/Http/Requests/UpdateAwardRequest.php +++ b/app/Http/Requests/UpdateAwardRequest.php @@ -25,6 +25,6 @@ class UpdateAwardRequest extends FormRequest */ public function rules() { - return Fare::$rules; + return Award::$rules; } } diff --git a/app/Models/Award.php b/app/Models/Award.php index b0c0071f..b4402fc6 100755 --- a/app/Models/Award.php +++ b/app/Models/Award.php @@ -14,7 +14,7 @@ class Award extends BaseModel public $table = 'awards'; public $fillable = [ - 'title', + 'name', 'description', 'image_url', 'ref_class', @@ -22,9 +22,12 @@ class Award extends BaseModel ]; public static $rules = [ - 'title' => 'required', + 'name' => 'required', 'description' => 'nullable', 'image_url' => 'nullable', + + 'ref_class' => 'required', + 'ref_class_params' => 'nullable' ]; /** @@ -41,8 +44,6 @@ class Award extends BaseModel try { return new $this->ref_class($award, $user); - # return $klass; - # return $klass->find($this->ref_class_id); } catch (\Exception $e) { return null; } diff --git a/app/Services/AwardsService.php b/app/Services/AwardService.php similarity index 64% rename from app/Services/AwardsService.php rename to app/Services/AwardService.php index 0c877989..5694c838 100644 --- a/app/Services/AwardsService.php +++ b/app/Services/AwardService.php @@ -5,26 +5,32 @@ namespace App\Services; use App\Support\ClassLoader; use Module; -class AwardsService +class AwardService { /** * Find any of the award classes + * @return \App\Interfaces\AwardInterface[] */ public function findAllAwardClasses() { $awards = []; + $formatted_awards = []; # Find the awards in the app/Awards directory $classes = ClassLoader::getClassesInPath(app_path('/Awards')); $awards = array_merge($awards, $classes); - # Look throughout all the other modules + # Look throughout all the other modules, in the module/{MODULE}/Awards directory foreach (Module::all() as $module) { $path = $module->getExtraPath('Awards'); $classes = ClassLoader::getClassesInPath($path); $awards = array_merge($awards, $classes); } - return $awards; + foreach ($awards as $award) { + $formatted_awards[\get_class($award)] = $award; + } + + return $formatted_awards; } } diff --git a/resources/views/admin/awards/create.blade.php b/resources/views/admin/awards/create.blade.php index 6a6a8c2b..6879d717 100755 --- a/resources/views/admin/awards/create.blade.php +++ b/resources/views/admin/awards/create.blade.php @@ -3,9 +3,10 @@ @section('content')
{{ $errors->first('name') }}
+{{ $errors->first('image_url') }}
{{ $errors->first('description') }}
{{ $errors->first('ref_class') }}
+{{ $errors->first('ref_class_params') }}
--
{!! $award->title !!}
-{!! $award->description !!}
-| Title | -Description | -Image | +Name | +Description | +Image | Action | @foreach($awards as $award)
|---|---|---|---|---|---|---|
| {!! $award->title !!} | -{!! $award->description !!} | -+ + {{ $award->name }} + | +{{ $award->description }} | +
+
+ @if($award->image)
+ |
- {!! Form::open(['route' => ['admin.awards.destroy', $award->id], 'method' => 'delete']) !!} - - {!! Form::button('', ['type' => 'submit', 'class' => 'btn btn-sm btn-danger btn-icon', 'onclick' => "return confirm('Are you sure you want to delete this award?')"]) !!} - {!! Form::close() !!} + {{ Form::open(['route' => ['admin.awards.destroy', $award->id], 'method' => 'delete']) }} + + + + {{ Form::button('', [ + 'type' => 'submit', + 'class' => 'btn btn-sm btn-danger btn-icon', + 'onclick' => "return confirm('Are you sure you want to delete this award?')" + ]) }} + + {{ Form::close() }} |