Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
csv-class for import-/export-functions in own addons
Vossi
Join Date: Mar 2005
Posts: 437

 

Germany
Show Printable Version Email this Page Subscription
Vossi Vossi is offline 08-05-2008, 10:00 PM

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:
PHP Code:
require_once(DIR '/includes/class_vbcsv.php');    
$vbcsv = new vBCSV($vbulletin$importfile$optionfields);
$vbcsv->importcsv($importtable); 
and the variables are:
Quote:
$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:
Quote:
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:
PHP Code:
id,name,city,userid,username,tel
81
,max test,hamburg,302,max,110
82
,moritz test,bremen,309,moritz,112 
This data needs to get imported with the following options:
PHP Code:
$optionfields = array();
$optionfields[0] = '0,0,0'// field 0 (id) ist getting ignored while import
$optionfields[1] = '3,1,1'// content of field 3 (userid) ist getting changed into '1' while import
$optionfields[2] = '4,1,admin'// content of field 4 (username) is getting changed into 'admin' while import 
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:
PHP Code:
require_once(DIR '/includes/class_vbcsv.php');
$vbcsv = new vBCSV($vbulletin$exportfile$optionfields);
$vbcsv->exportcsv($exporttable); 
and the variables are:
Quote:
$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:
Quote:
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, 11 views)
Reply With Quote
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04411 seconds
  • Memory Usage 2,216KB
  • Queries Executed 17 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit_attachment
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete