*/
public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'id';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
;
*/
public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'id';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isArchived = false')
*/
public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'archivedAt';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isArchived = true')
*/
public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'starredAt';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isStarred = true')
*/
private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
{
- return $qb->orderBy(sprintf('e.%s', $sortBy), $direction);
+ // in case one of these isn't defined, don't apply the orderBy
+ if (!$sortBy || !$direction) {
+ return $qb;
+ }
+
+ return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction));
}
}