|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fab\Vidi\Domain\Repository; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the Fab/Vidi project under GPLv2 or later. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; |
|
12
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
|
13
|
|
|
use TYPO3\CMS\Extbase\Persistence\Repository; |
|
14
|
|
|
use Fab\Vidi\Domain\Model\Selection; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Repository for accessing Selections |
|
18
|
|
|
*/ |
|
19
|
|
|
class SelectionRepository extends Repository |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $dataType |
|
24
|
|
|
* @return QueryResult |
|
25
|
|
|
*/ |
|
26
|
|
|
public function findByDataTypeForCurrentBackendUser($dataType) |
|
27
|
|
|
{ |
|
28
|
|
|
$query = $this->createQuery(); |
|
29
|
|
|
|
|
30
|
|
|
// Compute the OR part |
|
31
|
|
|
if ($this->getBackendUser()->isAdmin()) { |
|
32
|
|
|
$logicalOr = $query->logicalOr( |
|
33
|
|
|
$query->equals('visibility', Selection::VISIBILITY_EVERYONE), |
|
34
|
|
|
$query->equals('visibility', Selection::VISIBILITY_ADMIN_ONLY), |
|
35
|
|
|
$query->equals('cruser_id', $this->getBackendUser()->user['uid']) |
|
36
|
|
|
); |
|
37
|
|
|
} else { |
|
38
|
|
|
$logicalOr = $query->logicalOr( |
|
39
|
|
|
$query->equals('visibility', Selection::VISIBILITY_EVERYONE), |
|
40
|
|
|
$query->equals('cruser_id', $this->getBackendUser()->user['uid']) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Add matching criteria |
|
45
|
|
|
$query->matching( |
|
46
|
|
|
$query->logicalAnd( |
|
47
|
|
|
$query->equals('dataType', $dataType), |
|
48
|
|
|
$logicalOr |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
// Set ordering |
|
53
|
|
|
$query->setOrderings( |
|
54
|
|
|
array('name' => QueryInterface::ORDER_ASCENDING) |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
return $query->execute(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $dataType |
|
62
|
|
|
* @return QueryResult |
|
63
|
|
|
*/ |
|
64
|
|
|
public function findForEveryone($dataType) |
|
65
|
|
|
{ |
|
66
|
|
|
$query = $this->createQuery(); |
|
67
|
|
|
|
|
68
|
|
|
// Add matching criteria |
|
69
|
|
|
$query->matching( |
|
70
|
|
|
$query->logicalAnd( |
|
71
|
|
|
$query->equals('dataType', $dataType), |
|
72
|
|
|
$query->equals('visibility', Selection::VISIBILITY_EVERYONE) |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
// Set ordering |
|
77
|
|
|
$query->setOrderings( |
|
78
|
|
|
array('name' => QueryInterface::ORDER_ASCENDING) |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
return $query->execute(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Returns an instance of the current Backend User. |
|
86
|
|
|
* |
|
87
|
|
|
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function getBackendUser() |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
return $GLOBALS['BE_USER']; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: