‪TYPO3CMS  ‪main
BackendUserRepository.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
28 
35 {
39  public function ‪findByUidList(array $uidList): ‪QueryResult
40  {
41  $query = $this->‪createQuery();
42  $query->matching($query->in('uid', array_map(intval(...), $uidList)));
44  $result = $query->execute();
45  return $result;
46  }
47 
51  public function ‪findDemanded(‪Demand $demand): ‪QueryResult
52  {
53  $constraints = [];
54  $query = $this->‪createQuery();
55  $query->setOrderings(['userName' => ‪QueryInterface::ORDER_ASCENDING]);
56  // Username
57  if ($demand->‪getUserName() !== '') {
58  $searchConstraints = [];
59  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
60  foreach (['userName', 'realName'] as $field) {
61  $searchConstraints[] = $query->like(
62  $field,
63  '%' . $queryBuilder->escapeLikeWildcards($demand->‪getUserName()) . '%'
64  );
65  }
67  $searchConstraints[] = $query->equals('uid', (int)$demand->‪getUserName());
68  }
69  if (‪count($searchConstraints) === 1) {
70  $constraints[] = reset($searchConstraints);
71  } elseif (‪count($searchConstraints) >= 2) {
72  $constraints[] = $query->logicalOr(...$searchConstraints);
73  }
74  }
75  // Only display admin users
76  if ($demand->‪getUserType() === ‪Demand::USERTYPE_ADMINONLY) {
77  $constraints[] = $query->equals('admin', 1);
78  }
79  // Only display non-admin users
80  if ($demand->‪getUserType() === ‪Demand::USERTYPE_USERONLY) {
81  $constraints[] = $query->equals('admin', 0);
82  }
83  // Only display active users
84  if ($demand->‪getStatus() === ‪Demand::STATUS_ACTIVE) {
85  $constraints[] = $query->equals('disable', 0);
86  }
87  // Only display in-active users
88  if ($demand->‪getStatus() === ‪Demand::STATUS_INACTIVE) {
89  $constraints[] = $query->equals('disable', 1);
90  }
91  // Not logged in before
92  if ($demand->‪getLogins() === ‪Demand::LOGIN_NONE) {
93  $constraints[] = $query->equals('lastlogin', 0);
94  }
95  // At least one login
96  if ($demand->‪getLogins() === ‪Demand::LOGIN_SOME) {
97  $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
98  }
99  // In backend user group
100  if ($demand->‪getBackendUserGroup()) {
101  $constraints[] = $query->logicalOr(
102  $query->equals('usergroup', $demand->‪getBackendUserGroup()),
103  $query->like('usergroup', $demand->‪getBackendUserGroup() . ',%'),
104  $query->like('usergroup', '%,' . $demand->‪getBackendUserGroup()),
105  $query->like('usergroup', '%,' . $demand->‪getBackendUserGroup() . ',%'),
106  );
107  }
108  $query->matching($query->logicalAnd(...$constraints));
109 
111  $result = $query->execute();
112  return $result;
113  }
114 
118  public function ‪findOnline(): ‪QueryResult
119  {
120  $uids = [];
121  foreach ($this->‪getSessionBackend()->getAll() as $sessionRecord) {
122  if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) {
123  $uids[] = $sessionRecord['ses_userid'];
124  }
125  }
126 
127  $query = $this->‪createQuery();
128  $query->matching($query->in('uid', $uids));
130  $result = $query->execute();
131  return $result;
132  }
133 
138  {
139  $query = parent::createQuery();
140  $query->getQuerySettings()->setIgnoreEnableFields(true);
141  return $query;
142  }
143 
145  {
146  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
147  }
148 }
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:30
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getUserName
‪getUserName()
Definition: Demand.php:70
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findDemanded
‪findDemanded(Demand $demand)
Definition: BackendUserRepository.php:51
‪TYPO3\CMS\Beuser\Domain\Model\Demand\USERTYPE_ADMINONLY
‪const USERTYPE_ADMINONLY
Definition: Demand.php:28
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getLogins
‪getLogins()
Definition: Demand.php:100
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:41
‪TYPO3\CMS\Extbase\Persistence\Repository\count
‪count(array $criteria)
Definition: Repository.php:315
‪TYPO3\CMS\Beuser\Domain\Model\Demand\LOGIN_NONE
‪const LOGIN_NONE
Definition: Demand.php:35
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getStatus
‪getStatus()
Definition: Demand.php:90
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:99
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:16
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getBackendUserGroup
‪getBackendUserGroup()
Definition: Demand.php:110
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:30
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository
Definition: BackendUserRepository.php:35
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\createQuery
‪createQuery()
Definition: BackendUserRepository.php:137
‪TYPO3\CMS\Beuser\Domain\Model\Demand\LOGIN_SOME
‪const LOGIN_SOME
Definition: Demand.php:34
‪TYPO3\CMS\Beuser\Domain\Model\Demand\STATUS_INACTIVE
‪const STATUS_INACTIVE
Definition: Demand.php:32
‪TYPO3\CMS\Beuser\Domain\Model\Demand
Definition: Demand.php:25
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryResult
Definition: QueryResult.php:32
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findByUidList
‪findByUidList(array $uidList)
Definition: BackendUserRepository.php:39
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getUserType
‪getUserType()
Definition: Demand.php:80
‪TYPO3\CMS\Beuser\Domain\Model\Demand\USERTYPE_USERONLY
‪const USERTYPE_USERONLY
Definition: Demand.php:29
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\getSessionBackend
‪getSessionBackend()
Definition: BackendUserRepository.php:144
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:32
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Beuser\Domain\Model\Demand\STATUS_ACTIVE
‪const STATUS_ACTIVE
Definition: Demand.php:31
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findOnline
‪findOnline()
Definition: BackendUserRepository.php:118