Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
csv-class for import-/export-functions in own addons
Vossi
Join Date: Mar 2005
Posts: 428

Germany
by Vossi Vossi is offline 06 Aug 2008
Rating: (3 votes - 5.00 average)

I coded this csv-class for vB because I needed a decent import-/export-function for my own addons. This class is published as a so-called 'development-class' and it would be nice if this class is going to be more developed with your help.

Coders can use this simple class in their addons if they need to create backups of tables in the database or import data into it.

Importing a .csv-file:

The class is going to be called like this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and the variables are:
$vbulletin = registry object
$importfile = filename incl. path
$optionfields = array with 3 values each line
$importtable = name of table in database to import into
The array $optionfields ist constructed in the following way:
1. value = id of field (0=first field, 1=second field ....)
2. value = option (0=ignore field|1=fieldcontent of 3. value)
3. value = content which replaces the source content if option 1 ist set in in 2. value
For example look at this .csv-file:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This data needs to get imported with the following options:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Field id is getting ignored while import (in cases where you don's want the id to get imported and to avoid db-errors), the values for userid and username are getting changed into 1 and admin while import.

If $optionfields is not defined while the class is getting called, the table will be imported like it is without any .

Export into a .csv-Datei:

This function is similar to the import-function:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and the variables are:
$vbulletin = registry object
$exportfile = filename incl. path
$optionfields = array with 3 values each line
$exporttable = content which replaces the source content if option 1 ist set in in 2. value
The array $optionfields ist constructed in the following way:
1. value = id of field (0=first field, 1=second field ....)
2. value = option (0=ignore field|1=fieldcontent of 3. value)
3. value = content which is getting used while export when option 1 ist used in 2. value.
The way of using $optionfields is similar to the import-function.

If $optionfields is not defined while using the export-function, the table is getting exported without changes.
Attached Files
File Type: zip class_vbcsv.zip (4.2 KB, 7 views)

Last edited by Vossi : 06 Aug 2008 at 15:47.
Views: 1448
Reply With Quote
Reply


Similar Article
Article Author Type Replies Last Post
Import/Export BBCodes Dream vBulletin 3.5 Add-ons 12 25 Sep 2011 15:50

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 07:38.

Layout Options | Width: Wide Color: