瀏覽代碼

Refactoring services

develop
Guillaume 3 年之前
父節點
當前提交
5e13852f33
共有 12 個檔案被更改,包括 206 行新增57 行删除
  1. +54
    -0
      Model/Site/NewsModel.php
  2. +32
    -3
      Model/User/UserModel.php
  3. +29
    -26
      Repository/AbstractRepository.php
  4. +13
    -0
      Repository/AbstractRepositoryQuery.php
  5. +17
    -0
      Repository/AbstractStore.php
  6. +0
    -6
      Repository/Site/PageRepositoryQuery.php
  7. +0
    -11
      Repository/Site/PageStore.php
  8. +26
    -0
      Repository/StatusRepositoryQueryTrait.php
  9. +2
    -2
      Repository/Ticket/TicketRepositoryQuery.php
  10. +24
    -0
      Repository/TreeRepositoryQueryTrait.php
  11. +7
    -7
      Repository/User/UserRepositoryQuery.php
  12. +2
    -2
      Repository/User/UserStore.php

+ 54
- 0
Model/Site/NewsModel.php 查看文件

@@ -5,6 +5,8 @@ namespace Lc\SovBundle\Model\Site;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;

/**
* @ORM\MappedSuperclass()
@@ -18,6 +20,22 @@ abstract class NewsModel extends AbstractFullEntity implements NewsInterface
*/
protected $date;

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isSent;


/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Newsletter\NewsletterInsterface", inversedBy="news")
*/
protected $newsletter;

/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\File\FileInsterface", cascade={"persist", "remove"})
*/
protected $image;

public function __toString()
{
return $this->getTitle();
@@ -34,4 +52,40 @@ abstract class NewsModel extends AbstractFullEntity implements NewsInterface

return $this;
}

public function getIsSent(): ?bool
{
return $this->isSent;
}

public function setIsSent(?bool $isSent): self
{
$this->isSent = $isSent;

return $this;
}

public function getImage(): ?FileInterface
{
return $this->image;
}

public function setImage(?FileInterface $image): self
{
$this->image = $image;

return $this;
}

public function getNewsletter(): ?NewsletterInterface
{
return $this->newsletter;
}

public function setNewsletter(?NewsletterInterface $newsletter): self
{
$this->newsletter = $newsletter;

return $this;
}
}

+ 32
- 3
Model/User/UserModel.php 查看文件

@@ -6,6 +6,8 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -13,8 +15,9 @@ use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class UserModel implements EntityInterface, UserInterface
abstract class UserModel implements EntityInterface, UserInterface, DevAliasInterface
{
use DevAliasTrait;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
@@ -50,6 +53,11 @@ abstract class UserModel implements EntityInterface, UserInterface
*/
protected $gender;

/**
* @ORM\Column(type="date", nullable=true)
*/
protected $birthdate;

/**
* @ORM\Column(type="boolean")
*/
@@ -119,6 +127,19 @@ abstract class UserModel implements EntityInterface, UserInterface
return $this;
}

public function getBirthdate(): ?\DateTimeInterface
{
return $this->birthdate;
}

public function setBirthdate(\DateTimeInterface $birthdate): self
{
$this->birthdate = $birthdate;

return $this;
}


/**
* @see UserInterface
*/
@@ -159,6 +180,7 @@ abstract class UserModel implements EntityInterface, UserInterface
}


//TODO vérifier si on peut déplacer da Solver
public function generatePassword($length = 8): string
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
@@ -213,9 +235,16 @@ abstract class UserModel implements EntityInterface, UserInterface
return $this;
}

public function getName(): ?string
public function getPhone(): ?string
{
return $this->phone;
}

public function setPhone(?string $phone): self
{
return $this->getFirstname().' '.strtoupper($this->getLastname());
$this->phone = $phone;

return $this;
}

public function isVerified(): bool

+ 29
- 26
Repository/AbstractRepository.php 查看文件

@@ -19,16 +19,6 @@ abstract class AbstractRepository extends ServiceEntityRepository implements Ser
$this->defaultLocale = $locale;
}

public function findOneByOldUrl($url)
{
$qb = $this->createQueryBuilder('entity')
->where('entity.oldUrls LIKE :oldUrl')
->andWhere('entity.status = 1')
->setParameter(':oldUrl', '%' . $url . '%');

return $qb->getQuery()->getOneOrNullResult();
}

public function getOneOrNullResult(QueryBuilder $qb, $locale = null, $hydrationMode = null)
{
return $this->getTranslatedQuery($qb, $locale)->getOneOrNullResult($hydrationMode);
@@ -75,20 +65,8 @@ abstract class AbstractRepository extends ServiceEntityRepository implements Ser
return $query;
}

public function findBySimilarSlug($slug)
{
$qb = $this->createQueryBuilder('entity')
->select('COUNT(entity.slug) as totalSimilar')
->andWhere('entity.status>=0')
->andWhere('entity.slug LIKE :slug')
->setParameter('slug', $slug)
->groupBy('entity.slug')
->having('COUNT(entity.slug) >=1');

return $qb->getQuery()->getOneOrNullResult();
}

public function findAll()
// @TODO : à vérifier si on peut les virer
/*public function findAll()
{
return $this->findBy(array());
}
@@ -109,7 +87,7 @@ abstract class AbstractRepository extends ServiceEntityRepository implements Ser

protected function setCriteria(array $criteria): array
{
/*$className = $this->getClassMetadata()->getName();
$className = $this->getClassMetadata()->getName();
$entity = new $className;

if ($entity instanceof StatusInterface) {
@@ -119,9 +97,34 @@ abstract class AbstractRepository extends ServiceEntityRepository implements Ser
if ($criteria['status'] === false) {
unset($criteria['status']);
}
}*/
}

return $criteria;
}*/

// @TODO : à réécrire dans un Store
/*
public function findBySimilarSlug($slug)
{
$qb = $this->createQueryBuilder('entity')
->select('COUNT(entity.slug) as totalSimilar')
->andWhere('entity.status>=0')
->andWhere('entity.slug LIKE :slug')
->setParameter('slug', $slug)
->groupBy('entity.slug')
->having('COUNT(entity.slug) >=1');

return $qb->getQuery()->getOneOrNullResult();
}

public function findOneByOldUrl($url)
{
$qb = $this->createQueryBuilder('entity')
->where('entity.oldUrls LIKE :oldUrl')
->andWhere('entity.status = 1')
->setParameter(':oldUrl', '%' . $url . '%');

return $qb->getQuery()->getOneOrNullResult();
}*/

}

+ 13
- 0
Repository/AbstractRepositoryQuery.php 查看文件

@@ -8,6 +8,9 @@ use Knp\Component\Pager\PaginatorInterface;

abstract class AbstractRepositoryQuery
{
use StatusRepositoryQueryTrait;
use TreeRepositoryQueryTrait;

protected ServiceEntityRepository $repository;
protected QueryBuilder $query;
protected PaginatorInterface $paginator;
@@ -122,5 +125,15 @@ abstract class AbstractRepositoryQuery
->andWhere('.devAlias = :devAlias')
->setParameter('devAlias', $devAlias);
}

public function filterBySlug(string $slug)
{
return $this
->andWhere('.slug = :slug')
->setParameter('slug', $slug);
}



}


+ 17
- 0
Repository/AbstractStore.php 查看文件

@@ -2,8 +2,15 @@

namespace Lc\SovBundle\Repository;

use Lc\SovBundle\Model\Site\PageInterface;

abstract class AbstractStore
{
public function createQuery()
{
return $this->query->create();
}

public function getRepositoryQuery()
{
return $this->query;
@@ -26,4 +33,14 @@ abstract class AbstractStore

return $query->findOne();
}

//findPageBySlug
public function getOneBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();
$query->filterBySlug($slug);

return $query->findOne();
}

}

+ 0
- 6
Repository/Site/PageRepositoryQuery.php 查看文件

@@ -12,10 +12,4 @@ class PageRepositoryQuery extends AbstractRepositoryQuery implements PageReposit
parent::__construct($repository, 'r', $paginator);
}

public function filterBySlug(string $slug)
{
return $this
->andWhere('.slug = :slug')
->setParameter('slug', $slug);
}
}

+ 0
- 11
Repository/Site/PageStore.php 查看文件

@@ -13,15 +13,4 @@ class PageStore extends AbstractStore implements PageStoreInterface
{
$this->query = $query;
}

//findPageBySlug
public function getBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();

$query
->filterBySlug($slug);

return $query->findOne();
}
}

+ 26
- 0
Repository/StatusRepositoryQueryTrait.php 查看文件

@@ -0,0 +1,26 @@
<?php

namespace Lc\SovBundle\Repository;

trait StatusRepositoryQueryTrait
{
public function filterByStatus(int $status):self
{
return $this->andWhere('.status = :status')->setParameter(':status', $status);
}

public function filterIsOffline():self
{
return $this->andWhere('.status = :status')->setParameter(':status', 0);
}

public function filterIsOnline():self
{
return $this->andWhere('.status = :status')->setParameter(':status', 1);
}

public function filterIsOnlineAndOffline():self
{
return $this->andWhere('.status >= 0');
}
}

+ 2
- 2
Repository/Ticket/TicketRepositoryQuery.php 查看文件

@@ -23,8 +23,8 @@ class TicketRepositoryQuery extends AbstractRepositoryQuery implements TicketRep
public function filterByStatus($statusArray): self
{
return $this
->andWhere('.status IN (:status)')
->setParameter('status', $statusArray);
->andWhere('.status IN (:status)')
->setParameter('status', $statusArray);
}

public function selectCount(): self

+ 24
- 0
Repository/TreeRepositoryQueryTrait.php 查看文件

@@ -0,0 +1,24 @@
<?php

namespace Lc\SovBundle\Repository;

use Lc\SovBundle\Doctrine\EntityInterface;

trait TreeRepositoryQueryTrait
{
public function filterIsParent()
{
return $this->andWhere('.parent is NULL');
}

public function filterIsChildren()
{
return $this->andWhere('.parent is NOT NULL');
}

public function filterByParent(EntityInterface $parent)
{
return $this->andWhere('.parent = :parent')->setParameter('parent', $parent);
}

}

+ 7
- 7
Repository/User/UserRepositoryQuery.php 查看文件

@@ -17,22 +17,22 @@ class UserRepositoryQuery extends AbstractRepositoryQuery implements UserReposit
public function filterByNewsletter(Newsletter $newsletter): self
{
return $this
->andWhere(':newsletter MEMBER OF .newsletters')
->setParameter('newsletter', $newsletter->getId());
->andWhere(':newsletter MEMBER OF .newsletters')
->setParameter('newsletter', $newsletter->getId());
}

public function filterByRole(string $role): self
{
return $this
->andWhere('.roles LIKE :roles')
->setParameter('roles', '%"' . $role . '"%');
->andWhere('.roles LIKE :roles')
->setParameter('roles', '%"' . $role . '"%');
}

public function filterByTicketTypeNotification(string $ticketType): self
{
return $this
->andWhere('.ticketTypesNotification LIKE :ticketType')
->setParameter('ticketType', '%"' . $ticketType . '"%');
->andWhere('.ticketTypesNotification LIKE :ticketType')
->setParameter('ticketType', '%"' . $ticketType . '"%');
}

public function filterByEmail(string $email): self
@@ -42,4 +42,4 @@ class UserRepositoryQuery extends AbstractRepositoryQuery implements UserReposit
->setParameter('email', $email);
}

}
}

+ 2
- 2
Repository/User/UserStore.php 查看文件

@@ -14,7 +14,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
$this->query = $query;
}

//findAllByNewsletter
//findAllByNewsletter
public function getByNewsletter(Newsletter $newsletter, $query = null): array
{
if (is_null($query)) {
@@ -27,7 +27,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
return $query->find();
}

//findByRole
//findByRole
public function getByRole(string $role): array
{
$query = $this->query->create();

Loading…
取消
儲存