add node view entity
This commit is contained in:
parent
1f6aaf41e1
commit
1cb57a138f
102
core/Entity/NodeView.php
Normal file
102
core/Entity/NodeView.php
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Entity;
|
||||||
|
|
||||||
|
use App\Core\Entity\Site\Node;
|
||||||
|
use App\Repository\Entity\NodeViewRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use App\Core\Entity\EntityInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity(repositoryClass=NodeViewRepository::class)
|
||||||
|
*/
|
||||||
|
class NodeView implements EntityInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\GeneratedValue
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity=Node::class, inversedBy="nodeViews")
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=255)
|
||||||
|
*/
|
||||||
|
private $path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="integer", options={"default"=0})
|
||||||
|
*/
|
||||||
|
private $views = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date")
|
||||||
|
*/
|
||||||
|
private $date;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNode(): ?Node
|
||||||
|
{
|
||||||
|
return $this->node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNode(?Node $node): self
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPath(): ?string
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPath(string $path): self
|
||||||
|
{
|
||||||
|
$this->path = $path;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getViews(): ?int
|
||||||
|
{
|
||||||
|
return $this->views;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setViews(int $views): self
|
||||||
|
{
|
||||||
|
$this->views = $views;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addView(): self
|
||||||
|
{
|
||||||
|
++$this->views;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDate(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDate(\DateTimeInterface $date): self
|
||||||
|
{
|
||||||
|
$this->date = $date;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
21
core/Factory/NodeViewFactory.php
Normal file
21
core/Factory/NodeViewFactory.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Factory;
|
||||||
|
|
||||||
|
use App\Core\Entity\NodeView as Entity;
|
||||||
|
use App\Core\Entity\Site\Node;
|
||||||
|
|
||||||
|
class NodeViewFactory implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function create(Node $node, string $path): Entity
|
||||||
|
{
|
||||||
|
$entity = new Entity();
|
||||||
|
$entity
|
||||||
|
->setNode($node)
|
||||||
|
->setPath($path)
|
||||||
|
->setDate(new \DateTime())
|
||||||
|
;
|
||||||
|
|
||||||
|
return $entity;
|
||||||
|
}
|
||||||
|
}
|
21
core/Repository/NodeViewRepository.php
Normal file
21
core/Repository/NodeViewRepository.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Repository;
|
||||||
|
|
||||||
|
use App\Core\Entity\NodeView;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method NodeView|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method NodeView|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method NodeView[] findAll()
|
||||||
|
* @method NodeView[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class NodeViewRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, NodeView::class);
|
||||||
|
}
|
||||||
|
}
|
27
core/Repository/NodeViewRepositoryQuery.php
Normal file
27
core/Repository/NodeViewRepositoryQuery.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Repository;
|
||||||
|
|
||||||
|
use App\Core\Repository\NodeViewRepository as Repository;
|
||||||
|
use Knp\Component\Pager\PaginatorInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class NodeViewRepositoryQuery extends RepositoryQuery
|
||||||
|
{
|
||||||
|
public function __construct(Repository $repository, PaginatorInterface $paginator)
|
||||||
|
{
|
||||||
|
parent::__construct($repository, 'n', $paginator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filterByRequest(Request $request)
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->andWhere('.node = :node')
|
||||||
|
->andWhere('.path = :path')
|
||||||
|
->setParameters([
|
||||||
|
':node' => $request->attributes->get('_node'),
|
||||||
|
':path' => $request->getPathInfo(),
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue