Passed
Pull Request — master (#201)
by
unknown
09:49 queued 02:44
created

ProcessNumberRepository::startTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EWW\Dpf\Domain\Repository;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Database\Connection;
18
use TYPO3\CMS\Core\Database\ConnectionPool;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
21
22
/**
23
 * The repository for ProcessNumbers
24
 */
25
class ProcessNumberRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
26
{
27
28
    public function initializeObject() {
29
        $querySettings = $this->objectManager->get(Typo3QuerySettings::class);
30
        $querySettings->setRespectStoragePage(FALSE);
31
        $this->setDefaultQuerySettings($querySettings);
32
    }
33
34
    /**
35
     * Finds the highest case number of an owner id
36
     * for the current year
37
     *
38
     * @var string ownerId
39
     * @return array The found ProcessNumber Object
40
     */
41
    public function getHighestProcessNumberByOwnerIdAndYear($ownerId,$year)
42
    {
43
44
        $query = $this->createQuery();
45
46
        $constraints = array();
47
        $constraints[] = $query->equals('owner_id', $ownerId, false);
48
49
        $constraints[] = $query->equals('year', $year);
50
51
        if (count($constraints)) {
52
            $query->matching($query->logicalAnd($constraints));
53
        }
54
55
        $query->setOrderings(array("counter" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
56
57
        $result = $query->execute();
58
59
        if ($result) {
60
            return $result->getFirst();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->getFirst() returns the type object which is incompatible with the documented return type array.
Loading history...
61
        }
62
63
        return NULL;
64
    }
65
66
    /**
67
     * Get the connection for the process number table
68
     *
69
     * @return Connection
70
     */
71
    protected function getConnection()
72
    {
73
        return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(
74
            "tx_dpf_domain_model_processnumber"
75
        );
76
    }
77
78
    /**
79
     * Start transaction
80
     */
81
    public function startTransaction() {
82
        $this->getConnection()->beginTransaction();
83
    }
84
85
    /**
86
     * Commit transaction
87
     *
88
     * @throws \Doctrine\DBAL\ConnectionException
89
     */
90
    public function commitTransaction() {
91
        $this->getConnection()->commit();
92
    }
93
94
    /**
95
     * Rollback transaction
96
     *
97
     * @throws \Doctrine\DBAL\ConnectionException
98
     */
99
    public function rollbackTransaction() {
100
        $this->getConnection()->rollBack();
101
    }
102
103
}
104