mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
PHRAS-3277 validation reminder in percent
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user