This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Repository;
|
||||
use App\Entity\Order;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Order>
|
||||
@@ -39,6 +40,22 @@ class OrderRepository extends ServiceEntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(Order $entity, bool $flush = false): void
|
||||
{
|
||||
$order = $this->getEntityManager()->find(Order::class, $entity->getId());
|
||||
|
||||
if (!$order) {
|
||||
throw $this->createNotFoundException('Order not found: ' . $entity->getId());
|
||||
}
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Order[] Returns an array of Order objects
|
||||
// */
|
||||
@@ -63,4 +80,11 @@ class OrderRepository extends ServiceEntityRepository
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createNotFoundException(string $string)
|
||||
{
|
||||
throw new Exception($string);
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Orders;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Orders>
|
||||
*
|
||||
* @method Orders|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Orders|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Orders[] findAll()
|
||||
* @method Orders[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class OrdersRepository extends ServiceEntityRepository
|
||||
{
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function __construct(ManagerRegistry $registry, ValidatorInterface $validator)
|
||||
{
|
||||
parent::__construct($registry, Orders::class);
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Orders $entity
|
||||
* @param bool $flush
|
||||
* @return void
|
||||
*/
|
||||
public function add(Orders $entity, bool $flush = false): void
|
||||
{
|
||||
|
||||
$errors = $this->validator->validate($entity);
|
||||
if (count($errors) > 0) {
|
||||
var_dump($errors);
|
||||
}
|
||||
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Orders $entity
|
||||
* @param bool $flush
|
||||
* @return void
|
||||
*/
|
||||
public function update(Orders $entity, bool $flush = false): void
|
||||
{
|
||||
$order = $this->getEntityManager()->find(Orders::class, $entity->getId());
|
||||
|
||||
if (!$order) {
|
||||
throw $this->createNotFoundException('Order not found: '.$entity->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Orders $entity
|
||||
* @param bool $flush
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Orders $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Orders[] Returns an array of Orders objects
|
||||
*/
|
||||
public function findByStatus($status): array
|
||||
{
|
||||
return $this->createQueryBuilder('o')
|
||||
->andWhere('o.status = :val')
|
||||
->setParameter('val', $status)
|
||||
->orderBy('o.id', 'ASC')
|
||||
->setMaxResults(100)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return Orders|null
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function findOneByOrderId($orderId): ?Orders
|
||||
{
|
||||
return $this->createQueryBuilder('o')
|
||||
->andWhere('o.order_id = :val')
|
||||
->setParameter('val', $orderId)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Product;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -24,7 +25,7 @@ class ProductRepository extends ServiceEntityRepository
|
||||
public function save(Product $entity, bool $flush = false): ?int
|
||||
{
|
||||
|
||||
$entity->setUpdateTime(new \DateTime());
|
||||
$entity->setUpdateTime(new DateTime());
|
||||
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
@@ -68,4 +69,4 @@ class ProductRepository extends ServiceEntityRepository
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Stock;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -23,7 +24,7 @@ class StockRepository extends ServiceEntityRepository
|
||||
|
||||
public function save(Stock $entity, bool $flush = false): void
|
||||
{
|
||||
$entity->setUpdateTime(new \DateTime());
|
||||
$entity->setUpdateTime(new DateTime());
|
||||
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class WarehouseRepository extends ServiceEntityRepository
|
||||
|
||||
public function save(Warehouse $entity, bool $flush = false): ?int
|
||||
{
|
||||
$entity->setPrio(0);
|
||||
$entity->setPrio(0);
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
@@ -66,4 +66,4 @@ class WarehouseRepository extends ServiceEntityRepository
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user