vinorcola/import-bundle

Bundle providing tools for importing and mapping a file.

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

dev-master 2020-02-15 14:54 UTC

This package is auto-updated.

Last update: 2020-05-15 15:31:26 UTC


README

A bundle to import data from CSV or Excel files, letting the user map the columns of its file to the required fields for your process.

Configuration

Setup a temporary directory in which the uploaded files will be stored temporarily.

Setup as many imports as you want by configuring:

  • the route prefix (several routes are generated for each import process)
  • the mapping (the required columns for your process)
  • The process service (which must implement Vinorcola\ImportBundle\Model\ImportConsumerInterface).
# config/packages/vinorcola_import.yaml

vinorcola_import:
    temporaryDirectory: "%kernel.project_dir%/document-storage/tmp"
    imports:
        company_import:
            route_prefix:
                name: import.company.
                url: /company/import
            mapping: [ nationalIdentifier, companyName, address, city ]
            service: App\Model\CompanyImportHandler
        contact_import:
            route_prefix:
                name: import.contact.
                url: /contact/import
            mapping: [ firstName, lastName, emailAddress, phoneNumber ]
            service: App\Model\ContactImportHanlder
# config/routes/vinorcola_import.yaml

import_routes:
    resource: '@VinorcolaImportBundle/Controller/'
    type: vinorcola_import

Then, the consume method of your process service will be called for line of data in the user's file, providing an array with the mapped columns and the line index:

public function consume(array $values, int $lineIndex): void;

For example, in the App\Model\CompanyImportHandler, the consume method will be called with a $values array containing the following keys:

  • nationalIdentifier
  • companyName
  • address
  • city