‪TYPO3CMS  10.4
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 
34 {
41  public function ‪findByUidList(array $uidList)
42  {
43  $query = $this->‪createQuery();
44  $query->matching($query->in('uid', array_map('intval', $uidList)));
46  $result = $query->execute();
47  return $result;
48  }
49 
56  public function ‪findDemanded(‪Demand $demand)
57  {
58  $constraints = [];
59  $query = $this->‪createQuery();
60  $query->setOrderings(['userName' => ‪QueryInterface::ORDER_ASCENDING]);
61  // Username
62  if ($demand->‪getUserName() !== '') {
63  $searchConstraints = [];
64  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
65  foreach (['userName', 'realName'] as $field) {
66  $searchConstraints[] = $query->like(
67  $field,
68  '%' . $queryBuilder->escapeLikeWildcards($demand->‪getUserName()) . '%'
69  );
70  }
72  $searchConstraints[] = $query->equals('uid', (int)$demand->‪getUserName());
73  }
74  $constraints[] = $query->logicalOr($searchConstraints);
75  }
76  // Only display admin users
78  $constraints[] = $query->equals('admin', 1);
79  }
80  // Only display non-admin users
81  if ($demand->‪getUserType() == ‪Demand::USERTYPE_USERONLY) {
82  $constraints[] = $query->equals('admin', 0);
83  }
84  // Only display active users
85  if ($demand->‪getStatus() == ‪Demand::STATUS_ACTIVE) {
86  $constraints[] = $query->equals('disable', 0);
87  }
88  // Only display in-active users
89  if ($demand->‪getStatus() == ‪Demand::STATUS_INACTIVE) {
90  $constraints[] = $query->logicalOr($query->equals('disable', 1));
91  }
92  // Not logged in before
93  if ($demand->‪getLogins() == ‪Demand::LOGIN_NONE) {
94  $constraints[] = $query->equals('lastlogin', 0);
95  }
96  // At least one login
97  if ($demand->‪getLogins() == ‪Demand::LOGIN_SOME) {
98  $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
99  }
100  // In backend user group
101  // @TODO: Refactor for real n:m relations
102  if ($demand->‪getBackendUserGroup()) {
103  $constraints[] = $query->logicalOr([
104  $query->equals('usergroup', (int)$demand->‪getBackendUserGroup()),
105  $query->like('usergroup', (int)$demand->‪getBackendUserGroup() . ',%'),
106  $query->like('usergroup', '%,' . (int)$demand->‪getBackendUserGroup()),
107  $query->like('usergroup', '%,' . (int)$demand->‪getBackendUserGroup() . ',%')
108  ]);
109  }
110  if ($constraints !== []) {
111  $query->matching($query->logicalAnd($constraints));
112  }
114  $result = $query->execute();
115  return $result;
116  }
117 
123  public function ‪findOnline()
124  {
125  $uids = [];
126  foreach ($this->‪getSessionBackend()->getAll() as $sessionRecord) {
127  if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) {
128  $uids[] = $sessionRecord['ses_userid'];
129  }
130  }
131 
132  $query = $this->‪createQuery();
133  $query->matching($query->in('uid', $uids));
135  $result = $query->execute();
136  return $result;
137  }
138 
144  public function ‪createQuery()
145  {
146  $query = parent::createQuery();
147  $query->getQuerySettings()->setIgnoreEnableFields(true);
148  return $query;
149  }
150 
154  protected function ‪getSessionBackend()
155  {
156  $loginType = $this->‪getBackendUserAuthentication()->‪getLoginType();
157  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend($loginType);
158  }
159 
163  protected function ‪getBackendUserAuthentication()
164  {
165  return ‪$GLOBALS['BE_USER'];
166  }
167 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository
Definition: BackendUserGroupRepository.php:27
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:29
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\getSessionBackend
‪SessionBackendInterface getSessionBackend()
Definition: BackendUserRepository.php:154
‪TYPO3\CMS\Beuser\Domain\Model\Demand\USERTYPE_ADMINONLY
‪const USERTYPE_ADMINONLY
Definition: Demand.php:33
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: BackendUserRepository.php:163
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findDemanded
‪TYPO3 CMS Extbase Persistence Generic QueryResult findDemanded(Demand $demand)
Definition: BackendUserRepository.php:56
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\createQuery
‪QueryInterface createQuery()
Definition: BackendUserRepository.php:144
‪TYPO3\CMS\Beuser\Domain\Model\Demand\LOGIN_NONE
‪const LOGIN_NONE
Definition: Demand.php:53
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:98
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:16
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getUserType
‪int getUserType()
Definition: Demand.php:101
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository
Definition: BackendUserRepository.php:34
‪TYPO3\CMS\Beuser\Domain\Model\Demand\LOGIN_SOME
‪const LOGIN_SOME
Definition: Demand.php:49
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\getLoginType
‪string getLoginType()
Definition: AbstractUserAuthentication.php:1492
‪TYPO3\CMS\Beuser\Domain\Model\Demand\STATUS_INACTIVE
‪const STATUS_INACTIVE
Definition: Demand.php:45
‪TYPO3\CMS\Beuser\Domain\Model\Demand
Definition: Demand.php:25
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryResult
Definition: QueryResult.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Beuser\Domain\Model\Demand\USERTYPE_USERONLY
‪const USERTYPE_USERONLY
Definition: Demand.php:37
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
Definition: BackendUserGroupRepository.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Beuser\Domain\Model\Demand\STATUS_ACTIVE
‪const STATUS_ACTIVE
Definition: Demand.php:41
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getBackendUserGroup
‪int getBackendUserGroup()
Definition: Demand.php:149
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findByUidList
‪TYPO3 CMS Extbase Persistence Generic QueryResult findByUidList(array $uidList)
Definition: BackendUserRepository.php:41
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository\findOnline
‪TYPO3 CMS Extbase Persistence Generic QueryResult findOnline()
Definition: BackendUserRepository.php:123
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getStatus
‪int getStatus()
Definition: Demand.php:117
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getUserName
‪string getUserName()
Definition: Demand.php:85
‪TYPO3\CMS\Beuser\Domain\Model\Demand\getLogins
‪int getLogins()
Definition: Demand.php:133