Skip to content

Commit

Permalink
feat: get all types and populate request-btn
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Oct 4, 2023
1 parent 5d84567 commit 2b21a56
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
26 changes: 25 additions & 1 deletion app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use App\Models\Task;

class TaskController extends Controller
Expand All @@ -18,8 +19,31 @@ public function index()
{
$user = auth()->user();
$tasks = Task::where('recipient_user_id', $user->id)->get()->sortBy('created_at');

return view('tasks.index', compact('tasks'));
}

public static function getTypes(){
// Specify the directory where your subclasses are located
$subclassesDirectory = app_path('Tasks/Types');

// Initialize an array to store the subclasses
$subclasses = [];

// Get all PHP files in the directory
$files = File::files($subclassesDirectory);

foreach ($files as $file) {
// Get the class name from the file path
$className = 'App\\Tasks\\Types\\' . pathinfo($file, PATHINFO_FILENAME);;

// Check if the class exists and is a subclass of Types
if (class_exists($className) && is_subclass_of($className, 'App\\Tasks\\Types\\Types')) {
$subclasses[] = new $className();
}
}

return $subclasses;
}

}
5 changes: 4 additions & 1 deletion app/Http/Controllers/TrainingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\TaskController;

/**
* Controller for all trainings
Expand Down Expand Up @@ -343,7 +344,9 @@ public function show(Training $training)
$trainingInterests = TrainingInterest::where('training_id', $training->id)->orderBy('created_at', 'DESC')->get();
$activeTrainingInterest = TrainingInterest::where('training_id', $training->id)->where('expired', false)->get()->count();

return view('training.show', compact('training', 'reportsAndExams', 'trainingMentors', 'statuses', 'types', 'experiences', 'activities', 'trainingInterests', 'activeTrainingInterest'));
$requestTypes = TaskController::getTypes();

return view('training.show', compact('training', 'reportsAndExams', 'trainingMentors', 'statuses', 'types', 'experiences', 'activities', 'trainingInterests', 'activeTrainingInterest', 'requestTypes'));
}

/**
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"psr-4": {
"App\\": "app/",
"App\\Helpers\\": "app/helpers",
"App\\Tasks\\": "app/Tasks/",
"App\\Tasks\\Types\\": "app/Tasks/Types/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
Expand Down
11 changes: 6 additions & 5 deletions resources/views/training/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@
@endif
@endforeach
</h6>

<button class="btn btn-light btn-icon dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-hand"></i> Request
</button>
<div class="dropdown">
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<button class="dropdown-item" data-bs-toggle="modal" data-bs-target="#exampleModal"><i class="fas fa-key"></i> Theoretical Exam Token</button>
<button class="dropdown-item"><i class="fas fa-circle-arrow-up"></i> Rating Upgrade</button>
<button class="dropdown-item"><i class="fas fa-clock"></i> Solo Endorsement</button>
<button class="dropdown-item" data-bs-toggle="modal" data-bs-target="#exampleModal2"><i class="fas fa-message"></i> Custom Memo</button>
@foreach($requestTypes as $requestType)
<button class="dropdown-item" data-bs-toggle="modal" data-bs-target="#exampleModal">
<i class="fas {{ $requestType->getIcon() }}"></i>&nbsp;
{{ $requestType->getName() }}
</button>
@endforeach
</div>
</div>
</div>
Expand Down

0 comments on commit 2b21a56

Please sign in to comment.