-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
Showing
12 changed files
with
674 additions
and
261 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/Backend/Modules/Blog/DependencyInjection/BlogExtension.php
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,30 @@ | ||
<?php | ||
|
||
namespace Backend\Modules\Blog\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\Config\FileLocator; | ||
|
||
class BlogExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new Loader\YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../Resources/config') | ||
); | ||
$loader->load('services.yml'); | ||
} | ||
|
||
public function prepend(ContainerBuilder $container): void | ||
{ | ||
$loader = new Loader\YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../Resources/config') | ||
); | ||
$loader->load('doctrine.yml'); | ||
} | ||
} |
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,205 @@ | ||
<?php | ||
|
||
namespace Backend\Modules\Blog\Domain\Comment; | ||
|
||
use Common\Locale; | ||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Table(name="blog_comments") | ||
* @ORM\Entity(repositoryClass="Backend\Modules\Blog\Domain\Comment\CommentRepository") | ||
* @ORM\HasLifecycleCallbacks | ||
*/ | ||
class Comment | ||
{ | ||
/** | ||
* @var int | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var int | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $postId; | ||
|
||
/** | ||
* @var Locale | ||
* @ORM\Column(type="locale") | ||
*/ | ||
private $locale; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="string") | ||
*/ | ||
private $author; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="string") | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @var null|string | ||
* @ORM\Column(type="string", nullable=true) | ||
*/ | ||
private $website; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="text") | ||
*/ | ||
private $text; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="string", options={"default":"comment"}) | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="string", options={"default":"moderation"}) | ||
*/ | ||
private $status; | ||
|
||
/** | ||
* @var null|string | ||
* @ORM\Column(type="text", nullable=true) | ||
*/ | ||
private $data; | ||
|
||
/** | ||
* @var DateTime | ||
* @ORM\Column(type="datetime") | ||
*/ | ||
private $createdOn; | ||
|
||
public function __construct( | ||
int $postId, | ||
Locale $locale, | ||
string $author, | ||
string $email, | ||
string $text, | ||
string $type, | ||
string $status, | ||
?string $website, | ||
?string $data | ||
) { | ||
$this->postId = $postId; | ||
$this->locale = $locale; | ||
$this->author = $author; | ||
$this->email = $email; | ||
$this->text = $text; | ||
$this->type = $type; | ||
$this->status = $status; | ||
$this->website = $website; | ||
$this->data = $data; | ||
} | ||
|
||
public function update( | ||
string $author, | ||
string $email, | ||
string $text, | ||
string $type, | ||
string $status, | ||
?string $website, | ||
?string $data | ||
) { | ||
$this->author = $author; | ||
$this->email = $email; | ||
$this->text = $text; | ||
$this->type = $type; | ||
$this->status = $status; | ||
$this->website = $website; | ||
$this->data = $data; | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getPostId(): int | ||
{ | ||
return $this->postId; | ||
} | ||
|
||
public function getLocale(): Locale | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
public function getAuthor(): string | ||
{ | ||
return $this->author; | ||
} | ||
|
||
public function getEmail(): string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function getWebsite(): ?string | ||
{ | ||
return $this->website; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getStatus(): string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function getData(): ?string | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function getCreatedOn(): DateTime | ||
{ | ||
return $this->createdOn; | ||
} | ||
|
||
/** | ||
* @ORM\PrePersist | ||
*/ | ||
public function prePersist(): void | ||
{ | ||
if ($this->createdOn === null) { | ||
$this->createdOn = new DateTime(); | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'post_id' => $this->postId, | ||
'language' => $this->locale->getLocale(), | ||
'created_on' => $this->createdOn->format('U'), | ||
'author' => $this->author, | ||
'email' => $this->email, | ||
'website' => $this->website, | ||
'text' => $this->text, | ||
'type' => $this->type, | ||
'status' => $this->status, | ||
'data' => $this->data, | ||
]; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/Backend/Modules/Blog/Domain/Comment/CommentRepository.php
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,73 @@ | ||
<?php | ||
|
||
namespace Backend\Modules\Blog\Domain\Comment; | ||
|
||
use Common\Locale; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\ORM\EntityRepository; | ||
|
||
class CommentRepository extends EntityRepository | ||
{ | ||
public function listCountPerStatus(Locale $locale): array | ||
{ | ||
$builder = $this->createQueryBuilder('c') | ||
->select('c.status, count(c.status) as number') | ||
->where("c.locale = :locale") | ||
->setParameter('locale', $locale) | ||
->groupBy('c.status'); | ||
|
||
$results = $builder->getQuery()->getResult(); | ||
$data = []; | ||
|
||
foreach ($results as $row) { | ||
$data[$row['status']] = $row['number']; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function updateMultipleStatusById(array $ids, string $status): void | ||
{ | ||
$entityManager = $this->getEntityManager(); | ||
|
||
$builder = $entityManager | ||
->createQueryBuilder() | ||
->update(Comment::class, 'c') | ||
->set('c.status', ':newStatus') | ||
->where('c.id IN(:ids)') | ||
->setParameter( | ||
':newStatus', | ||
$status | ||
) | ||
->setParameter( | ||
':ids', | ||
$ids, | ||
Connection::PARAM_INT_ARRAY | ||
); | ||
$builder->getQuery()->execute(); | ||
|
||
// clear all the entities, as they won't get detached automatically on | ||
// removal | ||
$entityManager->clear(Comment::class); | ||
} | ||
|
||
public function deleteMultipleById(array $ids): void | ||
{ | ||
$entityManager = $this->getEntityManager(); | ||
|
||
$builder = $entityManager | ||
->createQueryBuilder() | ||
->delete(Comment::class, 'c') | ||
->where('c.id IN(:ids)') | ||
->setParameter( | ||
':ids', | ||
$ids, | ||
Connection::PARAM_INT_ARRAY | ||
); | ||
$builder->getQuery()->execute(); | ||
|
||
// clear all the entities, as they won't get detached automatically on | ||
// removal | ||
$entityManager->clear(Comment::class); | ||
} | ||
} |
Oops, something went wrong.