2017 © Pedro Peláez
 

elgg-plugin csv_process

Provides an interface for uploading/processing csvs with custom callbacks for other plugins

image

arckinteractive/csv_process

Provides an interface for uploading/processing csvs with custom callbacks for other plugins

  • Tuesday, December 29, 2015
  • by hypeJunction
  • Repository
  • 8 Watchers
  • 1 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

CSV Process for Elgg

Elgg 2.0+, (*1)

This is intended for developers who routinely use csvs for functions such as data imports., (*2)

This plugin aims to take much of the legwork out of csv processing. It provides an admin page for uploading/selecting the csv, selecting the function to process the csv, setting csv specific settings, and watching/downloading a log file showing how the script performed., (*3)

The form for handling csv functions is found at Admin -> Utilities -> CSV Processing, (*4)

Installation

Install/unzip/clone to the mod directory of your elgg installation, (*5)

The directory should be named csv_process, (*6)

Enable the plugin through the admin plugins page, (*7)

Dependencies

This plugin requires the vroom plugin https://github.com/jumbojett/vroom, (*8)

Integration

There are only 3 steps required to integrate to this plugin, (*9)

  1. Register a plugin hook handler to declare a callback function, (*10)

  2. Declare your callback function, (*11)

  3. Define your callback function, (*12)

Register your plugin hook handler:, (*13)

elgg_register_plugin_hook_handler('csv_process', 'callbacks', 'myplugin_csv_callbacks');

Declare your callback function:, (*14)

function myplugin_csv_callbacks($hook, $type, $return, $params) {   
    $return['myplugin_csv_process'] = elgg_echo('myplugin:handler:label');
    return $return;
}

The return value is an associative array with your callback function name as the key and a label describing the function as a value. These will be used to populate the dropdown input for selecting how to process the csv., (*15)

Define your callback function, (*16)

/**
 *
 *  @params array()
 */
function myplugin_csv_process($params) {

    static $skipped;

    // you can always know what line you are on with $params
    if ($params['line'] == 1) {
        // first line is our column headers, nothing to do here
        return;
    }

    // the $params['last'] flag indicates that there are is no more data
    // this can be used to log any final tallies or information
    // when the 'last' flag is true data will be an empty array
    if ($params['last']) {
        return "{$params['line']} lines processed, {$skipped} skipped users";
    }

    // our data is an array in $params['data']
    // do something with it
    $user = get_user($params['data'][0]);

    if (!$user) {
        $skipped++;
        return; // nothing to do here
    }

    // we have a user from our data, import something
    $user->food = $params['data'][1];


    // a returned string from the function will automatically be logged
    // but you can always log extra stuff yourself
    csv_process\log("my log message", $params);

    return 'this will also be logged!';
}

That's all. Sort out what to do with your data and let this plugin handle the interface, logging, row iterations, etc., (*17)

The Versions

29/12 2015

dev-master

9999999-dev http://arckinteractive.com

Provides an interface for uploading/processing csvs with custom callbacks for other plugins

  Sources   Download

GPL-2.0

The Requires

 

by Matt Beckett

plugin csv import elgg

29/12 2015

2.0.1

2.0.1.0 http://arckinteractive.com

Provides an interface for uploading/processing csvs with custom callbacks for other plugins

  Sources   Download

GPL-2.0

The Requires

 

by Matt Beckett

plugin csv import elgg

29/12 2015

2.0.0

2.0.0.0 http://arckinteractive.com

Provides an interface for uploading/processing csvs with custom callbacks for other plugins

  Sources   Download

GPL-2.0

The Requires

 

by Matt Beckett

plugin csv import elgg