Listing all the files and be able to select one.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\QuestionsService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -10,10 +11,22 @@ class ChallengeController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/challenge', name: 'app_challenge')]
|
||||
public function randomChallenge(): Response {
|
||||
|
||||
public function randomChallenge(): Response
|
||||
{
|
||||
return $this->render('challenge/start.html.twig');
|
||||
|
||||
}
|
||||
|
||||
#[Route('/list', name: 'app_list')]
|
||||
public function list(QuestionsService $questionsService): Response
|
||||
{
|
||||
$listOfChallenges = $questionsService->getList();
|
||||
return $this->render('challenge/list.html.twig', ['list' => $listOfChallenges]);
|
||||
}
|
||||
|
||||
#[Route('/challenge/{challenge<.*>}', name: 'app_challenge')]
|
||||
public function challenge(QuestionsService $questionsService, string $challenge): Response
|
||||
{
|
||||
$questions = $questionsService->getQuestions($challenge);
|
||||
return $this->render('challenge/list.html.twig', ['list' => $questions, 'challenge' => $challenge]);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class QuestionsService
|
||||
@@ -11,10 +12,10 @@ class QuestionsService
|
||||
{
|
||||
}
|
||||
|
||||
public function getQuestions(): array
|
||||
public function getQuestions(?string $file): array
|
||||
{
|
||||
$questions = [];
|
||||
foreach ($this->getQuestionFiles() as $file) {
|
||||
foreach ($this->getQuestionFiles($file) as $file) {
|
||||
$yamlFile = Yaml::parseFile($file->getRealPath());
|
||||
$questions = array_merge($questions, $yamlFile['questions']);
|
||||
}
|
||||
@@ -22,10 +23,24 @@ class QuestionsService
|
||||
return $questions;
|
||||
}
|
||||
|
||||
private function getQuestionFiles(): array
|
||||
private function getQuestionFiles(?string $file = null): array
|
||||
{
|
||||
$finder = new Finder();
|
||||
if ($file) {
|
||||
$finder->name($file);
|
||||
} else {
|
||||
$finder->name('*.yaml');
|
||||
}
|
||||
|
||||
return iterator_to_array($finder->files()->in($this->paths)->name('*.yaml'));
|
||||
return iterator_to_array($finder->files()->in($this->paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SplFileInfo[]
|
||||
*/
|
||||
public function getList(): array
|
||||
{
|
||||
return $this->getQuestionFiles();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,48 +2,37 @@
|
||||
|
||||
{% block body %}
|
||||
<div class="mx-auto mt-5 max-w-7xl px-2 sm:px-6 lg:px-8">
|
||||
|
||||
<div class="lg:flex lg:items-center lg:justify-between">
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">Back End Developer</h2>
|
||||
<div class="mt-1 flex flex-col sm:mt-0 sm:flex-row sm:flex-wrap sm:space-x-6">
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
<svg class="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path fill-rule="evenodd"
|
||||
d="M6 3.75A2.75 2.75 0 0 1 8.75 1h2.5A2.75 2.75 0 0 1 14 3.75v.443c.572.055 1.14.122 1.706.2C17.053 4.582 18 5.75 18 7.07v3.469c0 1.126-.694 2.191-1.83 2.54-1.952.599-4.024.921-6.17.921s-4.219-.322-6.17-.921C2.694 12.73 2 11.665 2 10.539V7.07c0-1.321.947-2.489 2.294-2.676A41.047 41.047 0 0 1 6 4.193V3.75Zm6.5 0v.325a41.622 41.622 0 0 0-5 0V3.75c0-.69.56-1.25 1.25-1.25h2.5c.69 0 1.25.56 1.25 1.25ZM10 10a1 1 0 0 0-1 1v.01a1 1 0 0 0 1 1h.01a1 1 0 0 0 1-1V11a1 1 0 0 0-1-1H10Z"
|
||||
clip-rule="evenodd"/>
|
||||
<path d="M3 15.055v-.684c.126.053.255.1.39.142 2.092.642 4.313.987 6.61.987 2.297 0 4.518-.345 6.61-.987.135-.041.264-.089.39-.142v.684c0 1.347-.985 2.53-2.363 2.686a41.454 41.454 0 0 1-9.274 0C3.985 17.585 3 16.402 3 15.055Z"/>
|
||||
</svg>
|
||||
Full-time
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
<svg class="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path fill-rule="evenodd"
|
||||
d="m9.69 18.933.003.001C9.89 19.02 10 19 10 19s.11.02.308-.066l.002-.001.006-.003.018-.008a5.741 5.741 0 0 0 .281-.14c.186-.096.446-.24.757-.433.62-.384 1.445-.966 2.274-1.765C15.302 14.988 17 12.493 17 9A7 7 0 1 0 3 9c0 3.492 1.698 5.988 3.355 7.584a13.731 13.731 0 0 0 2.273 1.765 11.842 11.842 0 0 0 .976.544l.062.029.018.008.006.003ZM10 11.25a2.25 2.25 0 1 0 0-4.5 2.25 2.25 0 0 0 0 4.5Z"
|
||||
clip-rule="evenodd"/>
|
||||
</svg>
|
||||
Remote
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
<svg class="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path d="M10.75 10.818v2.614A3.13 3.13 0 0 0 11.888 13c.482-.315.612-.648.612-.875 0-.227-.13-.56-.612-.875a3.13 3.13 0 0 0-1.138-.432ZM8.33 8.62c.053.055.115.11.184.164.208.16.46.284.736.363V6.603a2.45 2.45 0 0 0-.35.13c-.14.065-.27.143-.386.233-.377.292-.514.627-.514.909 0 .184.058.39.202.592.037.051.08.102.128.152Z"/>
|
||||
<path fill-rule="evenodd"
|
||||
d="M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-8-6a.75.75 0 0 1 .75.75v.316a3.78 3.78 0 0 1 1.653.713c.426.33.744.74.925 1.2a.75.75 0 0 1-1.395.55 1.35 1.35 0 0 0-.447-.563 2.187 2.187 0 0 0-.736-.363V9.3c.698.093 1.383.32 1.959.696.787.514 1.29 1.27 1.29 2.13 0 .86-.504 1.616-1.29 2.13-.576.377-1.261.603-1.96.696v.299a.75.75 0 1 1-1.5 0v-.3c-.697-.092-1.382-.318-1.958-.695-.482-.315-.857-.717-1.078-1.188a.75.75 0 1 1 1.359-.636c.08.173.245.376.54.569.313.205.706.353 1.138.432v-2.748a3.782 3.782 0 0 1-1.653-.713C6.9 9.433 6.5 8.681 6.5 7.875c0-.805.4-1.558 1.097-2.096a3.78 3.78 0 0 1 1.653-.713V4.75A.75.75 0 0 1 10 4Z"
|
||||
clip-rule="evenodd"/>
|
||||
</svg>
|
||||
$120k – $140k
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
<svg class="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path fill-rule="evenodd"
|
||||
d="M5.75 2a.75.75 0 0 1 .75.75V4h7V2.75a.75.75 0 0 1 1.5 0V4h.25A2.75 2.75 0 0 1 18 6.75v8.5A2.75 2.75 0 0 1 15.25 18H4.75A2.75 2.75 0 0 1 2 15.25v-8.5A2.75 2.75 0 0 1 4.75 4H5V2.75A.75.75 0 0 1 5.75 2Zm-1 5.5c-.69 0-1.25.56-1.25 1.25v6.5c0 .69.56 1.25 1.25 1.25h10.5c.69 0 1.25-.56 1.25-1.25v-6.5c0-.69-.56-1.25-1.25-1.25H4.75Z"
|
||||
clip-rule="evenodd"/>
|
||||
</svg>
|
||||
Closing on January 9, 2020
|
||||
<div class="mt-5 max-w-7xl px-2 sm:px-6 lg:px-8">
|
||||
{% set test = '' %}
|
||||
{% for challenge in list %}
|
||||
{% if test != challenge.getRelativePath %}
|
||||
<h2 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
|
||||
<a href="">{{ challenge.getRelativePath|replace({'_': ' '})|capitalize }} / All</a>
|
||||
</h2>
|
||||
{% endif %}
|
||||
<h2 class="leading-7 hover:text-cyan-600 text-gray-900 sm:truncate sm:tracking-tight ms-8">
|
||||
<a href="{{ path('app_challenge', {'challenge': challenge.getfilename}) }}">{{ challenge.getFilenameWithoutExtension|replace({'_': ' '})|capitalize }}</a></h2>
|
||||
{% set test = challenge.getRelativePath %}
|
||||
{% endfor %}
|
||||
<div class="lg:flex lg:items-center lg:justify-between">
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">Back End Developer</h2>
|
||||
<div class="mt-1 flex flex-col sm:mt-0 sm:flex-row sm:flex-wrap sm:space-x-6">
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
Full-time
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
Remote
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
$120k – $140k
|
||||
</div>
|
||||
<div class="mt-2 flex items-center text-sm text-gray-500">
|
||||
Closing on January 9, 2020
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 flex lg:ml-4 lg:mt-0">
|
||||
<div class="mt-5 flex lg:ml-4 lg:mt-0">
|
||||
<span class="hidden sm:block">
|
||||
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
|
||||
<svg class="-ml-0.5 mr-1.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
@@ -53,7 +42,7 @@
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<span class="ml-3 hidden sm:block">
|
||||
<span class="ml-3 hidden sm:block">
|
||||
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
|
||||
<svg class="-ml-0.5 mr-1.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z"/>
|
||||
@@ -63,7 +52,7 @@
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<span class="sm:ml-3">
|
||||
<span class="sm:ml-3">
|
||||
<button type="button"
|
||||
class="inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
|
||||
<svg class="-ml-0.5 mr-1.5 h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
@@ -74,26 +63,9 @@
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<!-- Dropdown -->
|
||||
<div class="relative ml-3 sm:hidden">
|
||||
<button type="button"
|
||||
class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:ring-gray-400"
|
||||
id="mobile-menu-button" aria-expanded="false" aria-haspopup="true">
|
||||
More
|
||||
<svg class="-mr-1 ml-1.5 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
|
||||
<path fill-rule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z"
|
||||
clip-rule="evenodd"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="absolute right-0 z-10 -mr-1 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu"
|
||||
aria-orientation="vertical" aria-labelledby="mobile-menu-button" tabindex="-1">
|
||||
<!-- Active: "bg-gray-100", Not Active: "" -->
|
||||
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="mobile-menu-item-0">Edit</a>
|
||||
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="mobile-menu-item-1">View</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user