TYPO3 CMS  TYPO3_7-6
LogEntryRepository.php
Go to the documentation of this file.
1 <?php
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 
21 {
27  protected $beUserList = [];
28 
34  public function initializeObject()
35  {
38  $defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
39  $defaultQuerySettings->setRespectStoragePage(false);
41  }
42 
49  public function findByConstraint(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
50  {
51  $query = $this->createQuery();
52  $queryConstraints = $this->createQueryConstraints($query, $constraint);
53  if (!empty($queryConstraints)) {
54  $query->matching($query->logicalAnd($queryConstraints));
55  }
56  $query->setOrderings(['uid' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING]);
57  $query->setLimit($constraint->getNumber());
58  return $query->execute();
59  }
60 
68  protected function createQueryConstraints(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
69  {
70  $queryConstraints = [];
71  // User / group handling
72  $this->addUsersAndGroupsToQueryConstraints($constraint, $query, $queryConstraints);
73  // Workspace
74  if ($constraint->getWorkspaceUid() != \TYPO3\CMS\Belog\Domain\Model\Workspace::UID_ANY_WORKSPACE) {
75  $queryConstraints[] = $query->equals('workspace', $constraint->getWorkspaceUid());
76  }
77  // Action (type):
78  if ($constraint->getAction() > 0) {
79  $queryConstraints[] = $query->equals('type', $constraint->getAction());
80  } elseif ($constraint->getAction() == -1) {
81  $queryConstraints[] = $query->in('error', [-1, 1, 2, 3]);
82  }
83  // Start / endtime handling: The timestamp calculation was already done
84  // in the controller, since we need those calculated values in the view as well.
85  $queryConstraints[] = $query->greaterThanOrEqual('tstamp', $constraint->getStartTimestamp());
86  $queryConstraints[] = $query->lessThan('tstamp', $constraint->getEndTimestamp());
87  // Page and level constraint if in page context
88  $this->addPageTreeConstraintsToQuery($constraint, $query, $queryConstraints);
89  return $queryConstraints;
90  }
91 
101  protected function addPageTreeConstraintsToQuery(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$queryConstraints)
102  {
103  if (!$constraint->getIsInPageContext()) {
104  return;
105  }
106  $pageIds = [];
107  // Check if we should get a whole tree of pages and not only a single page
108  if ($constraint->getDepth() > 0) {
110  $pageTree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageTreeView::class);
111  $pageTree->init('AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
112  $pageTree->makeHTML = 0;
113  $pageTree->fieldArray = ['uid'];
114  $pageTree->getTree($constraint->getPageId(), $constraint->getDepth());
115  $pageIds = $pageTree->ids;
116  }
117  $pageIds[] = $constraint->getPageId();
118  $queryConstraints[] = $query->in('eventPid', $pageIds);
119  }
120 
129  protected function addUsersAndGroupsToQueryConstraints(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$queryConstraints)
130  {
131  $userOrGroup = $constraint->getUserOrGroup();
132  if ($userOrGroup === '') {
133  return;
134  }
135  // Constraint for a group
136  if (substr($userOrGroup, 0, 3) === 'gr-') {
137  $groupId = (int)substr($userOrGroup, 3);
138  $userIds = [];
139  foreach ($this->beUserList as $userId => $userData) {
140  if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($userData['usergroup_cached_list'], $groupId)) {
141  $userIds[] = $userId;
142  }
143  }
144  if (!empty($userIds)) {
145  $queryConstraints[] = $query->in('userid', $userIds);
146  } else {
147  // If there are no group members -> use -1 as constraint to not find anything
148  $queryConstraints[] = $query->in('userid', [-1]);
149  }
150  } elseif (substr($userOrGroup, 0, 3) === 'us-') {
151  $queryConstraints[] = $query->equals('userid', (int)substr($userOrGroup, 3));
152  } elseif ($userOrGroup === '-1') {
153  $queryConstraints[] = $query->equals('userid', (int)$GLOBALS['BE_USER']->user['uid']);
154  }
155  }
156 }
createQueryConstraints(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
Definition: Repository.php:203
static getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
findByConstraint(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
$beUserList
addUsersAndGroupsToQueryConstraints(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$queryConstraints)