TYPO3  7.6
beuser/Classes/Domain/Repository/BackendUserRepository.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Beuser\Domain\Repository;
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 = array();
43  $query = $this->createQuery();
44  // Find invisible as well, but not deleted
45  $constraints[] = $query->equals('deleted', 0);
46  $query->setOrderings(array('userName' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
47  // Username
48  if ($demand->getUserName() !== '') {
49  $constraints[] = $query->like(
50  'userName',
51  '%' . $GLOBALS['TYPO3_DB']->escapeStrForLike($demand->getUserName(), 'be_users') . '%'
52  );
53  }
54  // Only display admin users
55  if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_ADMINONLY) {
56  $constraints[] = $query->equals('admin', 1);
57  }
58  // Only display non-admin users
59  if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_USERONLY) {
60  $constraints[] = $query->equals('admin', 0);
61  }
62  // Only display active users
63  if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_ACTIVE) {
64  $constraints[] = $query->equals('disable', 0);
65  }
66  // Only display in-active users
67  if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_INACTIVE) {
68  $constraints[] = $query->logicalOr($query->equals('disable', 1));
69  }
70  // Not logged in before
71  if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_NONE) {
72  $constraints[] = $query->equals('lastlogin', 0);
73  }
74  // At least one login
75  if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_SOME) {
76  $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
77  }
78  // In backend user group
79  // @TODO: Refactor for real n:m relations
80  if ($demand->getBackendUserGroup()) {
81  $constraints[] = $query->logicalOr(
82  $query->equals('usergroup', (int)$demand->getBackendUserGroup()->getUid()),
83  $query->like('usergroup', (int)$demand->getBackendUserGroup()->getUid() . ',%'),
84  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()->getUid()),
85  $query->like('usergroup', '%,' . (int)$demand->getBackendUserGroup()->getUid() . ',%')
86  );
87  $query->contains('usergroup', $demand->getBackendUserGroup());
88  }
89  $query->matching($query->logicalAnd($constraints));
90  return $query->execute();
91  }
92 
98  public function findOnline()
99  {
100  $uids = array();
101  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('DISTINCT ses_userid', 'be_sessions', '');
102  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
103  $uids[] = $row['ses_userid'];
104  }
105  $GLOBALS['TYPO3_DB']->sql_free_result($res);
106  $query = $this->createQuery();
107  $query->matching($query->in('uid', $uids));
108  return $query->execute();
109  }
110 
116  public function createQuery()
117  {
118  $query = parent::createQuery();
119  $query->getQuerySettings()->setIgnoreEnableFields(true);
120  $query->getQuerySettings()->setIncludeDeleted(true);
121  return $query;
122  }
123 }