PHP code example of nassau / kunstmaan-import-bundle

1. Go to this page and download the library: Download nassau/kunstmaan-import-bundle 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/ */

    

nassau / kunstmaan-import-bundle example snippets


class FoobarAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator implements ImportWizardAdminListConfiguratorInterface
{
    /**
     * Add a button to the admin list pointing to the import module
     */
    public function buildListActions()
    {
        $this->addListAction(new SimpleListAction([
            'path' => 'acmebundle_admin_foobar_import_upload',
            'params' => [],
        ], 'Upload Excel file', 'upload'));
    }

    public function getImportType()
    {
        return 'foobar';
    }


    /**
     * @Route("/import/{id}", name="acmebundle_admin_foobar_import_edit")
     * @param Request $request
     * @param Import $import
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function importAction(Request $request, Import $import)
    {
        $configurator = $this->getAdminListConfigurator();

        $result = $this->get('nassau.kunstmaan_import.import_wizard_action')->import($request, $import, $configurator);

        if (false === is_array($result)) {
            if ($result) {
                $this->addFlash('success', $result);
            }

            return $this->redirectToRoute('acmebundle_admin_foobar_import_edit', ['id' => $import->getId()]);
        }

        return $this->render('KunstmaanImportBundle::Import.html.twig', $result);
    }

    /**
     * @Route("/import", name="acmebundle_admin_foobar_import_upload")
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function uploadAction(Request $request)
    {
        $configurator = $this->getAdminListConfigurator();

        $result = $this->get('nassau.kunstmaan_import.import_wizard_action')->upload($configurator, $request);

        if (null === $result) {
            $this->addFlash('success', 'nassau.import.flash.successfull_import');

            return $this->redirectToRoute('acmebundle_admin_foobar');
        }

        if ($result instanceof Import) {
            $this->addFlash('warning', 'nassau.import.flash.import_errors');

            return $this->redirectToRoute('acmebundle_admin_foobar_import_edit', ['id' => $result->getId(), 'errors' => true]);
        }

        return $this->render($configurator->getAddTemplate(), $result);

    }