Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Repository/NodeVersionLockRepository.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\NodeBundle\Repository;
4
5
use Kunstmaan\AdminBundle\Entity\BaseUser;
6
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
7
use Kunstmaan\NodeBundle\Entity\NodeVersionLock;
8
9
/**
10
 * NodeVersionLockRepository
11
 *
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15 View Code Duplication
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
0 ignored issues
show
Should the type for parameter $userToExclude not be null|BaseUser?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
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