Returns a list-builder for media list.

@param Request $request
@param FieldDescriptorInterface[] $fieldDescriptors
@param array $types

@return DoctrineListBuilder
549136
private function getListBuilder(Request $request, array $fieldDescriptors, $types)
    {
        $restHelper = $this->get('sulu_core.doctrine_rest_helper');
        $factory = $this->get('sulu_core.doctrine_list_builder_factory');
        $listBuilder = $factory->create($this->getParameter('sulu.model.media.class'));
        $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

        // default sort by created
        if (!$request->get('sortBy')) {
            $listBuilder->sort($fieldDescriptors['created'], 'desc');
        }

        $collectionId = $request->get('collection');
        if ($collectionId) {
            $collectionType = $this->getCollectionRepository()->findCollectionTypeById($collectionId);
            if (SystemCollectionManagerInterface::COLLECTION_TYPE === $collectionType) {
                $this->getSecurityChecker()->checkPermission(
                    'sulu.media.system_collections',
                    PermissionTypes::VIEW
                );
            }
            $listBuilder->addSelectField($fieldDescriptors['collection']);
            $listBuilder->where($fieldDescriptors['collection'], $collectionId);
        } else {
            $listBuilder->addPermissionCheckField($fieldDescriptors['collection']);
            $listBuilder->setPermissionCheck(
                $this->getUser(),
                PermissionTypes::VIEW,
                $this->getParameter('sulu.model.collection.class')
            );
        }

        // set the types
        if (count($types)) {
            $listBuilder->in($fieldDescriptors['type'], $types);
        }

        if (!$this->getSecurityChecker()->hasPermission('sulu.media.system_collections', PermissionTypes::VIEW)) {
            $systemCollection = $this->getCollectionRepository()
                ->findCollectionByKey(SystemCollectionManagerInterface::COLLECTION_KEY);

            $lftExpression = $listBuilder->createWhereExpression(
                $fieldDescriptors['lft'],
                $systemCollection->getLft(),
                ListBuilderInterface::WHERE_COMPARATOR_LESS
            );
            $rgtExpression = $listBuilder->createWhereExpression(
                $fieldDescriptors['rgt'],
                $systemCollection->getRgt(),
                ListBuilderInterface::WHERE_COMPARATOR_GREATER
            );

            $listBuilder->addExpression(
                $listBuilder->createOrExpression([
                    $lftExpression,
                    $rgtExpression,
                ])
            );
        }

        // field which will be needed afterwards to generate route
        $listBuilder->addSelectField($fieldDescriptors['version']);
        $listBuilder->addSelectField($fieldDescriptors['subVersion']);
        $listBuilder->addSelectField($fieldDescriptors['name']);
        $listBuilder->addSelectField($fieldDescriptors['locale']);
        $listBuilder->addSelectField($fieldDescriptors['mimeType']);
        $listBuilder->addSelectField($fieldDescriptors['storageOptions']);
        $listBuilder->addSelectField($fieldDescriptors['id']);
        $listBuilder->addSelectField($fieldDescriptors['collection']);

        return $listBuilder;
    }
287310
public function listAction(Request $request)
    {
        $this->denyAccessUnlessGranted(ContributionActionInterface::READ, KeywordInterface::ENTITY_TYPE);
        $mapping = array(
            'label' => 'label'
        );
        $configuration = PaginateFinderConfiguration::generateFromRequest($request, $mapping);
        $repository = $this->get('open_orchestra_model.repository.keyword');
        $collection = $repository->findForPaginate($configuration);
        $recordsTotal = $repository->count();
        $recordsFiltered = $repository->countWithFilter($configuration);
        $facade = $this->get('open_orchestra_api.transformer_manager')->transform('keyword_collection', $collection);
        $facade->recordsTotal = $recordsTotal;
        $facade->recordsFiltered = $recordsFiltered;

        return $facade;
    }
430377
public function listByProfileAction(Request $request, $token)
    {
        list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPageByToken($request, $token);

        return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
    }
1249514
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
    {
        $options = [];
        $options['sonata_field_description'] = $fieldDescription;

        switch ($type) {
            case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType':
            case 'doctrine_phpcr_odm_tree':
                $options['class'] = $fieldDescription->getTargetEntity();
                $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

                break;
            case 'Sonata\AdminBundle\Form\Type\ModelType':
            case 'sonata_type_model':
            case 'Sonata\AdminBundle\Form\Type\ModelTypeList':
            case 'sonata_type_model_list':
                if ('child' !== $fieldDescription->getMappingType() && !$fieldDescription->getTargetEntity()) {
                    throw new \LogicException(sprintf(
                        'The field "%s" in class "%s" does not have a target model defined. Please specify the "targetDocument" attribute in the mapping for this class.',
                        $fieldDescription->getName(),
                        $fieldDescription->getAdmin()->getClass()
                    ));
                }

                $options['class'] = $fieldDescription->getTargetEntity();
                $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

                break;
            case 'Sonata\AdminBundle\Form\Type\AdminType':
            case 'sonata_type_admin':
                if (!$fieldDescription->getAssociationAdmin()) {
                    throw $this->getAssociationAdminException($fieldDescription);
                }

                $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
                $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));

                break;
            case 'Sonata\CoreBundle\Form\Type\CollectionType':
            case 'sonata_type_collection':
                if (!$fieldDescription->getAssociationAdmin()) {
                    throw $this->getAssociationAdminException($fieldDescription);
                }

                $options['type'] = 'Sonata\AdminBundle\Form\Type\AdminType';
                $options['modifiable'] = true;
                $options['type_options'] = [
                    'sonata_field_description' => $fieldDescription,
                    'data_class' => $fieldDescription->getAssociationAdmin()->getClass(),
                ];

            break;
        }

        return $options;
    }
1094622
public function fieldsAction(Request $request)
    {
        return $this->handleView(
            $this->view(
                array_values(
                    array_diff_key(
                        $this->getManager()->getFieldDescriptors($this->getLocale($request)),
                        [
                            'statusId' => false,
                            'categoryIds' => false,
                        ]
                    )
                ),
                200
            )
        );
    }
523034
private function getList(Request $request, $locale)
    {
        /** @var RestHelperInterface $restHelper */
        $restHelper = $this->getRestHelper();

        /** @var DoctrineListBuilderFactory $factory */
        $factory = $this->get('sulu_core.doctrine_list_builder_factory');

        $listBuilder = $factory->create($this->container->getParameter('sulu.model.contact.class'));
        $restHelper->initializeListBuilder($listBuilder, $this->getFieldDescriptors());

        $listResponse = $this->prepareListResponse($listBuilder, $locale);

        return new ListRepresentation(
            $listResponse,
            self::$entityKey,
            'get_contacts',
            $request->query->all(),
            $listBuilder->getCurrentPage(),
            $listBuilder->getLimit(),
            $listBuilder->count()
        );
    }
383440
public function listContentTypes(Request $request)
    {
        if ($this->getMediaType($request) === 'application/vnd.ez.api.contenttypelist') {
            $return = new Values\ContentTypeList(array(), $request->getPathInfo());
        } else {
            $return = new Values\ContentTypeInfoList(array(), $request->getPathInfo());
        }

        if ($request->query->has('identifier')) {
            $return->contentTypes = array($this->loadContentTypeByIdentifier($request));

            return $return;
        }

        if ($request->query->has('remoteId')) {
            $return->contentTypes = array(
                $this->loadContentTypeByRemoteId($request),
            );

            return $return;
        }

        $limit = null;
        if ($request->query->has('limit')) {
            $limit = (int)$request->query->get('limit', null);
            if ($limit <= 0) {
                throw new BadRequestException('wrong value for limit parameter');
            }
        }
        $contentTypes = $this->getContentTypeList();
        $sort = $request->query->get('sort');
        if ($request->query->has('orderby')) {
            $orderby = $request->query->get('orderby');
            $this->sortContentTypeList($contentTypes, $orderby, $sort);
        }
        $offset = $request->query->get('offset', 0);
        $return->contentTypes = array_slice($contentTypes, $offset, $limit);

        return $return;
    }
1335601
public function listAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

        $em = $this->getDoctrine()->getManager();
        $configuratorClassName = '';
        if ($this->container->hasParameter('kunstmaan_user_management.user_admin_list_configurator.class')) {
            $configuratorClassName = $this->container->getParameter(
                'kunstmaan_user_management.user_admin_list_configurator.class'
            );
        }

        $configurator = new $configuratorClassName($em);

        /* @var AdminList $adminList */
        $adminList = $this->container->get('kunstmaan_adminlist.factory')->createList($configurator);
        $adminList->bindRequest($request);

        return array(
            'adminlist' => $adminList,
        );
    }
381088
public function getFieldsAction(Request $request)
    {
        return $this->handleView(
            $this->view(array_values($this->getManager()->getFieldDescriptors($this->getLocale($request))))
        );
    }
418026
protected function getListBuilder($entityName, $fieldDescriptors)
    {
        /** @var RestHelperInterface $restHelper */
        $restHelper = $this->get('sulu_core.doctrine_rest_helper');

        /** @var DoctrineListBuilderFactory $factory */
        $factory = $this->get('sulu_core.doctrine_list_builder_factory');

        $listBuilder = $factory->create($entityName);

        $restHelper->initializeListBuilder(
            $listBuilder,
            $fieldDescriptors
        );

        return $listBuilder;
    }
1047824
public function listContentTypesForGroup($contentTypeGroupId, Request $request)
    {
        $contentTypes = $this->contentTypeService->loadContentTypes(
            $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId, Language::ALL),
            Language::ALL
        );

        if ($this->getMediaType($request) === 'application/vnd.ez.api.contenttypelist') {
            return new Values\ContentTypeList($contentTypes, $request->getPathInfo());
        }

        return new Values\ContentTypeInfoList($contentTypes, $request->getPathInfo());
    }
1114693
public function fetch(RequestDescriptor $request, $flags = 0)
    {
        $response = $this->send($request, $flags);
        $class    = $response->getMeta('entity');

        $data   = $response->getData();
        $entity = array();

        if (!empty($class)) {
            if (isset($data[0]) && is_array($data[0])) {
                foreach ($data as $resource) {
                    /** @var EntityInterface $entity */
                    $subEntity = new $class;
                    $entity->hydrate($resource);
                    $entity[] = $subEntity;
                }
            } else {

                /** @var EntityInterface $entity */
                $entity = new $class;
                $entity->hydrate($response->getData());
            }
        }

        return $entity;
    }
84909
public function cgetAction(Request $request)
    {
        $locale = $this->getUser()->getLocale();

        if ('true' == $request->get('flat')) {
            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->get('sulu_core.doctrine_rest_helper');

            $fieldDescriptors = $this->getFieldDescriptors();
            $listBuilder = $this->generateFlatListBuilder();
            $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);
            $this->applyRequestParameters($request, $listBuilder);

            $listResponse = $listBuilder->execute();
            $listResponse = $this->addLogos($listResponse, $locale);

            $list = new ListRepresentation(
                $listResponse,
                self::$entityKey,
                'get_accounts',
                $request->query->all(),
                $listBuilder->getCurrentPage(),
                $listBuilder->getLimit(),
                $listBuilder->count()
            );
            $view = $this->view($list, 200);
        } else {
            $filter = $this->retrieveFilter($request);
            $accountManager = $this->getAccountManager();
            $accounts = $accountManager->findAll($locale, $filter);
            $list = new CollectionRepresentation($accounts, self::$entityKey);
            $view = $this->view($list, 200);
        }

        $context = new Context();
        $context->setGroups(['fullAccount', 'partialContact', 'Default']);
        $view->setContext($context);

        return $this->handleView($view);
    }
416921
public function listActionCustom(Request $request = null)
    {
        $this->admin->checkAccess('list');

        $preResponse = $this->preList($request);
        if (null !== $preResponse) {
            return $preResponse;
        }

        if ($listMode = $request->get('_list_mode')) {
            $this->admin->setListMode($listMode);
        }

        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        return $this->renderWithExtraParams($this->admin->getTemplate('list'), [
            'action' => 'list',
            'form' => $formView,
            'batch_action_forms' => $this->getBatchActionFormViews(),

            'datagrid' => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
            'export_formats' => $this->admin->getExportFormats(),
        ], null);
    }
386249
public function getAjaxList(Request $request) // GET THE SLUG, ex. 'posts', 'pages', etc.
    {
        // GET THE SLUG, ex. 'posts', 'pages', etc.
        $slug = $request->slug;

        // GET THE DataType based on the slug
        $dataType = Admin::model('DataType')->where('slug', '=', $slug)->first();

        // Check permission
        $this->authorize('browse', app($dataType->model_name));

        $model = app($dataType->model_name);
        $query = $model->select('*');

        if (method_exists($model, 'adminList')) {
            $query = $model->adminList()->select('*');
        }

        if (!isset($request->order)) {
            if ($model->timestamps) {
                $query = $query->latest($model::CREATED_AT);
            } else {
                $relationships = $this->getRelationships($dataType);
                $query = $query->with($relationships)->orderBy($model->getKeyName(), 'DESC');
            }
        }

        $query = DataTables::of($query);

        foreach ($dataType->ajaxList() as $dataRow) {
            $query->editColumn($dataRow->field, function($dataTypeContent) use($request, $slug, $dataRow){
                $content = $dataTypeContent->{$dataRow->field};

                $handler = AbstractHandler::initial($dataRow->type);

                if (method_exists($handler, 'getContentForList')) {
                    $content = $handler->getContentForList($request, $slug, $dataRow, $dataTypeContent);
                }

                return $content;
            });

            if ($dataRow->type == 'relationship') {
                $query->filterColumn($dataRow->field, function ($query, $keyword) use($dataRow){
                    $relationship = json_decode($dataRow->details);
                    $ids = app($relationship->model)->where($relationship->label, 'like', "%$keyword%")->pluck($relationship->key);
                    $query->whereIn($relationship->column, $ids);
                });
            }
        }

        return $query
            ->addColumn('delete_checkbox', function($dataTypeContent) {
                return '<input type="checkbox" name="row_id" id="checkbox_' . $dataTypeContent->id . '" value="' . $dataTypeContent->id . '">';

            })
            ->addColumn('actions', function($dataTypeContent) use($dataType){
                return Admin::view('admin::list.datatable.buttons', ['data' => $dataTypeContent, 'dataType' => $dataType]);
            })
            ->rawColumns(array_merge($dataType->ajaxListFields(), ['delete_checkbox', 'actions']))
            ->make(true);
    }
1148767
public function create($type, Request $request)
    {
        if ($type && $product = $this->productManager->findByNamespace($type)) {
            $categories = $this->category->all()->nest()->listsFlattened('name');
            $shops = $this->shop->all();
            $optionTypes = $this->optionManager->all();

            return view('product::admin.products.create', compact('product', 'categories', 'shops', 'optionTypes'));
        }

        // If type is not exists, default type will be set
        $first = $this->productManager->first();

        return redirect()->route($request->route()->getName(), ['type' => $first->getEntityNamespace()]);
    }
816826
public function createAction(Request $request)
    {
        $templateRepository = $this->get('phlexible_media_template.template_manager');

        $type = $request->get('type');
        $key = $request->get('key');

        switch ($type) {
            case 'image':
                $template = new ImageTemplate();
                $template->setCache(false);
                break;
            case 'video':
                $template = new VideoTemplate();
                $template->setCache(true);
                break;
            case 'audio':
                $template = new AudioTemplate();
                $template->setCache(true);
                break;
            default:
                throw new InvalidArgumentException("Unknown template type $type");
        }

        $template->setKey($key);

        $templateRepository->updateTemplate($template);

        return new ResultResponse(true, 'New "'.$type.'" template "'.$key.'" created.');
    }