Code Duplication    Length = 50-51 lines in 2 locations

src/Kunstmaan/AdminListBundle/Repository/EntityVersionLockRepository.php 1 location

@@ 12-61 (lines=50) @@
9
/**
10
 * EntityVersionLockRepository
11
 */
12
class EntityVersionLockRepository extends EntityRepository
13
{
14
    /**
15
     * Check if there is a entity lock that's not passed the threshold.
16
     *
17
     * @param LockableEntity $entity
18
     * @param int            $threshold
19
     * @param User           $userToExclude
20
     *
21
     * @return EntityVersionLock[]
22
     */
23
    public function getLocksForLockableEntity(LockableEntity $entity, $threshold, User $userToExclude = null)
24
    {
25
        $qb = $this->createQueryBuilder('evl')
26
            ->select('evl')
27
            ->join('evl.lockableEntity', 'le')
28
            ->where('le.id = :e')
29
            ->andWhere('evl.createdAt > :date')
30
            ->setParameter('e', $entity->getId())
31
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)))
32
        ;
33
34
        if (!\is_null($userToExclude)) {
35
            $qb->andWhere('evl.owner <> :owner')
36
                ->setParameter('owner', $userToExclude->getUsername())
37
            ;
38
        }
39
40
        return $qb->getQuery()->getResult();
41
    }
42
43
    /**
44
     * Get locks that are passed the threshold.
45
     *
46
     * @param LockableEntity $entity
47
     * @param int            $threshold
48
     *
49
     * @return mixed
50
     */
51
    public function getExpiredLocks(LockableEntity $entity, $threshold)
52
    {
53
        $qb = $this->createQueryBuilder('evl')
54
            ->select('evl')
55
            ->join('evl.lockableEntity', 'le')
56
            ->where('le.id = :e')
57
            ->andWhere('evl.createdAt < :date')
58
            ->setParameter('e', $entity->getId())
59
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)));
60
61
        return $qb->getQuery()->getResult();
62
    }
63
}
64

src/Kunstmaan/NodeBundle/Repository/NodeVersionLockRepository.php 1 location

@@ 15-65 (lines=51) @@
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15
class NodeVersionLockRepository extends \Doctrine\ORM\EntityRepository
16
{
17
    /**
18
     * Check if there is a nodetranslation lock that's not passed the 30 minute threshold.
19
     *
20
     * @param NodeTranslation $nodeTranslation
21
     * @param bool            $isPublicVersion
22
     * @param int             $threshold
23
     * @param BaseUser        $userToExclude
24
     *
25
     * @return NodeVersionLock[]
26
     */
27
    public function getLocksForNodeTranslation(NodeTranslation $nodeTranslation, $isPublicVersion, $threshold, BaseUser $userToExclude = null)
28
    {
29
        $qb = $this->createQueryBuilder('nvl')
30
            ->select('nvl')
31
            ->where('nvl.nodeTranslation = :nt')
32
            ->andWhere('nvl.publicVersion = :pub')
33
            ->andWhere('nvl.createdAt > :date')
34
            ->setParameter('nt', $nodeTranslation)
35
            ->setParameter('pub', $isPublicVersion)
36
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)))
37
        ;
38
39
        if (!\is_null($userToExclude)) {
40
            $qb->andWhere('nvl.owner <> :owner')
41
                ->setParameter('owner', $userToExclude->getUsername())
42
            ;
43
        }
44
45
        return $qb->getQuery()->getResult();
46
    }
47
48
    /**
49
     * Get locks that are passed the threshold.
50
     *
51
     * @param NodeTranslation $nodeTranslation
52
     * @param int             $threshold
53
     *
54
     * @return mixed
55
     */
56
    public function getExpiredLocks(NodeTranslation $nodeTranslation, $threshold)
57
    {
58
        $qb = $this->createQueryBuilder('nvl')
59
            ->select('nvl')
60
            ->where('nvl.nodeTranslation = :nt')
61
            ->andWhere('nvl.createdAt < :date')
62
            ->setParameter('nt', $nodeTranslation)
63
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)));
64
65
        return $qb->getQuery()->getResult();
66
    }
67
}
68