arckinteractive / csv_process
提供一个接口用于上传/处理csv文件,并为其他插件提供自定义回调
2.0.1
2015-12-29 19:59 UTC
Requires
- php: >=5.5
- composer/installers: ~1.0
This package is not auto-updated.
Last update: 2024-09-14 18:42:07 UTC
README
本插件旨在为经常使用csv文件进行数据导入等操作的开发者提供帮助。
此插件旨在简化csv处理的大部分工作。它提供了一个管理页面用于上传/选择csv文件,选择处理csv的功能,设置csv特定设置,以及查看/下载显示脚本执行情况的日志文件。
处理csv功能的表单位于管理 -> 工具 -> CSV处理
##安装
安装/解压/克隆到您的elgg安装的mod目录
该目录应命名为csv_process
通过管理员插件页面启用插件
##依赖
此插件需要vroom插件 https://github.com/jumbojett/vroom
##集成
集成此插件需要以下3个步骤
-
注册插件钩子处理程序以声明回调函数
-
声明您的回调函数
-
定义您的回调函数
注册您的插件钩子处理程序
elgg_register_plugin_hook_handler('csv_process', 'callbacks', 'myplugin_csv_callbacks');
声明您的回调函数
function myplugin_csv_callbacks($hook, $type, $return, $params) {
$return['myplugin_csv_process'] = elgg_echo('myplugin:handler:label');
return $return;
}
返回值是一个关联数组,其中您的回调函数名称作为键,一个描述功能的标签作为值。这些将用于填充下拉输入框以选择如何处理csv。
定义您的回调函数
/**
*
* @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!';
}
这就是全部。确定如何处理您的数据,然后让此插件处理界面、日志记录、行迭代等。