You are here

function _views_bulk_operations_direct_process in Views Bulk Operations (VBO) 6.3

Helper function for direct execution operations.

1 call to _views_bulk_operations_direct_process()
_views_bulk_operations_execute in ./views_bulk_operations.module
Helper function to execute the chosen action upon selected objects.

File

./views_bulk_operations.module, line 731
Allows operations to be performed on items selected in a view.

Code

function _views_bulk_operations_direct_process($view, $operation, $objects, $params, $object_info, &$context) {
  if ($operation['aggregate'] != VBO_AGGREGATE_FORBIDDEN) {
    if (isset($object_info['access'])) {
      foreach ($objects as $num => $row) {
        $oid = $row->{$view->base_field};
        $object = call_user_func($object_info['load'], $oid);
        if (!_views_bulk_operations_object_permission($operation, $object, $object_info)) {
          unset($objects[$num]);
          $context['results']['log'][] = t('Skipped %action on @type %title due to insufficient permissions.', array(
            '%action' => $operation['label'],
            '@type' => t($object_info['type']),
            '%title' => $object->{$object_info['title']},
          ));
          continue;
        }
        $oids[] = $oid;
      }
    }
    if (!empty($objects)) {
      _views_bulk_operations_action_aggregate_do($operation, $oids, $objects, $params, $object_info);
      $context['results']['log'][] = t('Performed aggregate %action on @types %oids.', array(
        '%action' => $operation['label'],
        '@types' => format_plural(count($objects), t($object_info['type']), t($object_info['type'] . 's')),
        '%oids' => implode(',', $oids),
      ));
      $context['results']['rows'] += count($objects);
    }
  }
  else {
    foreach ($objects as $num => $row) {
      $oid = $row->{$view->base_field};
      $object = call_user_func($object_info['load'], $oid);
      if (!_views_bulk_operations_object_permission($operation, $object, $object_info)) {
        $context['results']['log'][] = t('Skipped %action on @type %title due to insufficient permissions.', array(
          '%action' => $operation['label'],
          '@type' => t($object_info['type']),
          '%title' => $object->{$object_info['title']},
        ));
        continue;
      }
      _views_bulk_operations_action_do($operation, $oid, $object, $row, $params, $object_info);
      $context['results']['log'][] = t('Performed %action on @type %title.', array(
        '%action' => $operation['label'],
        '@type' => t($object_info['type']),
        '%title' => $object->{$object_info['title']},
      ));
      $context['results']['rows'] += 1;
    }
  }
}