Passed
Pull Request — master (#76)
by Romain
04:16
created

EntityNotificationRepository::initializeObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Repository;
18
19
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
20
use CuyZ\Notiz\Domain\Notification\EntityNotification;
21
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
22
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
23
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
24
use TYPO3\CMS\Extbase\Persistence\Repository;
25
26
class EntityNotificationRepository extends Repository
27
{
28
    /**
29
     * Initializes the query settings.
30
     */
31
    public function initializeObject()
32
    {
33
        /** @var $querySettings QuerySettingsInterface */
34
        $querySettings = $this->objectManager->get(QuerySettingsInterface::class);
35
36
        $querySettings->setRespectStoragePage(false);
37
38
        $this->setDefaultQuerySettings($querySettings);
39
    }
40
41
    /**
42
     * @param EventDefinition $eventDefinition
43
     * @return QueryResultInterface
44
     */
45
    public function findFromEventDefinition(EventDefinition $eventDefinition)
46
    {
47
        $query = $this->createQuery();
48
49
        $query->matching(
50
            $query->equals('event', $eventDefinition->getFullIdentifier())
51
        );
52
53
        return $query->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->execute() also could return the type array which is incompatible with the documented return type TYPO3\CMS\Extbase\Persistence\QueryResultInterface.
Loading history...
54
    }
55
56
    /**
57
     * Returns the wanted notification even if it was disabled.
58
     *
59
     * @param mixed $identifier
60
     * @return EntityNotification|object
61
     */
62
    public function findByIdentifierForce($identifier)
63
    {
64
        $query = $this->createQueryWithoutEnableStatement();
65
66
        $query->matching(
67
            $query->equals('uid', $identifier)
68
        );
69
70
        return $query->execute()->getFirst();
71
    }
72
73
    /**
74
     * @return QueryInterface
75
     */
76
    protected function createQueryWithoutEnableStatement()
77
    {
78
        $query = $this->createQuery();
79
        $query->getQuerySettings()
80
            ->setIgnoreEnableFields(true);
81
82
        return $query;
83
    }
84
}
85