Create snippets skeleton
This commit is contained in:
parent
bf83e5aabd
commit
921dcf1e97
@ -20,14 +20,12 @@ final class Version20230403161503 extends AbstractMigration
|
|||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
// this up() migration is auto-generated, please modify it to your needs
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
$this->addSql('CREATE TABLE email (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
|
||||||
$this->addSql('ALTER TABLE user ADD name VARCHAR(255) NOT NULL, ADD email VARCHAR(255) NOT NULL');
|
$this->addSql('ALTER TABLE user ADD name VARCHAR(255) NOT NULL, ADD email VARCHAR(255) NOT NULL');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
public function down(Schema $schema): void
|
||||||
{
|
{
|
||||||
// this down() migration is auto-generated, please modify it to your needs
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
$this->addSql('DROP TABLE email');
|
|
||||||
$this->addSql('ALTER TABLE `user` DROP name, DROP email');
|
$this->addSql('ALTER TABLE `user` DROP name, DROP email');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
migrations/Version20230403214405.php
Normal file
35
migrations/Version20230403214405.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?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 Version20230403214405 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TABLE snip (id INT AUTO_INCREMENT NOT NULL, created_by_id INT NOT NULL, name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_FEBD9796B03A8386 (created_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('ALTER TABLE snip ADD CONSTRAINT FK_FEBD9796B03A8386 FOREIGN KEY (created_by_id) REFERENCES `user` (id)');
|
||||||
|
$this->addSql('DROP TABLE email');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TABLE email (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
|
||||||
|
$this->addSql('ALTER TABLE snip DROP FOREIGN KEY FK_FEBD9796B03A8386');
|
||||||
|
$this->addSql('DROP TABLE snip');
|
||||||
|
}
|
||||||
|
}
|
@ -11,9 +11,9 @@ class HomeController extends AbstractController
|
|||||||
#[Route('/', name: 'home')]
|
#[Route('/', name: 'home')]
|
||||||
public function home(): Response
|
public function home(): Response
|
||||||
{
|
{
|
||||||
return $this->redirectToRoute('task_view');
|
// return $this->redirectToRoute('task_view');
|
||||||
// return $this->render('simple.html.twig', [
|
return $this->render('simple.html.twig', [
|
||||||
// 'text' => 'Welcome!'
|
'text' => 'Welcome!'
|
||||||
// ]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
29
src/Controller/SnipController.php
Normal file
29
src/Controller/SnipController.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Snip;
|
||||||
|
use App\Repository\SnipRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
#[Route('/snip', name: 'snip')]
|
||||||
|
class SnipController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/', name: '_index')]
|
||||||
|
public function index(SnipRepository $repository): Response
|
||||||
|
{
|
||||||
|
return $this->render('snip/index.html.twig', [
|
||||||
|
'snips' => $repository->findAll(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/singe/{snip}', name: '_single')]
|
||||||
|
public function single(Snip $snip): Response
|
||||||
|
{
|
||||||
|
return $this->render('snip/single.html.twig', [
|
||||||
|
'snip' => $snip,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
0
src/Entity/.gitignore
vendored
0
src/Entity/.gitignore
vendored
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity;
|
|
||||||
|
|
||||||
use App\Repository\EmailRepository;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: EmailRepository::class)]
|
|
||||||
class Email
|
|
||||||
{
|
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\GeneratedValue]
|
|
||||||
#[ORM\Column]
|
|
||||||
private ?int $id = null;
|
|
||||||
|
|
||||||
public function getId(): ?int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
}
|
|
22
src/Entity/Helpers/EnableableTrait.php
Normal file
22
src/Entity/Helpers/EnableableTrait.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Helpers;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
trait EnableableTrait
|
||||||
|
{
|
||||||
|
#[ORM\Column(options: ['default' => true])]
|
||||||
|
private bool $enabled = true;
|
||||||
|
|
||||||
|
public function isEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEnabled(bool $enabled): static
|
||||||
|
{
|
||||||
|
$this->enabled = $enabled;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
54
src/Entity/Helpers/TrackedTrait.php
Normal file
54
src/Entity/Helpers/TrackedTrait.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Helpers;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use DateTime;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
trait TrackedTrait
|
||||||
|
{
|
||||||
|
#[ORM\Column]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private ?DateTime $createdAt = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private ?User $createdBy = null;
|
||||||
|
|
||||||
|
public function getCreatedBy(): ?User
|
||||||
|
{
|
||||||
|
return $this->createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedBy(?User $createdBy): self
|
||||||
|
{
|
||||||
|
$this->createdBy = $createdBy;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt(): ?DateTime
|
||||||
|
{
|
||||||
|
return $this->createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt(DateTime $createdAt): self
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): string
|
||||||
|
{
|
||||||
|
return date_format($this->createdAt, "ymd");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAtTodayNoSeconds(): self
|
||||||
|
{
|
||||||
|
$this->setCreatedAt(DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i')));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
38
src/Entity/Snip.php
Normal file
38
src/Entity/Snip.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Entity\Helpers\TrackedTrait;
|
||||||
|
use App\Repository\SnipRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: SnipRepository::class)]
|
||||||
|
class Snip
|
||||||
|
{
|
||||||
|
use TrackedTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $name = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): ?string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): self
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
27
src/Form/SnipType.php
Normal file
27
src/Form/SnipType.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Snip;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class SnipType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('name')
|
||||||
|
->add('createdAt')
|
||||||
|
->add('createdBy')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Snip::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
66
src/Repository/SnipRepository.php
Normal file
66
src/Repository/SnipRepository.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Snip;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Snip>
|
||||||
|
*
|
||||||
|
* @method Snip|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method Snip|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method Snip[] findAll()
|
||||||
|
* @method Snip[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class SnipRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Snip::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(Snip $entity, bool $flush = false): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($entity);
|
||||||
|
|
||||||
|
if ($flush) {
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove(Snip $entity, bool $flush = false): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->remove($entity);
|
||||||
|
|
||||||
|
if ($flush) {
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Snip[] Returns an array of Snip objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('s')
|
||||||
|
// ->andWhere('s.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('s.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?Snip
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('s')
|
||||||
|
// ->andWhere('s.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark" style="z-index: 1;">
|
<nav class="navbar navbar-expand-md navbar-dark bg-dark" style="z-index: 1;">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a title="BlueLinked Eco System" class="navbar-brand" href="{{ path('home') }}">BLES</a>
|
<a title="BlueLinked Eco System" class="navbar-brand" href="{{ path('home') }}">Snips</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar"
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar"
|
||||||
aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
@ -11,6 +11,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ path('home') }}">Home</a>
|
<a class="nav-link" href="{{ path('home') }}">Home</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ path('snip_index') }}">Snips</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav my-2 my-lg-0">
|
<ul class="navbar-nav my-2 my-lg-0">
|
||||||
{% if app.environment == 'dev' %}
|
{% if app.environment == 'dev' %}
|
||||||
|
20
templates/snip/index.html.twig
Normal file
20
templates/snip/index.html.twig
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{% extends 'base/base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h1>Snippets</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="list-group">
|
||||||
|
{% for snip in snips %}
|
||||||
|
<a class="list-group-item">
|
||||||
|
{{ snip }}
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
11
templates/snip/single.html.twig
Normal file
11
templates/snip/single.html.twig
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{% extends 'base/base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h1>{{ snip }}</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -4,9 +4,6 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<h4>{{ app.user.name }}</h4>
|
<h4>{{ app.user.name }}</h4>
|
||||||
{% if is_granted('ROLE_API') %}
|
|
||||||
Your api key: {{ app.user.apiKey }} <a class="btn btn-primary" href="{{ path('user_apikey_generate') }}">Regenerate</a> <br/>
|
|
||||||
{% endif %}
|
|
||||||
<br/>
|
<br/>
|
||||||
{% if is_granted('ROLE_ADMIN') %}
|
{% if is_granted('ROLE_ADMIN') %}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
Loading…
Reference in New Issue
Block a user