<?php
namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
/**
* @method User|null find($id, $lockMode = null, $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
*/
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
}
$user->setPassword($newHashedPassword);
$this->_em->persist($user);
$this->_em->flush();
}
public function findUserFirmenmitglieder($firmenprofilId, $sortNach1, $sortNach2, $sort)
{
$queryBuilder = $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.firmen_profil = :firmenprofil')
->addOrderBy('up.' . $sortNach1, $sort)
->addOrderBy('up.' . $sortNach2, 'ASC');
$queryBuilder->setParameter('firmenprofil', $firmenprofilId);
return $queryBuilder->getQuery()->getResult();
}
public function findUserMitBestimmterROLE(string $role)
{
return $this->createQueryBuilder('u')
->andWhere('u.roles LIKE :role')
->setParameter('role', '%"' . $role . '"%')
->getQuery()
->getResult();
}
public function findUserAusserCelseo()
{
return $this->createQueryBuilder('u')
->andWhere('u.id > 100')
->getQuery()
->getResult();
}
public function findMoeglicheNeueCelseoMasterAccounts()
{
return $this->createQueryBuilder('u')
->andWhere('u.id < 100')
->andWhere('u.firmen_profil IS NULL')
->getQuery()
->getResult();
}
public function findUserMitFirmenverbindung()
{
$queryBuilder = $this->createQueryBuilder('u')
->andWhere('u.firmen_profil IS NOT NULL');
return $queryBuilder->getQuery()->getResult();
}
public function findAdminsMitNewsletterFreigabe(string $role)
{
return $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.firmen_profil = 1')
->andWhere('u.roles LIKE :role')
->setParameter('role', '%"' . $role . '"%')
->andWhere('up.newsletter = 1')
->getQuery()
->getResult();
}
public function findUserMitBuchungsrechteMitNewsletterFreigabe(string $role)
{
return $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.firmen_profil > 2')
->andWhere('u.id > 100')
->andWhere('u.roles LIKE :role')
->setParameter('role', '%"' . $role . '"%')
->andWhere('up.newsletter = 1')
->getQuery()
->getResult();
}
public function findUserMitFirmenverbindungOhneProvisorischMitNewsletterFreigabe()
{
$queryBuilder = $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.firmen_profil IS NOT NULL')
->andWhere('u.firmen_profil > 2')
->andWhere('u.freigeschaltet = 1')
->andWhere('u.angelegt_am <> u.letzter_login')
->andWhere('u.id > 100')
->andWhere('u.provisorischer_mitarbeiter IS NULL')
->andWhere('up.newsletter = 1');
return $queryBuilder->getQuery()->getResult();
}
public function findAlleFreigeschalteteUserOhneProvisorischMitNewsletterFreigabe()
{
$queryBuilder = $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.freigeschaltet = 1')
->andWhere('u.angelegt_am <> u.letzter_login');
$orStatements = $queryBuilder->expr()->orX(
$queryBuilder->expr()->isNull('u.firmen_profil'),
$queryBuilder->expr()->gte('u.firmen_profil', 2)
);
$queryBuilder->andWhere($orStatements);
$queryBuilder->andWhere('u.id > 100')
->andWhere('u.provisorischer_mitarbeiter IS NULL')
->andWhere('up.newsletter = 1');
return $queryBuilder->getQuery()->getResult();
}
public function findUserOnline($datumVergangenheit)
{
$queryBuilder = $this->createQueryBuilder('u')
->andWhere('u.letzter_login > :now')
->setParameter('now', $datumVergangenheit);
return $queryBuilder->getQuery()->getResult();
}
public function findFirmenmitgliederOhneProvisorisch($firmaId, $sortierung)
{
$queryBuilder = $this->createQueryBuilder('u')
->innerJoin('u.user_profil', 'up')
->andWhere('u.provisorischer_mitarbeiter IS NULL')
->andWhere('u.firmen_profil = :firmaId')
->setParameter('firmaId', $firmaId)
->orderBy('up.' . $sortierung, 'ASC');
return $queryBuilder->getQuery()->getResult();
}
}