PHP code example of elma / devexpressbundle

1. Go to this page and download the library: Download elma/devexpressbundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elma / devexpressbundle example snippets


    /**
     * @return \Symfony\Component\HttpFoundation\Response
     * @Route(...)
     */
    public function indexAction(Request $request)
    {
        // Initiate the parser
        $parser = new SearchQueryParser(); 
        // Parse the DevExpress object
        $query = $parser->parse(json_decode($request->get('loadOptions')));

        // Link between the column header and the doctrine field
        $map = [
            "Username" => "u.username",
            "FirstName" => "u.firstName"
        ];
        // Create the config with the mapping
        $config = new DoctrineQueryConfig($map);

        // Return the data and the total number of item
        return $this->json([
            'content' => $this->getContent($config, $query),
            'total' => $this->getTotal($config, $query)
        ]);
    }

    private function getContent(DoctrineQueryConfig $config, SearchQuery $query)
    {
        // Create the query builder
        $queryBuilder = $this->getDoctrine()->getManager()->createQueryBuilder();
        // Select Data from the DB
        $queryBuilder->select('u')->from('AcmeUserBundle:Order', 'u');

        // Create the query handle
        $handler = new DoctrineQueryHandler($config, $queryBuilder, $query);
        // Binds the filters, pagination and sorting
        $queryBuilder = $handler->addAllModifiers();

        return $queryBuilder->getQuery()->getResult();
    }

    private function getTotal(DoctrineQueryConfig $config, SearchQuery $query)
    {
        $queryBuilder = $this->getDoctrine()->getManager('catalogue')->createQueryBuilder();
        $queryBuilder->select('COUNT(u)')->from('AcmeUserBundle:Order', 'u');

        $handler = new DoctrineQueryHandler($config, $queryBuilder, $query);
        // Add only the filters. You must not add the pagination. You should not add sorting (useless for counting)
        $handler->addFilters();

       return $queryBuilder->getQuery()->getSingleScalarResult();
    }

//File : app/AppKernel.php
$bundles = [
    // ...
    new Bilendi\DevExpressBundle\BilendiDevExpressBundle,
    // ...
]