Completed
Push — master ( b87c44...b5d8bc )
by Tim
14:02
created

AbstractRawRepository::updateByUid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
nc 1
cc 1
nop 2
1
<?php
2
/**
3
 * Abstract raw repository
4
 *
5
 * @author  Tim Lochmüller
6
 */
7
8
namespace HDNET\Focuspoint\Domain\Repository;
9
10
use TYPO3\CMS\Core\Database\ConnectionPool;
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
13
/**
14
 * Abstract raw repository
15
 */
16
abstract class AbstractRawRepository
17
{
18
19
    /**
20
     * Get the tablename
21
     *
22
     * @return string
23
     */
24
    abstract protected function getTableName(): string;
25
26
    /**
27
     * Find by uid
28
     *
29
     * @param int $uid
30
     * @return array|null
31
     */
32
    public function findByUid(int $uid)
33
    {
34
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->getTableName());
35
        $rows = $queryBuilder->select('*')
36
            ->from($this->getTableName())
37
            ->where(
38
                $queryBuilder->expr()->eq('uid', $uid)
39
            )
40
            ->execute()
41
            ->fetchAll();
42
        return isset($rows[0]) ? $rows[0] : null;
43
    }
44
45
    /**
46
     * Update by uid
47
     *
48
     * @param int $uid
49
     * @param array $values
50
     */
51
    public function updateByUid(int $uid, array $values)
52
    {
53
        $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->getTableName());
54
        $connection->update(
55
            $this->getTableName(),
56
            $values,
57
            ['uid' => (int) $uid]
58
        );
59
    }
60
61
}
62