PHRAS-3277 validation reminder in percent

This commit is contained in:
aina esokia
2020-12-02 17:31:05 +03:00
parent 4b80d5c589
commit 427216ec43
17 changed files with 427 additions and 395 deletions

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Model\Entities\ValidationParticipant;
use DateTime;
use Doctrine\ORM\EntityRepository;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
class ValidationParticipantRepository extends EntityRepository
{
@@ -22,24 +23,31 @@ class ValidationParticipantRepository extends EntityRepository
/**
* Retrieve all not reminded participants where the validation has not expired
*
* @param $expireDate DateTime The expiration Date
* @param $timeLeftPercent float Percent of the time left before the validation expires.
* @param $today DateTime fake "today" to allow to get past/future events
* (used by SendValidationRemindersCommand.php to debug with --dry)
* @return ValidationParticipant[]
*/
public function findNotConfirmedAndNotRemindedParticipantsByExpireDate(DateTime $expireDate, DateTime $today=null)
public function findNotConfirmedAndNotRemindedParticipantsByTimeLeftPercent($timeLeftPercent, DateTime $today=null)
{
$dql = '
SELECT p, s
FROM Phraseanet:ValidationParticipant p
JOIN p.session s
JOIN s.basket b
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\ValidationParticipant', 'p');
$selectClause = $rsm->generateSelectClause();
$sql = '
SELECT ' . $selectClause . '
FROM ValidationParticipants p
INNER JOIN ValidationSessions s on p.validation_session_id = s.id
INNER JOIN Baskets b on b.id = s.basket_id
WHERE p.is_confirmed = 0
AND p.reminded IS NULL
AND s.expires < :date AND s.expires > ' . ($today===null ? 'CURRENT_TIMESTAMP()' : ':today');
AND s.expires > '. ($today===null ? 'CURRENT_TIMESTAMP()' : ':today') . '
AND DATE_SUB(s.expires, INTERVAL FLOOR((TO_SECONDS(s.expires) - TO_SECONDS(s.created)) * :percent) SECOND) <= '. ($today===null ? 'CURRENT_TIMESTAMP()' : ':today')
;
$q = $this->_em->createNativeQuery($sql, $rsm);
$q->setParameter('percent', (float)($timeLeftPercent/100));
$q = $this->_em->createQuery($dql)
->setParameter('date', $expireDate, Type::DATETIME);
if($today !== null) {
$q->setParameter('today', $today, Type::DATETIME);
}