for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\Photo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* @method Photo|null find($id, $lockMode = null, $lockVersion = null)
* @method Photo|null findOneBy(array $criteria, array $orderBy = null)
* @method Photo[] findAll()
* @method Photo[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
final class PhotoRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
parent::__construct($registry, Photo::class);
}
public function reorderPhotos(array $ids): void
$i = 1;
foreach ($ids as $id) {
$this->createQueryBuilder('i')
->update('App\Entity\Photo', 'p')
->set('p.sort_order', $i)
->where('p.id = ?1')
->setParameter(1, $id)
->getQuery()
->execute();
++$i;