_em); $rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\BasketParticipant', 'p'); $selectClause = $rsm->generateSelectClause(); switch($this->_em->getConnection()->getDriver()->getName()) { case 'pdo_mysql': $sql = ' SELECT ' . $selectClause . ' FROM BasketParticipants p INNER JOIN Baskets b on b.id = p.basket_id WHERE p.is_confirmed = 0 AND p.reminded IS NULL AND b.vote_expires > '. ($today===null ? 'CURRENT_TIMESTAMP()' : ':today') . ' AND DATE_SUB(b.vote_expires, INTERVAL FLOOR((TO_SECONDS(b.vote_expires) - TO_SECONDS(b.vote_created)) * :percent) SECOND) <= '. ($today===null ? 'CURRENT_TIMESTAMP()' : ':today') ; break; case 'pdo_sqlite': $sql = ' SELECT ' . $selectClause . ' FROM BasketParticipants p INNER JOIN Baskets b on b.id = p.basket_id WHERE p.is_confirmed = 0 AND p.reminded IS NULL AND b.vote_expires > '. ($today===null ? 'strftime("%s","now")' : 'strftime("%s", :today)') . ' AND (strftime("%s", b.vote_expires) - ((strftime("%s", b.vote_expires) - strftime("%s", b.vote_created)) * :percent) )<= '. ($today===null ? 'strftime("%s","now")' : 'strftime("%s", :today)') ; break; default: throw new Exception('Unused PDO!, if necessary define the query for this PDO'); } $q = $this->_em->createNativeQuery($sql, $rsm); $q->setParameter('percent', (float)($timeLeftPercent/100)); if($today !== null) { $q->setParameter('today', $today, Type::DATETIME); } return $q->getResult(); } }