PHP code example of bigfoot / import-bundle

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

    

bigfoot / import-bundle example snippets

 shell
php composer.phar update
 php
/* Services/QualitelisNotesDataMapper.php */
class QualitelisNotesDataMapper extends AbstractSimpleDataMapper
{
    ...
}
 php
/* Services/QualitelisNotesDataMapper.php */
class QualitelisNotesDataMapper extends AbstractSimpleDataMapper
{
    const FIELD_1           = 'header_field_1';
    const FIELD_2           = 'header_field_2';
}
 php
/* Services/QualitelisNotesDataMapper.php */
class QualitelisNotesDataMapper extends AbstractSimpleDataMapper
{
    const FIELD_1           = 'header_field_1';
    const FIELD_2           = 'header_field_2';

    protected function getColumnMap()
    {
        return array(

            self::FIELD_1       => 'setField1',
            self::FIELD_2       => 'setField2',

            ...
            ...


        );
    }
}
 php
/* Services/QualitelisNotesDataMapper.php */
class QualitelisNotesDataMapper extends AbstractSimpleDataMapper
{
    const FIELD_1           = 'header_field_1';
    const FIELD_2           = 'header_field_2';

    protected function getColumnMap()
    {
        return array(

            self::FIELD_1       => 'setField1',
            self::FIELD_2       => 'setField2',

            ...
            ...


        );
    }

    protected function getEncodedValue($value) {
        return utf8_encode($value);
    }
}
 php
/* Services/QualitelisNotesDataMapper.php */
class QualitelisNotesDataMapper extends AbstractSimpleDataMapper
{
    const FIELD_1           = 'header_field_1';
    const FIELD_2           = 'header_field_2';

    protected function getColumnMap()
    {
        return array(

            self::FIELD_1       => 'setField1',
            self::FIELD_2       => 'setField2',

            ...
            ...


        );
    }

    protected function getEncodedValue($value) {
        return utf8_encode($value);
    }

    protected function getObject($className, $line)
    {

        $em = $this->container->get('doctrine.orm.default_entity_manager');

        $qualitelis_namespace = $this->container->getParameter('bigfoot_qualitelis.namespace');


        $object = $em->getRepository($qualitelis_namespace.$className)->findOneBy(array(self::FIELD_1 => $line[$this->data->getIndexOfHead(self::FIELD_1)]));

        if (!$object) {
            $fqcn = $qualitelis_namespace.'\\Entity\\'.$className;
            return new $fqcn;
        }

        return $object;
    }
}
 php
/* Controller/DefaultController.php */

public function indexAction()
{

    $em = $this->container->get('doctrine.orm.default_entity_manager');

    /* Where 'nameOfTheFtpConfiguration' is the name you entered for the FTP configuration  */
    $object = $em->getRepository('BigfootImportBundle:DataSource')->findOneBy(array('name' => 'nameOfTheFtpConfiguration'));

    $client = $this->get('bigfoot_import.client');
    $client->init($object->getDomain());
    $client->setAuth($object->getUsername(),$object->getPassword());

    $parser = $this->get('bigfoot_import.csvparser');
    $parser->setClient($client);
    $parser->setDelimiter(';');

    /* Name of your csv file in the FTP */
    $data = $parser->parse('nameofthecsvfile.csv');

    /* Name of the service */
    $dataMapper = $this->get('bigfoot_qualitelis.note_datamapper');

    $dataMapper->setData($data);

    /* Name of your entity */
    $dataMapper->className = 'QualitelisNote';

    $dataMapper->map();

    return new Response();
}