MemberRepository.php 2.13 KB
Newer Older
Thomas Löffler's avatar
Thomas Löffler committed
1
<?php
Sebastian Diez's avatar
Sebastian Diez committed
2
3
4
5
6
namespace T3o\T3oMembership\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

7
8
/**
 * This file is part of the TYPO3 CMS project.
Thomas Löffler's avatar
Thomas Löffler committed
9
 *
10
11
12
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
Thomas Löffler's avatar
Thomas Löffler committed
13
 *
14
15
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
Thomas Löffler's avatar
Thomas Löffler committed
16
 *
17
18
 * The TYPO3 project - inspiring people to share!
 */
Thomas Löffler's avatar
Thomas Löffler committed
19
20

/**
Sebastian Diez's avatar
Sebastian Diez committed
21
 * Class \T3oMembership\Domain\Repository\MemberRepository
22
 *
23
 * @author Thomas Löffler <thomas.loeffler@typo3.org>
Thomas Löffler's avatar
Thomas Löffler committed
24
 */
Sebastian Diez's avatar
Sebastian Diez committed
25
class MemberRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
Thomas Löffler's avatar
Thomas Löffler committed
26
{
Thomas Löffler's avatar
Thomas Löffler committed
27

Thomas Löffler's avatar
Thomas Löffler committed
28
29
30
    /**
     * @var array
     */
31
    protected $defaultOrderings = [
32
        'membership.sorting' => QueryInterface::ORDER_ASCENDING,
33
34
35
        'name' => QueryInterface::ORDER_ASCENDING,
        'lastname' => QueryInterface::ORDER_ASCENDING
    ];
Thomas Löffler's avatar
Thomas Löffler committed
36

Thomas Löffler's avatar
Thomas Löffler committed
37
    /**
38
     * @param string $filterString
Thomas Löffler's avatar
Thomas Löffler committed
39
     * @param integer $filterMembership
Sebastian Diez's avatar
Sebastian Diez committed
40
     * @return QueryResultInterface
Thomas Löffler's avatar
Thomas Löffler committed
41
42
43
44
     */
    public function findByStringAndMembership($filterString, $filterMembership)
    {
        $query = $this->createQuery();
45
        $constraints = [];
Thomas Löffler's avatar
Thomas Löffler committed
46
        if ($filterString) {
47
            $filterString = $this->getDatabaseConnection()->escapeStrForLike($filterString, 'tx_t3omembership_domain_model_member');
48
49
50
51
52
53
54
            $constraints = $query->logicalOr(
                [
                    $query->like('name', '%' . $filterString . '%'),
                    $query->like('firstname', '%' . $filterString . '%'),
                    $query->like('lastname', '%' . $filterString . '%'),
                ]
            );
Thomas Löffler's avatar
Thomas Löffler committed
55
56
57
58
        }
        if ($filterMembership) {
            $constraints[] = $query->equals('membership', $filterMembership);
        }
Thomas Löffler's avatar
Thomas Löffler committed
59

Thomas Löffler's avatar
Thomas Löffler committed
60
61
        return $query->matching($query->logicalAnd($constraints))->execute();
    }
Thomas Löffler's avatar
Thomas Löffler committed
62

Thomas Löffler's avatar
Thomas Löffler committed
63
    /**
64
     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
Thomas Löffler's avatar
Thomas Löffler committed
65
66
67
68
69
     */
    protected function getDatabaseConnection()
    {
        return $GLOBALS['TYPO3_DB'];
    }
70
}