private function updateTrends()
{
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
// Reset trends
$q = $em->createQuery('UPDATE Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle bundle SET bundle.trend1 = 0');
$q->execute();
$query = <<<EOF
UPDATE bundle
JOIN (
SELECT date, bundle_id,
(
SELECT current.value - value AS diff
FROM score
WHERE bundle_id = current.bundle_id
AND date < current.date
ORDER BY date DESC
LIMIT 1
) AS diff
FROM score AS current
WHERE date = CURRENT_DATE
) score
ON score.bundle_id = bundle.id
AND score.diff > :minDiff
SET trend1 = score.diff
WHERE score >= :minThreshold
EOF;
$minDiff = $this->getContainer()->getParameter('knp_bundles.trending_bundle.min_score_diff');
$minThreshold = $this->getContainer()->getParameter('knp_bundles.trending_bundle.min_score_threshold');
$nbRows = $em->getConnection()->executeUpdate($query, array('minDiff' => $minDiff, 'minThreshold' => $minThreshold));
return $nbRows;
}