|
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 EWW\Dpf\Domain\Model\Bookmark; |
|
18
|
|
|
use EWW\Dpf\Domain\Model\Document; |
|
19
|
|
|
use \EWW\Dpf\Domain\Workflow\DocumentWorkflow; |
|
20
|
|
|
use \EWW\Dpf\Security\Security; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The repository for Bookmarks |
|
24
|
|
|
*/ |
|
25
|
|
|
class BookmarkRepository extends \EWW\Dpf\Domain\Repository\AbstractRepository |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @param int $feUserUid |
|
29
|
|
|
* @param string $identifier |
|
30
|
|
|
* @return object |
|
31
|
|
|
*/ |
|
32
|
|
|
public function findBookmark($feUserUid, $identifier) |
|
33
|
|
|
{ |
|
34
|
|
|
$query = $this->createQuery(); |
|
35
|
|
|
|
|
36
|
|
|
$query->matching( |
|
37
|
|
|
$query->logicalAnd( |
|
38
|
|
|
$query->equals('document_identifier', $identifier), |
|
39
|
|
|
$query->equals('fe_user_uid', $feUserUid) |
|
|
|
|
|
|
40
|
|
|
) |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
return $query->execute()->getFirst(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Document|string $document |
|
48
|
|
|
* @param int|null $feUserUid |
|
49
|
|
|
* @return bool |
|
50
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function removeBookmark($document, $feUserUid) |
|
53
|
|
|
{ |
|
54
|
|
|
$query = $this->createQuery(); |
|
55
|
|
|
|
|
56
|
|
|
if ($document instanceof Document) { |
|
57
|
|
|
// A document can be identified (documentIdentifier) by its Fedora PID or the document UID in case it hasn't been |
|
58
|
|
|
// published (that means it exits only locally in the TYPO3 db). |
|
59
|
|
|
// In order to find a bookmark that belongs to a document, it is essential to search for both identifiers. |
|
60
|
|
|
$constraintsAnd[] = $query->logicalOr( |
|
|
|
|
|
|
61
|
|
|
$query->equals('document_identifier', $document->getObjectIdentifier()), |
|
62
|
|
|
$query->equals('document_identifier', $document->getUid()) |
|
|
|
|
|
|
63
|
|
|
); |
|
64
|
|
|
} else { |
|
65
|
|
|
// In case $document already contains a plain identifier the above distinction is not necessary. |
|
66
|
|
|
$constraintsAnd[] = $query->equals('document_identifier', $document); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($feUserUid) { |
|
|
|
|
|
|
70
|
|
|
$constraintsAnd[] = $query->equals('fe_user_uid', $feUserUid); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$query->matching($query->logicalAnd($constraintsAnd)); |
|
74
|
|
|
|
|
75
|
|
|
$queryResult = $query->execute(); |
|
76
|
|
|
|
|
77
|
|
|
/** @var Bookmark @$bookmark */ |
|
78
|
|
|
foreach ($queryResult as $bookmark) { |
|
79
|
|
|
$this->remove($bookmark); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $queryResult->count() > 0; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Document|string $document |
|
87
|
|
|
* @param int $feUserUid |
|
88
|
|
|
* @return bool |
|
89
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
90
|
|
|
*/ |
|
91
|
|
|
public function addBookmark($document, $feUserUid) |
|
92
|
|
|
{ |
|
93
|
|
|
if ($document instanceof Document) { |
|
94
|
|
|
// The returned documentIdentifier is either a PID or the document UID (TYPO3 db), see also |
|
95
|
|
|
// the above method removeBookmark(). |
|
96
|
|
|
$identifier = $document->getDocumentIdentifier(); |
|
97
|
|
|
} else { |
|
98
|
|
|
// In case $document already contains a plain identifier we can use it directly. |
|
99
|
|
|
$identifier = $document; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$bookmark = $this->findBookmark($feUserUid, $identifier); |
|
103
|
|
|
if (!$bookmark) { |
|
|
|
|
|
|
104
|
|
|
$bookmark = new Bookmark(); |
|
105
|
|
|
$bookmark->setDocumentIdentifier($identifier); |
|
106
|
|
|
$bookmark->setFeUserUid($feUserUid); |
|
107
|
|
|
$this->add($bookmark); |
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param Document $document |
|
116
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
117
|
|
|
*/ |
|
118
|
|
|
public function findDocumentBookmarks(Document $document) |
|
119
|
|
|
{ |
|
120
|
|
|
$query = $this->createQuery(); |
|
121
|
|
|
|
|
122
|
|
|
$constraintsAnd[] = $query->logicalOr( |
|
|
|
|
|
|
123
|
|
|
$query->equals('document_identifier', $document->getObjectIdentifier()), |
|
124
|
|
|
$query->equals('document_identifier', $document->getUid()) |
|
|
|
|
|
|
125
|
|
|
); |
|
126
|
|
|
|
|
127
|
|
|
$query->matching($query->logicalAnd($constraintsAnd)); |
|
128
|
|
|
return $query->execute(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.