-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01ef6f5
commit cb9a8c8
Showing
24 changed files
with
703 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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 Version20231212033444 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 comment (id INT AUTO_INCREMENT NOT NULL, author_id INT DEFAULT NULL, status_id INT NOT NULL, email VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', comment LONGTEXT NOT NULL, INDEX IDX_9474526CF675F31B (author_id), INDEX IDX_9474526C6BF700BD (status_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE comment_status (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_B1133D0E5E237E06 (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CF675F31B FOREIGN KEY (author_id) REFERENCES `user` (id)'); | ||
$this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C6BF700BD FOREIGN KEY (status_id) REFERENCES comment_status (id)'); | ||
|
||
foreach (['new', 'published', 'rejected'] as $commentStatus) { | ||
$this->addSql('INSERT INTO comment_status (name) values (:name)', ['name' => $commentStatus]); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526CF675F31B'); | ||
$this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526C6BF700BD'); | ||
$this->addSql('DROP TABLE comment'); | ||
$this->addSql('DROP TABLE comment_status'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Version20231212041343 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('ALTER TABLE comment ADD article_id INT NOT NULL'); | ||
$this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C7294869C FOREIGN KEY (article_id) REFERENCES article (id)'); | ||
$this->addSql('CREATE INDEX IDX_9474526C7294869C ON comment (article_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526C7294869C'); | ||
$this->addSql('DROP INDEX IDX_9474526C7294869C ON comment'); | ||
$this->addSql('ALTER TABLE comment DROP article_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Article; | ||
use App\Entity\Comment; | ||
use App\Form\AuthorizedCommentType; | ||
use App\Form\UnauthorizedCommentType; | ||
use App\Repository\CommentRepository; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[Route('/article', name: 'article.')] | ||
class ArticleController extends AbstractController | ||
{ | ||
#[Route('/{article}', name: 'show')] | ||
public function index(Article $article, Request $request, CommentRepository $commentRepository): Response | ||
{ | ||
$comment = (new Comment()) | ||
->setArticle($article); | ||
|
||
$form = $this->createForm($this->getUser() ? AuthorizedCommentType::class : UnauthorizedCommentType::class, $comment); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$commentRepository->save($comment, true); | ||
|
||
if ($comment->isStatusPublished()) { | ||
$this->addFlash('success', 'Комментарий опубликован'); | ||
} elseif ($comment->isStatusNew()) { | ||
$this->addFlash('success', 'Комментарий будет опубликован после проверки модератором'); | ||
} | ||
|
||
return $this->redirectToRoute('article.show', ['article' => $article->getId()]); | ||
} | ||
|
||
return $this->render('article/index.html.twig', [ | ||
'article' => $article, | ||
'form' => $form, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Controller\EasyAdmin; | ||
|
||
use App\Entity\Comment; | ||
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; | ||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||
|
||
class CommentCrudController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return Comment::class; | ||
} | ||
|
||
public function configureFields(string $pageName): iterable | ||
{ | ||
return [ | ||
IdField::new('id') | ||
->hideOnForm(), | ||
EmailField::new('email'), | ||
TextareaField::new('comment'), | ||
DateTimeField::new('createdAt') | ||
->hideOnForm(), | ||
AssociationField::new('status'), | ||
AssociationField::new('author') | ||
->hideOnForm() | ||
]; | ||
} | ||
|
||
public function configureFilters(Filters $filters): Filters | ||
{ | ||
return $filters | ||
->add('status'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.