Bulk Operation
/**
* Implements hook_action_info().
*/
function spaint_user_action_info() {
return array(
'spaint_user_modify_action' => array(
'type' => 'entity',
'label' => t('Remind user about Application'),
'behavior' => array('changes_property'),
'configurable' => FALSE,
'vbo_configurable' => TRUE,
'triggers' => array('any'),
),
);
}
function spaint_user_modify_action_form($settings, $entityType) {
$form['message'] = array(
'#title' => t('Enter message'),
'#type' => 'textfield',
'#description' => t('Enter a message to send to users'),
'#default_value' => t('Don\'t forget about us'),
);
return $form;
}
function spaint_user_modify_action_submit($form, &$form_state) {
$message = $form_state['values']['message'];
$operations = array();
foreach ($form_state['selection'] as $uid) {
$operations[] = array('spaint_user_sent_push', array($uid, $message));
}
$batch = array(
'operations' => $operations,
'finished' => 'spaint_user_batch_sent_push_finished',
'title' => t('Changing status...'),
'init_message' => t('Initializing.'),
'progress_message' => t('Completed @current of @total.'),
'error_message' => t('An error has occurred.'),
);
batch_set($batch);
}
/**
* Callback change status promocodes. Calling inner batch.
*/
function spaint_user_sent_push($uid, $message) {
$query = db_select('push_notifications_tokens', 't');
$query->fields('t', array('token'));
$query->condition('t.uid', $uid);
$result = $query->execute()->fetchAll();
if (!empty($result)) {
$payload['alert'] = "{\"header\":\"Silk Paints\",\"message\":\"$message\"}";
push_notifications_gcm_send_message(array(reset($result)->token), $payload);
}
}