Hooking Bulk Handler
XML
Add the hook to the hooks section of your module's module.xml
module.xml
<hooks>
<bulkhandler class="Bulkhandler" namespace="FreePBX\modules">
<method callingMethod="getHeaders" class="Yourmodule" namespace="FreePBX\modules">bulkhandlerGetHeaders</method>
<method callingMethod="import" class="Yourmodule" namespace="FreePBX\modules">bulkhandlerImport</method>
<method callingMethod="export" class="Youemodule" namespace="FreePBX\modules">bulkhandlerExport</method>
</bulkhandler>
</hooks> |
Methods
getHeaders
Expects a multidimensional array back with the key as the field name with 1 child item of description
Yourmodule.class.php
public function bulkhandlerGetHeaders($type) {
switch ($type) {
case 'extensions':
$headers = array(
'yourmodule_item1' => array(
'description' => _('Your module item 1 should be foo or bar')
),
'yourmodule_item2' => array(
'description' => _('Your module item 2 should be bar or baz'),
)
);
return $headers;
break;
}
} |
import
This function will be passed the type and a blob of data for you to handle. The data will be an array with one item for each row.
You should return array with a bool status.
Yourmodule.class.php
public function bulkhandlerImport($type, $rawData) {
$ret = NULL;
switch ($type) {
case 'extensions':
foreach ($rawData as $data) {
$extension = $data['extension'];
foreach ($data as $key => $value) {
if (substr($key, 0, 9) == 'mymodule_') {
$settingname = substr($key, 9);
switch ($settingname) {
case 'item1':
case 'item2':
$settings[$settingname] = explode('-', $value);
break;
default:
$settings[$settingname] = $value;
break;
}
}
}
if (!empty($settings) && count($settings) > 0) {
$this->addSettingsById($extension, $settings);
}
}
$ret = array(
'status' => true,
);
break;
}
return $ret;
} |
export
You should return back null or a multidimensional array with the key as the extension and the settings as an array
Yourmodule.class.php