TYPO3 CMS  TYPO3_8-7
BackendUserRepository.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 
26 
31 {
38  public function findByUidList(array $uidList)
39  {
40  $query = $this->createQuery();
41  $query->matching($query->in('uid', array_map('intval', $uidList)));
43  $result = $query->execute();
44  return $result;
45  }
46 
53  public function findDemanded(Demand $demand)
54  {
55  $constraints = [];
56  $query = $this->createQuery();
57  // Find invisible as well, but not deleted
58  $constraints[] = $query->equals('deleted', 0);
59  $query->setOrderings(['userName' => QueryInterface::ORDER_ASCENDING]);
60  // Username
61  if ($demand->getUserName() !== '') {
62  $searchConstraints = [];
63  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
64  foreach (['userName', 'uid', 'realName'] as $field) {
65  $searchConstraints[] = $query->like(
66  $field,
67  '%' . $queryBuilder->escapeLikeWildcards($demand->getUserName()) . '%'
68  );
69  }
70  $constraints[] = $query->logicalOr($searchConstraints);
71  }
72  // Only display admin users
73  if ($demand->getUserType() == Demand::USERTYPE_ADMINONLY) {
74  $constraints[] = $query->equals('admin', 1);
75  }
76  // Only display non-admin users
77  if ($demand->getUserType() == Demand::USERTYPE_USERONLY) {
78  $constraints[] = $query->equals('admin', 0);
79  }
80  // Only display active users
81  if ($demand->getStatus() == Demand::STATUS_ACTIVE) {
82  $constraints[] = $query->equals('disable', 0);
83  }
84  // Only display in-active users
85  if ($demand->getStatus() == Demand::STATUS_INACTIVE) {
86  $constraints[] = $query->logicalOr($query->equals('disable', 1));
87  }
88  // Not logged in before
89  if ($demand->getLogins() == Demand::LOGIN_NONE) {
90  $constraints[] = $query->equals('lastlogin', 0);
91  }
92  // At least one login
93  if ($demand->getLogins() == Demand::LOGIN_SOME) {
94  $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
95  }
96  // In backend user group
97  // @TODO: Refactor for real n:m relations
98  if ($demand->getBackendUserGroup()) {
99  $constraints[] = $query->logicalOr([
100  $query->equals('usergroup', (int)$demand->getBackendUserGroup()),
101  $query->like('usergroup', (int)$demand->getBackendUserGroup() . ',%'),
102  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()),
103  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup() . ',%')
104  ]);
105  }
106  $query->matching($query->logicalAnd($constraints));
108  $result = $query->execute();
109  return $result;
110  }
111 
117  public function findOnline()
118  {
119  $uids = [];
120  foreach ($this->getSessionBackend()->getAll() as $sessionRecord) {
121  if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) {
122  $uids[] = $sessionRecord['ses_userid'];
123  }
124  }
125 
126  $query = $this->createQuery();
127  $query->matching($query->in('uid', $uids));
129  $result = $query->execute();
130  return $result;
131  }
132 
138  public function createQuery()
139  {
140  $query = parent::createQuery();
141  $query->getQuerySettings()->setIgnoreEnableFields(true);
142  $query->getQuerySettings()->setIncludeDeleted(true);
143  return $query;
144  }
145 
149  protected function getSessionBackend()
150  {
151  $loginType = $this->getBackendUserAuthentication()->getLoginType();
152  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend($loginType);
153  }
154 
158  protected function getBackendUserAuthentication()
159  {
160  return $GLOBALS['BE_USER'];
161  }
162 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']