for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Stu\Orm\Repository;
use Couchbase\View;
use Doctrine\ORM\EntityRepository;
use Stu\Module\Control\ViewContext;
use Stu\Orm\Entity\TutorialStep;
use Stu\Orm\Entity\UserInterface;
use Stu\Orm\Entity\UserTutorial;
/**
* @extends EntityRepository<TutorialStep>
*/
final class TutorialStepRepository extends EntityRepository implements TutorialStepRepositoryInterface
{
public function findByUserAndViewContext(UserInterface $user, ViewContext $viewContext): array
$subquery = $this->getEntityManager()->createQuery(
sprintf(
'SELECT ts.id
FROM %s ts
JOIN %s ut WITH ts.id = ut.tutorial_step_id
WHERE ut.user = :user
AND ts.module = :module
AND ts.view = :view',
TutorialStep::class,
UserTutorial::class
)
)->setParameters([
'user' => $user,
'module' => $viewContext->getModule()->value,
'view' => $viewContext->getViewIdentifier(),
]);
$result = $subquery->getOneOrNullResult();
if (!$result) {
return [];
}
return $this->getEntityManager()->createQuery(
'SELECT ts FROM %s ts
WHERE ts.module = :module
TutorialStep::class
])->getResult();
public function findAllFirstSteps(): array
return $this->getEntityManager()
->createQuery(
'SELECT ts FROM %1$s ts
WHERE NOT EXISTS (SELECT ts2.id FROM %1$s ts2
WHERE ts2.next_step_id = ts.id)',
->getResult();