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