eZ Community » Forums » Developer » CSV Import & ezgmaplocation
expandshrink

CSV Import & ezgmaplocation

CSV Import & ezgmaplocation

Friday 03 August 2012 6:36:13 pm - 2 replies

Hello Everybody,

I use the 'SQLi-Import' Extension and i want to import data from a CSV File that contains informations such as Longitude and Latitude to create directly a nodes in BO , a node was a objet of class and this class have a type of attribute that use the ezgmaplocation extension.

$csvFile = $target_path;
$options = new SQLICSVOptions( array(
            'csv_path'    => $csvFile,
            'enclosure'   => '~'
        ) );
$csvDoc = new SQLICSVDoc( $options );
$csvDoc->parse();
        foreach( $csvDoc->rows as $row ) // Iteration
            {
               
                $contentOptions = new SQLIContentOptions( array(
                    'class_identifier'      => 'site',
                    'remote_id'             => $row->titre
                ) );
                $content = SQLIContent::create( $contentOptions );
               
                $content->fields->description = SQLIContentUtils::getRichContent( $row->description );
                $content->fields->continent = (string)$row->continent;
                $content->fields->pays = (string)$row->pays;
                $content->fields->activites = (string)$row->activites;
                $latitude = (double)$row->latitude;
                $longitude = (double)$row->longitude;
                $content->fields->emplacement_gmap = array( "latitude"=> $latitude, "longitude" => $longitude);        
                $content->addLocation(SQLILocation::fromNodeID($classe));
               
                $publisher = SQLIContentPublisher::getInstance();
                $publisher->publish($content);
               
            }
unset($content);

emplacement_gmap is the ID of attribute, but when I import CSV file the problem is there are no values of latitude and longitude of attribute "emplacement_gmap" .

 

Thx happy.gif Emoticon

Modified on Friday 03 August 2012 6:37:10 pm by V4Vendetta V

Sunday 05 August 2012 10:06:10 am

 

emplacement_gmap is the ID of attribute, but when I import CSV file the problem is there are no values of latitude and longitude of attribute "emplacement_gmap" .

The problem is that you want to use an array as a value for the GMap location attribute. It's needed to be a string, according to its fromString() method :

<gmapTableId_or_0>|#<latitude>|#<longitude>|#<address>

Moreover, you do your unset( $content ) outside the foreach loop. You'd better do this inside the  loop to properly free memory blunk.gif Emoticon.

Monday 03 February 2014 8:21:10 pm

Sample .csv file format to import GMap data into a class with two attributes, a name and the location.

Abington;"1|#42.117629|#-70.956766|#Abington, MA"
<span style="font-size: 1.1em;">Acton;"1|#42.48582|#-71.433299|#Acton, MA"</span>

Note the 1 in the first position of the GMap data.  If you have a zero, it doesn't import the data.

To run the script:

 php bin/php/ezcsvimport.php -v --class=community 121  test.csv

121 is the parent node.

Many thanks to this thread and the CSV import script!

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from