public function listAction(Request $request)
    {
        $type = $request->request->get('tasks', 'involved');
        $sort = $request->request->get('sort', 'createdAt');
        $dir = $request->request->get('dir', 'DESC');
        $limit = $request->request->get('limit', 20);
        $start = $request->request->get('start', 0);

        $status = [];
        foreach ($request->request->all() as $key => $value) {
            if (substr($key, 0, 7) === 'status_') {
                $status[] = substr($key, 7);
            }
        }

        $taskManager = $this->get('phlexible_task.task_manager');

        if (!count($status)) {
            $status[] = current(array_keys($taskManager->getStates()));
        }

        $userId = $this->getUser()->getId();

        switch ($type) {
            case 'tasks':
                $tasks = $taskManager->findByCreatedByAndStatus($userId, $status, [$sort => $dir], $limit, $start);
                $total = $taskManager->countByCreatedByAndStatus($userId, $status);
                break;

            case 'todos':
                $tasks = $taskManager->findByAssignedToAndStatus($userId, $status, [$sort => $dir], $limit, $start);
                $total = $taskManager->countByAssignedToAndStatus($userId, $status);
                break;

            case 'involved':
                $tasks = $taskManager->findByInvolvementAndStatus($userId, $status, [$sort => $dir], $limit, $start);
                $total = $taskManager->countByInvolvementAndStatus($userId, $status);
                break;

            case 'all':
            default:
                $tasks = $taskManager->findByStatus($status, [$sort => $dir], $limit, $start);
                $total = $taskManager->countByStatus($status);
                break;
        }

        $data = [];
        foreach ($tasks as $task) {
            /* @var $task Task */
            $data[] = $this->serializeTask($task);
        }

        return new JsonResponse([
            'tasks' => $data,
            'total' => $total,
        ]);
    }