You are here

function slickgrid_views_pre_view in Slickgrid 7

Same name and namespace in other branches
  1. 6 slickgrid.module \slickgrid_views_pre_view()
  2. 7.2 slickgrid.module \slickgrid_views_pre_view()

Implementation of hook_views_pre_view

Parameters

object $view :

Return value

void

File

./slickgrid.module, line 128

Code

function slickgrid_views_pre_view(&$view, $display_id) {
  global $user;
  if (isset($_POST['display_id'])) {
    $view->slickgrid_settings = slickgrid_get_settings(array(
      'uid' => $user->uid,
      'view_name' => $view->name,
      'display_id' => $_POST['display_id'],
    ));
  }

  // If there are hidden columns
  if (isset($view->slickgrid_settings['hidden_columns'])) {

    // Remove them from the exported file
    foreach ($view->slickgrid_settings['hidden_columns'] as $hidden_column) {
      $view
        ->set_item($display_id, 'field', $hidden_column, null);
    }
  }

  // If row selection checkboxes are enabled, allow users to only export selected nodes.
  if (isset($_POST['export_selected_rows']) && isset($_POST['entity_ids'])) {

    // Remove all existing arguments - we'll limit result set by entity ID only
    foreach ($view
      ->get_items('argument') as $id => $arg) {
      $view
        ->set_item($display_id, 'argument', $id, NULL);
    }

    // Add an argument to limit the view to only nids being updated
    $options = array(
      'table' => $view->base_table,
      'field' => $view->base_field,
      'break_phrase' => 1,
    );
    $view
      ->add_item($display_id, 'argument', $view->base_table, $view->base_field, $options);
    $view
      ->set_arguments(array(
      implode('+', $_POST['entity_ids']),
    ));
  }

  // Collapsible tree stuff
  $plugins = array();

  // Is this a slickgrid?
  if ($view->display_handler
    ->get_option('style_plugin') == 'slickgrid') {
    $style_options = $view->display_handler
      ->get_option('style_options');
    if (isset($style_options['columns'])) {
      foreach ($style_options['columns'] as $field_id => $column) {

        // Get all plugin types
        foreach (array_keys(slickgrid_get_plugin_types()) as $plugin_type) {

          // Has the plugin been set for this column?
          if (!empty($column[$plugin_type])) {
            if (!isset($plugins[$plugin_type])) {
              $plugins[$plugin_type] = slickgrid_get_plugins($plugin_type);
            }

            // Plugins can define callbacks for views+pre_view
            if (isset($plugins[$plugin_type][$column[$plugin_type]]['hooks']['views_pre_view'])) {

              //Load the plugin file if there's a callback function
              require_once DRUPAL_ROOT . '/' . $plugins[$plugin_type][$column[$plugin_type]]['path'] . '/' . $plugins[$plugin_type][$column[$plugin_type]]['file'];

              // Get & call the function
              $func = $plugins[$plugin_type][$column[$plugin_type]]['hooks']['views_pre_view'];
              $func($view, $field_id, $display_id);
            }
          }
        }
      }
    }
  }
}