Allow snips to be archived
This commit is contained in:
@ -151,4 +151,19 @@ class SnipController extends AbstractController
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/archive/{snip}', name: '_archive')]
|
||||
public function archive(Snip $snip): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
||||
$snip->setArchived(!$snip->isArchived());
|
||||
$this->repository->save($snip);
|
||||
if ($snip->isArchived()) {
|
||||
$this->addFlash('success', sprintf('Snip "%s" archived', $snip));
|
||||
} else {
|
||||
$this->addFlash('success', sprintf('Snip "%s" unarchived', $snip));
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ readonly class SnipFilterRequest implements CachableDtoInterface
|
||||
public const string VISIBILITY_ALL = 'all';
|
||||
public const string VISIBILITY_VISIBLE = 'visible';
|
||||
public const string VISIBILITY_HIDDEN = 'hidden';
|
||||
public const string VISIBILITY_ARCHIVED = 'archived';
|
||||
|
||||
public const string SORT_NAME = 'name';
|
||||
public const string SORT_DATE = 'date';
|
||||
|
@ -36,6 +36,9 @@ class Snip
|
||||
#[ORM\Column]
|
||||
private bool $visible = true;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $archived = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->snipContents = new ArrayCollection();
|
||||
@ -145,4 +148,16 @@ class Snip
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isArchived(): ?bool
|
||||
{
|
||||
return $this->archived;
|
||||
}
|
||||
|
||||
public function setArchived(bool $archived): static
|
||||
{
|
||||
$this->archived = $archived;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class SnipRepository extends ServiceEntityRepository
|
||||
->setParameter('user', $user)
|
||||
;
|
||||
|
||||
$showArchived = false;
|
||||
switch ($request->visibility) {
|
||||
case SnipFilterRequest::VISIBILITY_ALL:
|
||||
break;
|
||||
@ -59,9 +60,13 @@ class SnipRepository extends ServiceEntityRepository
|
||||
case SnipFilterRequest::VISIBILITY_HIDDEN:
|
||||
$qb->andWhere('s.visible = false');
|
||||
break;
|
||||
case SnipFilterRequest::VISIBILITY_ARCHIVED:
|
||||
$showArchived = true;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid visibility option: ', $request->visibility);
|
||||
}
|
||||
$qb->andWhere('s.archived = ' . ($showArchived ? 'true' : 'false'));
|
||||
|
||||
switch ($request->sort) {
|
||||
case SnipFilterRequest::SORT_NAME:
|
||||
@ -73,6 +78,7 @@ class SnipRepository extends ServiceEntityRepository
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid sort option: ', $request->sort);
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
@ -82,6 +88,7 @@ class SnipRepository extends ServiceEntityRepository
|
||||
->createQueryBuilder('s')
|
||||
->where('s.public = true')
|
||||
->andWhere('s.visible = true')
|
||||
->andWhere('s.archived = false')
|
||||
->orderBy('s.createdAt', 'DESC')
|
||||
;
|
||||
|
||||
|
Reference in New Issue
Block a user