/**
  * Find Backend Users matching to Demand object properties
  *
  * @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
  * @return Tx_Extbase_Persistence_QueryResult<Tx_Beuser_Domain_Model_BackendUser>
  */
 public function findDemanded(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)
 {
     $constraints = array();
     $query = $this->createQuery();
     // Find invisible as well, but not deleted
     $constraints[] = $query->equals('deleted', 0);
     $query->setOrderings(array('userName' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
     // Username
     if ($demand->getUserName() !== '') {
         $constraints[] = $query->like('userName', '%' . $GLOBALS['TYPO3_DB']->escapeStrForLike($demand->getUserName(), 'be_users') . '%');
     }
     // Only display admin users
     if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_ADMINONLY) {
         $constraints[] = $query->equals('admin', 1);
     }
     // Only display non-admin users
     if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_USERONLY) {
         $constraints[] = $query->equals('admin', 0);
     }
     // Only display active users
     if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_ACTIVE) {
         $constraints[] = $query->equals('disable', 0);
     }
     // Only display in-active users
     if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_INACTIVE) {
         $constraints[] = $query->logicalOr($query->equals('disable', 1));
     }
     // Not logged in before
     if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_NONE) {
         $constraints[] = $query->equals('lastlogin', 0);
     }
     // At least one login
     if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_SOME) {
         $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
     }
     // In backend user group
     // @TODO: Refactor for real n:m relations
     if ($demand->getBackendUserGroup()) {
         $constraints[] = $query->logicalOr($query->equals('usergroup', intval($demand->getBackendUserGroup()->getUid())), $query->like('usergroup', intval($demand->getBackendUserGroup()->getUid()) . ',%'), $query->like('usergroup', '%,' . intval($demand->getBackendUserGroup()->getUid())), $query->like('usergroup', '%,' . intval($demand->getBackendUserGroup()->getUid()) . ',%'));
         $query->contains('usergroup', $demand->getBackendUserGroup());
     }
     $query->matching($query->logicalAnd($constraints));
     return $query->execute();
 }
示例#2
0
 /**
  * @test
  */
 public function setUserNameReturnExpectedValueForString()
 {
     $newUserName = '******';
     $this->subject->setUserName($newUserName);
     $this->assertSame($this->subject->getUserName(), $newUserName, 'UserName is not as set before.');
 }
示例#3
0
 /**
  * Find Backend Users matching to Demand object properties
  *
  * @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult<\TYPO3\CMS\Beuser\Domain\Model\BackendUser>
  */
 public function findDemanded(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand)
 {
     $constraints = [];
     $query = $this->createQuery();
     // Find invisible as well, but not deleted
     $constraints[] = $query->equals('deleted', 0);
     $query->setOrderings(['userName' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING]);
     // Username
     if ($demand->getUserName() !== '') {
         $searchConstraints = [];
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
         foreach (['userName', 'uid', 'realName'] as $field) {
             $searchConstraints[] = $query->like($field, '%' . $queryBuilder->escapeLikeWildcards($demand->getUserName()) . '%');
         }
         $constraints[] = $query->logicalOr($searchConstraints);
     }
     // Only display admin users
     if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_ADMINONLY) {
         $constraints[] = $query->equals('admin', 1);
     }
     // Only display non-admin users
     if ($demand->getUserType() == \TYPO3\CMS\Beuser\Domain\Model\Demand::USERTYPE_USERONLY) {
         $constraints[] = $query->equals('admin', 0);
     }
     // Only display active users
     if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_ACTIVE) {
         $constraints[] = $query->equals('disable', 0);
     }
     // Only display in-active users
     if ($demand->getStatus() == \TYPO3\CMS\Beuser\Domain\Model\Demand::STATUS_INACTIVE) {
         $constraints[] = $query->logicalOr($query->equals('disable', 1));
     }
     // Not logged in before
     if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_NONE) {
         $constraints[] = $query->equals('lastlogin', 0);
     }
     // At least one login
     if ($demand->getLogins() == \TYPO3\CMS\Beuser\Domain\Model\Demand::LOGIN_SOME) {
         $constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
     }
     // In backend user group
     // @TODO: Refactor for real n:m relations
     if ($demand->getBackendUserGroup()) {
         $constraints[] = $query->logicalOr($query->equals('usergroup', (int) $demand->getBackendUserGroup()->getUid()), $query->like('usergroup', (int) $demand->getBackendUserGroup()->getUid() . ',%'), $query->like('usergroup', '%,' . (int) $demand->getBackendUserGroup()->getUid()), $query->like('usergroup', '%,' . (int) $demand->getBackendUserGroup()->getUid() . ',%'));
         $query->contains('usergroup', $demand->getBackendUserGroup());
     }
     $query->matching($query->logicalAnd($constraints));
     return $query->execute();
 }