Browse Source

Refactoring services

develop
Guillaume 3 years ago
parent
commit
9c4aa9731e
9 changed files with 126 additions and 71 deletions
  1. +13
    -37
      Doctrine/Extension/BlameableNullableTrait.php
  2. +8
    -12
      Repository/AbstractRepositoryQuery.php
  3. +17
    -0
      Repository/File/FileStore.php
  4. +17
    -0
      Repository/Newsletter/NewsletterStore.php
  5. +14
    -16
      Repository/RepositoryQueryInterface.php
  6. +17
    -0
      Repository/Setting/SiteSettingStore.php
  7. +17
    -0
      Repository/Site/SiteStore.php
  8. +17
    -0
      Repository/Ticket/TicketMessageStore.php
  9. +6
    -6
      Solver/Setting/SettingSolver.php

+ 13
- 37
Doctrine/Extension/BlameableNullableTrait.php View File

trait BlameableNullableTrait trait BlameableNullableTrait
{ {


/**
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
* @ORM\JoinColumn(nullable=true)
*/
protected $createdBy;
/**
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
* @ORM\JoinColumn(nullable=true)
*/
protected $createdBy;

/**
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
* @ORM\JoinColumn(nullable=true)
*/
protected $updatedBy;


/**
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
* @ORM\JoinColumn(nullable=true)
*/
protected $updatedBy;


public function getCreatedBy(): ?UserInterface
{
return $this->createdBy;
}

public function setCreatedBy(?UserInterface $createdBy): self
{
$this->createdBy = $createdBy;

return $this;
}

public function getUpdatedBy(): ?UserInterface
{
return $this->updatedBy;
}

public function setUpdatedBy(?UserInterface $updatedBy): self
{
$this->updatedBy = $updatedBy;

return $this;
}


} }

+ 8
- 12
Repository/AbstractRepositoryQuery.php View File

return $this->query->getQuery()->getResult(); return $this->query->getQuery()->getResult();
} }


public function limit(int $maxResults)
public function limit(int $maxResults):self
{ {
return $this->query->setMaxResults($maxResults);
$this->query->setMaxResults($maxResults);
return $this;
} }


public function paginate(int $page = 1, int $limit = 20) public function paginate(int $page = 1, int $limit = 20)
} }
} }


public function filterById(int $id)
public function filterById(int $id):self
{ {
return $this return $this
->andWhere('.id = :id') ->andWhere('.id = :id')
/* /*
* SLUG * SLUG
*/ */
public function filterBySlug(string $slug)
public function filterBySlug(string $slug):self
{ {
return $this return $this
->andWhere('.slug = :slug') ->andWhere('.slug = :slug')
/* /*
* TREE * TREE
*/ */
public function filterIsParent()
public function filterIsParent():self
{ {
return $this->andWhere('.parent is NULL'); return $this->andWhere('.parent is NULL');
} }


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


public function filterByParent(EntityInterface $parent)
public function filterByParent(EntityInterface $parent):self
{ {
return $this->andWhere('.parent = :parent')->setParameter('parent', $parent); return $this->andWhere('.parent = :parent')->setParameter('parent', $parent);
} }
/* /*
* STATUS * STATUS
*/ */
public function filterByStatus(int $status):self
{
return $this->andWhereStatus($this->id, $status);
}

public function filterIsOffline():self public function filterIsOffline():self
{ {
return $this->andWhereStatus($this->id, 0); return $this->andWhereStatus($this->id, 0);

+ 17
- 0
Repository/File/FileStore.php View File

namespace Lc\SovBundle\Repository\File; namespace Lc\SovBundle\Repository\File;


use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;


class FileStore extends AbstractStore implements FileStoreInterface class FileStore extends AbstractStore implements FileStoreInterface
{ {
{ {
$this->query = $query; $this->query = $query;
} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}
} }

+ 17
- 0
Repository/Newsletter/NewsletterStore.php View File

namespace Lc\SovBundle\Repository\Newsletter; namespace Lc\SovBundle\Repository\Newsletter;


use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;


class NewsletterStore extends AbstractStore implements NewsletterStoreInterface class NewsletterStore extends AbstractStore implements NewsletterStoreInterface
{ {
{ {
$this->query = $query; $this->query = $query;
} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}
} }

+ 14
- 16
Repository/RepositoryQueryInterface.php View File

{ {
public function create(); public function create();


public function call(callable $fn): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function call(callable $fn):self;


public function count(): string; public function count(): string;




public function find(): array; public function find(): array;


public function limit(int $maxResults);
public function limit(int $maxResults):self;


public function paginate(int $page = 1, int $limit = 20); public function paginate(int $page = 1, int $limit = 20);


public function getRepository(): ServiceEntityRepository; public function getRepository(): ServiceEntityRepository;


public function groupBy(string $field): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function groupBy(string $field):self;


public function orderBy(string $field, string $sort = 'ASC'): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function orderBy(string $field, string $sort = 'ASC'):self;


public function filterById(int $id);
public function filterById(int $id):self;


public function filterByDevAlias(string $devAlias): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function filterByDevAlias(string $devAlias):self;


public function filterBySlug(string $slug);
public function filterBySlug(string $slug):self;


public function filterIsParent();
public function filterIsParent():self;


public function filterIsChildren();
public function filterIsChildren():self;


public function filterByParent(EntityInterface $parent);
public function filterByParent(EntityInterface $parent):self;


public function filterByStatus($status): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function filterIsOffline():self;


public function filterIsOffline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function filterIsOnline():self;


public function filterIsOnline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function filterIsDeleted():self;


public function filterIsDeleted(): \Lc\SovBundle\Repository\AbstractRepositoryQuery;

public function filterIsOnlineAndOffline(): \Lc\SovBundle\Repository\AbstractRepositoryQuery;
public function filterIsOnlineAndOffline():self;
} }

+ 17
- 0
Repository/Setting/SiteSettingStore.php View File

namespace Lc\SovBundle\Repository\Setting; namespace Lc\SovBundle\Repository\Setting;


use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;


class SiteSettingStore extends AbstractStore implements SiteSettingStoreInterface class SiteSettingStore extends AbstractStore implements SiteSettingStoreInterface
{ {
{ {
$this->query = $query; $this->query = $query;
} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}
} }

+ 17
- 0
Repository/Site/SiteStore.php View File

namespace Lc\SovBundle\Repository\Site; namespace Lc\SovBundle\Repository\Site;


use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;


class SiteStore extends AbstractStore implements SiteStoreInterface class SiteStore extends AbstractStore implements SiteStoreInterface
{ {
{ {
$this->query = $query; $this->query = $query;
} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}
} }

+ 17
- 0
Repository/Ticket/TicketMessageStore.php View File

namespace Lc\SovBundle\Repository\Ticket; namespace Lc\SovBundle\Repository\Ticket;


use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;


class TicketMessageStore extends AbstractStore implements TicketMessageStoreInterface class TicketMessageStore extends AbstractStore implements TicketMessageStoreInterface
{ {
{ {
$this->query = $query; $this->query = $query;
} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{

return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}
} }

+ 6
- 6
Solver/Setting/SettingSolver.php View File

{ {
public function getValue(SettingInterface $setting) public function getValue(SettingInterface $setting)
{ {
if ($this->getText()) {
return $this->getText();
} elseif ($this->getDate()) {
return $this->getDate();
} elseif ($this->getFile()) {
return $this->getFile();
if ($setting->getText()) {
return $setting->getText();
} elseif ($setting->getDate()) {
return $setting->getDate();
} elseif ($setting->getFile()) {
return $setting->getFile();
} }
} }
} }

Loading…
Cancel
Save