TYPO3 CMS  TYPO3_7-6
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 
21 {
28  public function findByUidList(array $uidList)
29  {
30  $query = $this->createQuery();
31  return $query->matching($query->in('uid', $GLOBALS['TYPO3_DB']->cleanIntArray($uidList)))->execute();
32  }
33 
40  public function findDemanded(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)
41  {
42  $constraints = [];
43  $query = $this->createQuery();
44  // Find invisible as well, but not deleted
45  $constraints[] = $query->equals('deleted', 0);
46  $query->setOrderings(['userName' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING]);
47  // Username
48  if ($demand->getUserName() !== '') {
49  $searchConstraints = [];
50  foreach (['userName', 'uid', 'realName'] as $field) {
51  $searchConstraints[] = $query->like(
52  $field, '%' . $GLOBALS['TYPO3_DB']->escapeStrForLike($demand->getUserName(), 'be_users') . '%'
53  );
54  }
55  $constraints[] = $query->logicalOr($searchConstraints);
56  }
57  // Only display admin users
58  if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_ADMINONLY) {
59  $constraints[] = $query->equals('admin', 1);
60  }
61  // Only display non-admin users
62  if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_USERONLY) {
63  $constraints[] = $query->equals('admin', 0);
64  }
65  // Only display active users
66  if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_ACTIVE) {
67  $constraints[] = $query->equals('disable', 0);
68  }
69  // Only display in-active users
70  if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_INACTIVE) {
71  $constraints[] = $query->logicalOr($query->equals('disable', 1));
72  }
73  // Not logged in before
74  if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_NONE) {
75  $constraints[] = $query->equals('lastlogin', 0);
76  }
77  // At least one login
78  if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_SOME) {
79  $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
80  }
81  // In backend user group
82  // @TODO: Refactor for real n:m relations
83  if ($demand->getBackendUserGroup()) {
84  $constraints[] = $query->logicalOr(
85  $query->equals('usergroup', (int)$demand->getBackendUserGroup()->getUid()),
86  $query->like('usergroup', (int)$demand->getBackendUserGroup()->getUid() . ',%'),
87  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()->getUid()),
88  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()->getUid() . ',%')
89  );
90  $query->contains('usergroup', $demand->getBackendUserGroup());
91  }
92  $query->matching($query->logicalAnd($constraints));
93  return $query->execute();
94  }
95 
101  public function findOnline()
102  {
103  $uids = [];
104  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('DISTINCT ses_userid', 'be_sessions', '');
105  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
106  $uids[] = $row['ses_userid'];
107  }
108  $GLOBALS['TYPO3_DB']->sql_free_result($res);
109  $query = $this->createQuery();
110  $query->matching($query->in('uid', $uids));
111  return $query->execute();
112  }
113 
119  public function createQuery()
120  {
121  $query = parent::createQuery();
122  $query->getQuerySettings()->setIgnoreEnableFields(true);
123  $query->getQuerySettings()->setIncludeDeleted(true);
124  return $query;
125  }
126 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
findDemanded(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)