Coder Social home page Coder Social logo

importcsv's Introduction

Import / export CSV

Author: Twisted Interactive
Website: http://www.twisted.nl

Import a CSV file to create new entries for a certain section, or export an existing section to a CSV file

Import drivers

The import- and export-functions are provided by importdrivers. These are located in the folder drivers. By default, the import/export-function looks for a driver called ImportDriver_(fieldname) to handle the imports and export of a specific field.

For example, for select-fields the ImportDriver_select is used and for upload-fields the ImportDriver_upload is used. If no exact driver can be found, it falls back to ImportDriver_default which is good for most fields (as it simply relies on a value-field in your database table).

Default drivers

Default drivers are packaged for:

  • Frontend Member Manager Password (to prevent double MD5-ing)
  • Select (to provide selecting of multiple values)
  • Selectbox link (to import and export while remaining human-readable values in your CSV)
  • Reference link (to import and export while remaining human-readable values in your CSV)
  • Status (to select the right value from the dedicated statusses-table)
  • Subsection Manager (to keep the multiple ID's intact)
  • Upload (to import files with CSV)

Write your own driver

Do you have an exotic field where the default driver just isn't enough? Then you should write your own driver. Don't worry! It's not that difficult. Just look at the default driver and at the pre-packaged drivers installed with the extension to get an idea about how it works.

Most important to remember are the functions import($value, $entry_id) and export($data, $entry_id).

import($value, $entry_id)

The import function processes the value fetched from the CSV-file and prepares it for storing into the entry. Sometimes some pre-processing must be done to store the entry correct. For example, look at the select-driver, which breaks the value into an array so it gets sent to the entry. Or the upload-driver which loads some meta-data to store in the entry. The function should return a $data-parameter. This parameter is used by the extension to provide the entry with data: $entry->setData($fieldID, $data);.

export($data, $entry_id)

The export function processes the data fetch from the entry by the $entry->getData($field->get('id'));-function. It is the raw data that is provided by Symphony. Here you can do some post-processing to alter the data before it gets stored in the CSV. For example: the select-driver stores multiple values as a single string, combining them with a comma. And the selectbox-link driver loads the human-readable value of the item to store in the CSV. The function should return a $value-parameter. This parameter is used by the extension to be placed in the CSV file.

scanDatabase($value)

This is also an important function. It is used for updating entries. Basicly what it does, is scan the database to find an entry with the value specified. If a match is found, it returns the ID of the entry which in turn will get updated. If no match is found, null is returned.

In the import-process it is used as followed: when you want to import something, and you selected a specific field as 'unique', that field will be used to scan the database for an existing value. Most of the times these are input fields or something, like an ID, a e-mail address, or something else that has a value-row in the database (which is the default behaviour).

But if you have a field which doesn't have a value-row in the database, you need to specify an adjusted query in the driver. Otherwise it will always get imported as a new entry when that field is selected as the unique field.

Make this extension better!

Did you write a driver for a field? Share it with us! It will only make this extension better and stronger!

importcsv's People

Contributors

kanduvisla avatar simon-dt avatar brendo avatar davidoliver avatar xfrenette avatar patrickyan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.