public function directoryAction(Request $request)
    {
        $id = $request->query->get('id');

        $parent = null;
        if (intval($id)) {
            $em = $this->getDoctrine()->getManager();

            $parent = $em->getReference('ClasticMediaBundle:Directory', $id);
        }

        $directories = $this->getDoctrine()->getRepository('ClasticMediaBundle:Directory')
            ->findBy(array(
                'parent' => $parent,
            ));

        $data = array_map(function (Directory $directory) use ($parent) {
            return array(
                'id' => $directory->getId(),
                'text' => $directory->getName(),
                'children' => true,
                'state' => array(
                    'disabled' => false,
                    'opened' => !$parent,
                    'selected' => !$parent,
                ),
            );
        }, $directories);

        return new JsonResponse($data);
    }