Skip to content

Commit

Permalink
Merge aeae796 into a45ab48
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsverkoyen committed Nov 15, 2017
2 parents a45ab48 + aeae796 commit 90b2770
Show file tree
Hide file tree
Showing 12 changed files with 674 additions and 261 deletions.
30 changes: 30 additions & 0 deletions src/Backend/Modules/Blog/DependencyInjection/BlogExtension.php
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');
}
}
205 changes: 205 additions & 0 deletions src/Backend/Modules/Blog/Domain/Comment/Comment.php
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 src/Backend/Modules/Blog/Domain/Comment/CommentRepository.php
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);
}
}
Loading

0 comments on commit 90b2770

Please sign in to comment.