public function getBuilderForStarredByUser($userId)
{
return $this
- ->getBuilderByUser($userId)
+ ->getBuilderByUser($userId, 'starredAt', 'desc')
->andWhere('e.isStarred = true')
;
}
* Get id and url from all entries
* Used for the clean-duplicates command.
*/
- public function getAllEntriesIdAndUrl($userId)
+ public function findAllEntriesIdAndUrlByUserId($userId)
{
$qb = $this->createQueryBuilder('e')
->select('e.id, e.url')
return $qb->getQuery()->getArrayResult();
}
+ /**
+ * @param int $userId
+ *
+ * @return array
+ */
+ public function findAllEntriesIdByUserId($userId = null)
+ {
+ $qb = $this->createQueryBuilder('e')
+ ->select('e.id');
+
+ if (null !== $userId) {
+ $qb->where('e.user = :userid')->setParameter(':userid', $userId);
+ }
+
+ return $qb->getQuery()->getArrayResult();
+ }
+
/**
* Find all entries by url and owner.
*
/**
* Return a query builder to used by other getBuilderFor* method.
*
- * @param int $userId
+ * @param int $userId
+ * @param string $sortBy
+ * @param string $direction
*
* @return QueryBuilder
*/
- private function getBuilderByUser($userId)
+ private function getBuilderByUser($userId, $sortBy = 'createdAt', $direction = 'desc')
{
return $this->createQueryBuilder('e')
->andWhere('e.user = :userId')->setParameter('userId', $userId)
- ->orderBy('e.createdAt', 'desc')
- ;
+ ->orderBy(sprintf('e.%s', $sortBy), $direction);
}
}