Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.
Merged
32 changes: 32 additions & 0 deletions migrations/Version20241006112324.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241006112324 extends AbstractMigration
{
public function getDescription(): string
{
return 'Allow administrators commenting on feedback';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE feedback ADD comment TEXT DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE feedback DROP comment');
}
}
20 changes: 13 additions & 7 deletions src/Controller/Admin/FeedbackCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
Expand All @@ -40,22 +41,27 @@ public static function getEntityFqcn(): string
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id')->setDisabled(),
IdField::new('id')->hideOnIndex()->setDisabled(),
ChoiceField::new('type')->hideWhenUpdating(),
AssociationField::new('sender')->hideWhenUpdating(),
TextField::new('title')->hideWhenUpdating(),
TextEditorField::new('description')->hideWhenUpdating(),
ChoiceField::new('type')->hideWhenUpdating(),
TextField::new('contact')->hideWhenUpdating(),
ArrayField::new('metadata')->hideWhenUpdating(),
TextEditorField::new('description')->hideOnIndex()->hideWhenUpdating(),
TextField::new('contact')->hideOnIndex()->hideWhenUpdating(),
ArrayField::new('metadata')->hideOnIndex()->hideWhenUpdating(),
TextareaField::new('comment', 'feedback.comment')->hideOnIndex(),
ChoiceField::new('status'),
DateTimeField::new('createdAt', 'Created at')->setDisabled(),
DateTimeField::new('updatedAt', 'Updated at')->setDisabled(),
DateTimeField::new('updatedAt', 'Updated at')->hideOnIndex()->setDisabled(),
];
}

public function configureFilters(Filters $filters): Filters
{
return $filters->add('sender')->add('type')->add('status');
return $filters
->add('sender')
->add('type')
->add(FeedbackStatusFilter::new('status'))
;
}

public function configureActions(Actions $actions): Actions
Expand Down
58 changes: 58 additions & 0 deletions src/Controller/Admin/FeedbackStatusFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use App\Entity\FeedbackStatus;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDataDto;
use EasyCorp\Bundle\EasyAdminBundle\Filter\FilterTrait;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class FeedbackStatusFilter implements FilterInterface
{
use FilterTrait;

private const string filterBacklog = 'BACKLOG';
private const string filterNewInProgress = 'NEW_IN_PROGRESS';
private const string filterResolvedClosed = 'RESOLVED_CLOSED';

public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$statusSet = match ($filterDataDto->getValue()) {
self::filterBacklog => [FeedbackStatus::Backlog],
self::filterNewInProgress => [FeedbackStatus::New, FeedbackStatus::InProgress],
self::filterResolvedClosed => [FeedbackStatus::Resolved, FeedbackStatus::Closed],
default => [],
};

$queryBuilder
->andWhere("{$filterDataDto->getEntityAlias()}.{$filterDataDto->getProperty()} IN (:status)")
->setParameter(
'status',
$statusSet,
)
;
}

public static function new(string $propertyName, ?string $label = null): self
{
return (new self())
->setFilterFqcn(self::class)
->setProperty($propertyName)
->setLabel($label)
->setFormType(ChoiceType::class)
->setFormTypeOptions([
'choices' => [
'Backlog' => self::filterBacklog,
'New & In Progress' => self::filterNewInProgress,
'Resolved & Closed' => self::filterResolvedClosed,
],
])
;
}
}
4 changes: 2 additions & 2 deletions src/Controller/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommentsController extends AbstractController
*
* You should get it from `app.scss`.
*/
private static string $primaryColor = '#4154f1';
private const string primaryColor = '#4154f1';

#[Route('/', name: '')]
public function index(#[CurrentUser] User $user, CommentRepository $commentRepository): Response
Expand Down Expand Up @@ -67,7 +67,7 @@ public function likes(
'datasets' => [
[
'label' => $translator->trans('charts.likes_of_each_comment'),
'backgroundColor' => self::$primaryColor,
'backgroundColor' => self::primaryColor,
'data' => array_map(fn ($comment) => $comment['count'], $likesOfEachComment),
],
],
Expand Down
7 changes: 4 additions & 3 deletions src/Controller/OverviewCardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OverviewCardsController extends AbstractController
*
* You should get it from `app.scss`.
*/
private static string $primaryColor = '#4154f1';
private const string primaryColor = '#4154f1';

/**
* Retrieve the card showing the experience point (XP).
Expand All @@ -39,9 +39,10 @@ public function points(
): Response {
try {
$points = $pointCalculationService->calculate($user);
} catch (\Throwable) {
} catch (\Throwable $e) {
$logger->warning('Failed to calculate the points for the user.', [
'user' => $user->getId(),
'exception' => $e,
]);
$points = 0;
}
Expand Down Expand Up @@ -174,7 +175,7 @@ public function eventDailyChart(
'datasets' => [
[
'label' => $translator->trans('charts.event_daily_chart'),
'backgroundColor' => self::$primaryColor,
'backgroundColor' => self::primaryColor,
'data' => array_map(fn ($event) => $event['count'], $events),
],
],
Expand Down
15 changes: 15 additions & 0 deletions src/Entity/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Feedback
#[ORM\Column]
private \DateTimeImmutable $updated_at;

#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $comment = null;

public function getId(): ?Ulid
{
return $this->id;
Expand Down Expand Up @@ -191,4 +194,16 @@ public function updateUpdatedAtValue(): void
{
$this->updated_at = new \DateTimeImmutable();
}

public function getComment(): ?string
{
return $this->comment;
}

public function setComment(?string $comment): static
{
$this->comment = $comment;

return $this;
}
}
6 changes: 3 additions & 3 deletions src/Repository/QuestionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class QuestionRepository extends ServiceEntityRepository
{
public static int $pageSize = 12;
public const int pageSize = 12;

public function __construct(
ManagerRegistry $registry,
Expand Down Expand Up @@ -86,8 +86,8 @@ public function search(?string $query, ?string $type, int $page, ?int $pageSize
}

return $this->searchService->search($this->getEntityManager(), Question::class, $query ?? '', [
'limit' => $pageSize ?? self::$pageSize,
'offset' => ($page - 1) * ($pageSize ?? self::$pageSize),
'limit' => $pageSize ?? self::pageSize,
'offset' => ($page - 1) * ($pageSize ?? self::pageSize),
'filter' => $filters,
'sort' => ['id:asc'],
]);
Expand Down
Loading