Completed
Push — master ( 4cc4cf...1e6e7e )
by Tim
13:02 queued 10s
created

QuestionCategoryRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createQuery() 0 8 1
A findByParent() 0 10 2
1
<?php
2
3
declare(strict_types = 1);
4
/**
5
 * Build up the Question category.
6
 */
7
8
namespace HDNET\Faq\Domain\Repository;
9
10
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
11
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
12
13
/**
14
 * Build up the Question category.
15
 */
16
class QuestionCategoryRepository extends AbstractRepository
17
{
18
    /**
19
     * Default sorting.
20
     *
21
     * @var array
22
     */
23
    protected $defaultOrderings = ['sorting' => QueryInterface::ORDER_ASCENDING];
24
25
    /**
26
     * Create query.
27
     *
28
     * @return QueryInterface
29
     */
30
    public function createQuery(): QueryInterface
31
    {
32
        $query = parent::createQuery();
33
        $query->getQuerySettings()
34
            ->setRespectStoragePage(false);
35
36
        return $query;
37
    }
38
39
    /**
40
     * Find the categories in the right order (default: default, $sorting=TRUE: alphabetical).
41
     *
42
     * @param int  $topCategory
43
     * @param bool $sorting
44
     *
45
     * @return array|QueryResultInterface
46
     */
47
    public function findByParent(int $topCategory, bool $sorting = false)
48
    {
49
        $query = $this->createQuery();
50
        $query->matching($query->equals('parent', $topCategory));
51
        if ($sorting) {
52
            $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
53
        }
54
55
        return $query->execute();
56
    }
57
}
58