PrivateContent Plugin
Import / Export Class
Introduction
#Defined in classes/users_import_export.php
PHP class managing users import and export: CSV and Excel files, PrivateContent-to-PrivateContent JSON files. It extends the main pc_users class.
The class is not loaded automatically: include its file before using it. Methods work with the data submitted by the related admin forms, then they are mostly useful to replicate those operations via code. To customize standard imports and exports, use their hooks (eg. pc_csv_export_fields_to_get or pc_csv_import_new_user).
include_once(PC_DIR .'/classes/users_import_export.php');
$ie = new pvtcont_users_import_export(); This class replaces the old $pc_users->export_users() method.
csv_export()
method#Exports users data into a CSV or Excel file. Exported fields can be managed through pc_csv_export_fields_to_get and the users query through pc_csv_export_users_query.
Usage
csv_export($fdata) Parameters
| Parameter | Description |
|---|---|
(array) $fdata | export options - check the table below |
Export options
| Key | Description |
|---|---|
pc_csv_exp_export_type | csv or excel |
pc_csv_exp_user_statuses | array of statuses to export (1, 2, 3) or array('all') |
pc_csv_exp_user_cats | array of user category IDs or array('all') |
pc_selective_data_exp | array of field IDs to export. Empty array to export everything |
Return values
| Type | Description |
|---|---|
(array) | array('status' => 'success', 'filedata' => base64 encoded file) or array('status' => 'error', 'message' => ..) |
Example
include_once(PC_DIR .'/classes/users_import_export.php');
$ie = new pvtcont_users_import_export();
$result = $ie->csv_export(array(
'pc_csv_exp_export_type' => 'csv',
'pc_csv_exp_user_statuses' => array(1),
'pc_csv_exp_user_cats' => array('all'),
'pc_selective_data_exp' => array('username', 'email'),
));
if($result['status'] == 'success') {
$csv = base64_decode($result['filedata']);
} pvtc_export()
method#Exports users (data, meta and categories) into a JSON file, to be imported in another website running PrivateContent. Hooks: pc_pvtc_export_users_query, pc_pvtc_export_user_meta, pc_pvtc_export_user_data_array.
Usage
pvtc_export($fdata) Parameters
| Parameter | Description |
|---|---|
(array) $fdata | export options: pc_pvtc_exp_user_statuses, pc_pvtc_exp_user_cats and pc_selective_data_exp (same values of csv_export()) |
Return values
| Type | Description |
|---|---|
(array) | array('status' => 'success', 'filedata' => ..) or array('status' => 'error', 'message' => ..) |
$import_report
property#Public property filled by import methods, available also inside import hooks through the class reference they pass.
| Key | Description |
|---|---|
new_cats | created user categories |
new_users | imported users |
overridden_users | existing users updated |
discarded_users | skipped users |
user_errors | errors found, per user |