Hi,

Just need some help from you regarding the following issue.

I have a created a view from a drupal database table using the data module with views and VBO.
The data module allows you to create a view from the adopted table.
But,
when I go to the views and edit the view added through the data module, i see no multi-checkbox list under selected operations.

I want to have all the operations that are available under the node view type to be available here, for my view created with data module. (views created with data module have a view type data table)

Any help greatly appreciated.
Please help me ...
it's really very urgent.

Thanks,
Nilesh Barve

CommentFileSizeAuthor
#15 no operations to select.png13.73 KBheld69
#8 data_vbo.tgz950 bytesinfojunkie

Comments

infojunkie’s picture

VBO does not support Data module yet. Since this is critical for you, I assume you are ready to code VBO support for data tables. I will be happy to help you out.

To support data tables, you must implement hook_views_bulk_operations_object_info. Check views_bulk_operations.module for an example implementation of this hook. Be aware of the following points:

* Views of data tables have a type (attribute base_table in the view object) that is equal to the table name. Therefore, your implementation of the hook above must return one entry per table name. Specifically, the base_table attribute should match the table name. Give the type attribute the value data.
* You will also need to implement actions on the data tables, unless you can live with the generic "Execute arbitrary PHP script" action. Your new actions should be of type data, matching the object info type above. In your actions, you will probably use the Data API to manipulate fields.

Once this is done, edit the VBO style settings in the View admin interface. There, you will find your new actions.

nileshbarve13’s picture

Hi Karim,

Thanks for you prompt reply.

from the above i understand that i have to code out the operations for the data table type view.

So, i added

'datatable' => array(
'type' => 'data',
'base_table' => 'data_tables',
'load' => 'custom_get_term',
'oid' => 'tid',
'title' => 'name',
'hook' => 'Data table',
),

to the "function views_bulk_operations_views_bulk_operations_object_info()" in "views_bulk_operations.module"

Now, what next?
How do i get the table name for the above hook?

Can you please tell me what changes i need to make to get the above working?

here's some additional information on what i am planning to do.

I have a custom module(used in conjunction with smsframework and smsbulk modules) to send bulk sms to a drupal user list. I am able to do this successfully as the "selected operations show all VBO for user type view".

My next requirement is to send bulk sms to a non drupal user list. This is where i use data module to import the new table and create a view from it.

I want to send bulk sms to this imported list.
so, basically i want all actions under user or node type view to be under the data tables view.

Please give me step by step instructions.

If possible, could you create a example bulk operation from the user/node view for data table and post it here?

That would be of great help.

Thanks again.
(will be troubling you for some more time with this :-) )

Thanks,
Nilesh Barve.

nileshbarve13’s picture

Hi Karim,

The table i imported through data module is smslist with just 1 record (having 6 fields).
just tried coding some part in a new .inc file named smslist.action.inc as follows.

<?php
// $Id:$

/* @file
* Emails selected objects to a recipient as a list
*/

/*function views_bulk_operations_smslist_info() {
$object_info = array(
'datatable' => array(
'type' => 'data',
'base_table' => 'smslist',
'load' => 'custom_get_term',
'oid' => 'tid',
'title' => 'name',
'hook' => 'Data table',
),
);
return $object_info;
}*/

/* Implementation of hook_action_info().*/

function views_bulk_operations_smslist_action_info() {
return array(
'views_bulk_operations_smslist_action' => array(
'description' => t('Email list of nodes to a recipient'),
'type' => 'data', // this should probably be changed to something else!
'base_table' => 'smslist',
'aggregate' => TRUE, // tell Drupal this action operates on all nodes at once (not one by one)
'configurable' => TRUE, // tell Drupal this action requires form input
'hooks' => array(),
),
);
}

/* Implementation of a Drupal action.
* Passes selected nodes as arguments to a view.
* @param $objects array of node IDs
* @param $context array of other parameters
/
function views_bulk_operations_smslist_action($objects, $context = array()) {
global $user;

// $objects is an array of object IDs, since the action includes aggregate.

/* @todo Build the email containing the node descriptions here.
* We need to loop through getting the nodes from the $objects ID array and
* building the body of the email into $params['context']['body'] and subject into $params['context']['subject']
*/

$recipient = $context['recipient'];
$account = $user;
$language = user_preferred_language($account);
$params = array('account' => $account, 'context' => $context);

if (drupal_mail('view_bulk_operations_smslist', 'action_send_email', $recipient, $language, $params)) {
watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
} else {
watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
}
//}

/* Implementation of hook_mail().*/

function view_bulk_operations_smslist_mail($key,&$message,$params) {
$account = $params['account'];
$context = $params['context'];

$variables = array(
'%site_name' => variable_get('site_name', 'Drupal'),
'%username' => $account->name,
);

$subject = strtr($context['subject'], $variables);
$body = strtr($context['message'], $variables);
$message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
$message['body'][] = drupal_html_to_text($body);
}

function views_bulk_operations_smslist_action_form($context) {
$form['recipient'] = array(
'#title' => t('Email Recipient'),
'#type' => 'textfield',
'#description' => t('Enter an email address to send the list of nodes to.'),
'#default_value' => @$context['recipient'],
'#required' => TRUE,
);
return $form;
}

/* Validate system_send_email_action form submissions.*/

function views_bulk_operations_smslist_action_validate($form, $form_state) {
$form_values = $form_state['values'];
// Validate the configuration form.
if (!valid_email_address_list($form_values['recipient'] ) ) {
form_set_error('recipient', t('Please enter valid email addresses.'));
}
}
/* Verify the syntax of the given comma-delimited list of e-mail addresses.
*
* @param $mail
* A string containing comma-delimited list of e-mail addresses.
* @return
* TRUE if all the addresses are in a valid format.
* @todo
* Put this function in the correct place for user functions.
*/

function valid_email_address_list($mail) {

$ret = true;

$email_array = explode(',', $mail);

foreach ( $email_array as $key => $email_address ){

if ( !valid_email_address( $email_address ) ){
$ret = false;
break;
}

}
return $ret;
}
function views_bulk_operations_smslist_action_submit($form, $form_state) {
return array('recipient' => $form_state['values']['recipient']);
}

Still no actions are listed in view for smslist.

Please tell where i'm going wrong. Do i need to add code anywhere else?

Thanks,
Nilesh Barve.

infojunkie’s picture

I advise you to create your own module with the implementation of hook_views_bulk_operations_object_info and your action.

Make sure that the base_table in object info corresponds to your table name, and that the type of your object info is the same as thetype of your action info. Then the action will appear in the VBO settings.

nileshbarve13’s picture

Hi Karim,

Thank you for the response....
I was not very clear about what exactly you instructed me to do.(because i'm relatively new to drupal)

Just used my common sense to make a module with "hook_views_bulk_operations_object_info()" and it worked
like a charm....

The hook function is as follows:--

function datatables_views_bulk_operations_object_info() {
$info = array();
if (module_exists('datatables')) {
$info = array(
'website_total_customer_list' => array(
'type' => 'data',
'base_table' => 'website_total_customer_list',
'load' => '_datatables_civicrm_contact_load',
'title' => 'contact_id',
),
);
}
return $info;
}

as you can see, my module name is "datatables" and the imported table is "website_total_customer_list".
All the above works fine for me when i see the view for above mentioned table i get the recordset and i am able to send sms to that list.

But this module works for only one table given above.
I want to get the VBO in another view created from another imported table. Do I need to create a separate module for each table?
I dont understand how to get the table name dynamically for my hook function.

Please shed some light on the above issues.

Thank you once again for all the help you have given so far....

Cheers:-)
Nilesh Barve.

infojunkie’s picture

You can just populate the $info with several keys:

$info['table_1'] = array(
...
);
$info['table_2'] = array(
...
);
ivan zugec’s picture

I got VBO to work with the Data module and custom actions, it's pretty straight forward once you know how.

Step 1. Notify VBO about your Data module table using hook_views_bulk_operations_object_info.
Example:

/**
 * Implementation of hook_views_bulk_operations_object_info().
 */
function example_views_bulk_operations_object_info() {
  $object_info = array(
    'example_data_table' => array(
      'type' => 'example',
      'base_table' => 'example_data_table', //Must be Data table name.
      'load' => 'example_load_row', //Function which returns a single row
      'oid' => 'id', //Specific column used as your ID.
      'title' => 'name',
    ),
  );
  return $object_info;
}

Step 2. Create custom actions.

/**
 * Implementation of hook_action_info().
 */
function example_action_info() {

  $info['example_send_email_action'] = array(
    'type' => 'example',
    'description' => t('Send email'),
    'configurable' => FALSE,
    'hooks' => array(
      'any' => TRUE,
    ),
  );
  $info['example_send_delete_email_action'] = array(
    'type' => 'example',
    'description' => t('Delete'),
    'configurable' => FALSE,
    'hooks' => array(
      'any' => TRUE,
    ),
  );
  
  return $info;
}

Step 3. Setup your action functions.

function example_send_email_action($object, $context) { };
function example_send_delete_email_action($object, $context) { };
infojunkie’s picture

Title: bulk operations not listed on views created with data module » Integrate VBO with Data module
Component: Actions » Integration
Priority: Critical » Normal
Issue tags: +data
StatusFileSize
new950 bytes

I just remembered that I had been working on a Data + VBO integration a few weeks ago. Here's the module (it's not published yet, I will probably submit it to the Data maintainers). This module gives VBO access to all data tables, and exposes a new action to delete data records. You can create your specific actions based on the code here.

You will need to use the latest VBO dev (12 hours from now because I just committed a necessary change to support this module).

infojunkie’s picture

Thanks Ivan for your contribution! I didn't notice your reply as I was writing mine.

The difference between Ivan's code and mine is that his code addresses particular data tables, while mine provides a generic mechanism for all data tables. If you want to go with the generic approach, be aware that the record title is currently taken to be the id itself, which is not very informative. To get around that, you need to implement hook_views_bulk_operations_object_info_alter():

<?php
function mymodule_views_bulk_operations_object_info_alter(&$object_info) {
  $object_info['example_table']['title'] = 'example_title_field';
}
?>
nileshbarve13’s picture

Component: Integration » Actions
Priority: Normal » Critical

Hi Ivan,
i just got it working a few hours ago...
Thanks for your help...
nicely explained...

cheers:-)
Nilesh.

infojunkie’s picture

Category: feature » support
Priority: Critical » Normal
Status: Active » Fixed

Setting to fixed unless OP has more issues.

nileshbarve13’s picture

Hi Karim,

I need another addition to be made to the datatable action list.
I want the edit option to edit individual records displayed in the datatable view.

Based on the delete code in your data_vbo module i've managed to write additional functions to edit/modify as follows:-
defining the action

'datatable_modify_action' => array(
'type' => 'data',
'description' => t('Modify data record'),
'configurable' => FALSE,
'behavior' => array('changes_node_property'),
),

the actual modify function call

function datatable_modify_action($datum, $context) {
if (!isset($context['object_info'])) return;
$object_info = $context['object_info'];
$handler = data_get_handler($object_info['base_table']);
if (!$handler) return;
$handler->modify(array($object_info['oid'] => $datum->{$object_info['oid']}));
}

this is where i need your help...

How to edit the selected data table record? what handler to be used and where??

please guide me.

Thanks,
Nilesh.

infojunkie’s picture

To edit fields, you need to do write an action that exposes a form (called a configurable action). Read the Writing actions guide to find out how.

When you understand how to write configurable actions, you will need to do the following:

* In the action form, retrieve the object_info and use it to retrieve the data table (data_get_table). The returned object can be queried to find the table schema, which you need to iterate on to build a form input for each table field.

* Once you successfully write a submit function for the action, your new action function will be passed the edited fields in the context. Use the data handler (as in the delete action) to update the current record with the new values.

FYI, this is not a simple job, so if there are known fields to be edited, it's better to write code for these explicit fields instead of writing a generic action that will work for any field of any type.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

held69’s picture

Status: Closed (fixed) » Active
StatusFileSize
new13.73 KB

Sorry to open up this thread.

despite the combination of VBO, Data module and data_vbo i still dont get any operation select list to choose a operation from.
A full description of my problem can be found in the Data issue cue:
http://drupal.org/node/997594

Thanks

infojunkie’s picture

webform_submissions is a table created by Webform module, correct? If so, it will not be picked up by Data and therefore VBO will not pick it up either.

held69’s picture

thanks for your swift reply.

Using the webform_mysql_views-6.x-1.2 mentioned in this screencast:
http://nodeone.se/blogg/finally-webform-submission-data-in-views

webform tables can be picked up by Data.

As for the view i created, i can filter out all the webform submitted data without any problem.

As soon as i pick VBO as style in my view i get a checkbox in front of all my results as well.
Only the selectlist to pick out any operations is not available.

luthien’s picture

I'm experiencing the same problem (http://drupal.org/node/1041510) but I'm using tw, not the data module. The differences between data and tw module were explained here (http://drupal.org/node/580650).

infojunkie’s picture

Re #17: I understand. Not sure how Data deals with adopted tables, I will need to dig deeper in it.
Re #18: Table Wizard is not supported by VBO. Feel free to create a new feature request but I doubt I will get to it any time soon.

held69’s picture

Thanks sofar...

gepeto’s picture

Hi!

Did you find a solution to this issue? I am facing exactly the same problem as held69.

Thank you in advanced

infojunkie’s picture

Version: 6.x-1.10 » 6.x-1.x-dev

@gepeto: I tested the latest dev with an adopted table and received some PHP warnings, but the actions were not empty. I committed a fix to avoid the warnings, so please try it and let me know.

gepeto’s picture

@infojunkie I have tried it, but I'm still getting a blank list there

Cheers

gepeto’s picture

I want a view of webform submissions with bulk operations (delete), any clue how to achieve this????

infojunkie’s picture

@gepeto, you need to make sure that data_vbo.module::data_vbo_views_bulk_operations_object_info() gets called and senses your webform submissions table. For example, insert the line

dsm($object_info);

just before the line

return $object_info;

and make sure to have Devel module turned on. What does it print out?

gepeto’s picture

@infojunkie

It gives some warning now:
warning: htmlspecialchars() expects parameter 1 to be string, object given in /home/gener/workspace/elior/sites/all/modules/devel/krumo/class.krumo.php on line 1041.

*
... (Array, 1 element)
o
webform_views_work_with_elior (Array, 5 elements)
+
type (String, 4 characters ) data
+
base_table (String, 29 characters ) webform_views_work_with_elior
+
load (Array, 2 elements) | (Callback) ::load();
#
0 (Object) DataViewsBulkOperationsHelper
*
table_name (String, 29 characters ) webform_views_work_with_elior
#
1 (String, 4 characters ) load
+
oid (NULL)
+
title (NULL)
*
Krumo version 0.2a
| http://krumo.sourceforge.net
Called from /home/gener/workspace/elior/sites/all/modules/data_vbo/data_vbo.module, line 38

Any hints? Is the array coming from the adopted table, how to get the string it needs.

Thank you in advanced

infojunkie’s picture

Status: Active » Fixed

The problem is that the table webform_views_work_with_elior does not have a primary key. Therefore VBO cannot load records from it. To fix this, you need to specify one of the table columns as being the primary key, both in the database and in the Drupal schema.

gepeto’s picture

Oh Thank you, will try this.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sdsheridan’s picture

Status: Closed (fixed) » Active

Problem is that webform_view_ is based on a MySQL view, not a table, and so doesn't have a primary key. I ran into problems using a webform view for the basis of a bulk mailing because VBO makes assumptions that everything coming from the data module is a table, but it's not. I had to hack a bit of the code in the VBO.module to take care of the case where $object->{$object_info['title']} was not set to permit mass eMails to webform submission eMails. Not sure exactly where this should be addressed, as there are many layers, but not a lot of hooks to 'fix' things for an underlying SQL view as the base data table... There is of course hook_schema_alter, and I tried that in webform_mysql_views, but that didn't get me anywhere, really, and using hook__views_bulk_operations_object_info_alter wasn't enough to provide information for the load function...

sdsheridan’s picture

May have found the simplest workaround after pouring through some code... a slight change to the data module. See https://drupal.org/node/889306 .

Shawn

bojanz’s picture

Status: Active » Closed (fixed)

Closing old issue again, you opened a new one anyway.