You are here

total_control_workflow.module in Total Control Admin Dashboard 6

File

total_control_workflow.module
View source
<?php

// default views for Total Control Workflow
include_once 'includes/total_control_workflow.default_views.inc';

/* 
 * Implementation of hook_perm
 * adds permissions for access to the total control dashboard
 */
function total_control_workflow_perm() {
  return array(
    'have total workflow control',
  );
}

/**
 * Implementation of hook_ctools_plugin_dierctory() to let the system know
 * we implement task and task_handler plugins.
 */
function total_control_workflow_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools') {
    return 'plugins_workflow/' . $plugin;
  }
}

/**
 * Implementation of hook_menu_alter
 * Change menu tab weights?
 */
function total_control_workflow_menu_alter(&$items) {
  $states = workflow_get_states();

  // these are in the order we want
  $count = 1;
  foreach ($states as $sid => $state_name) {
    $num = db_result(db_query("SELECT count(*) FROM {workflow_node} WHERE sid = %d", $sid));
    $items['admin/dashboard/workflow/' . $sid]['weight'] = $count;
    $items['admin/dashboard/workflow/' . $sid]['title'] = $items['admin/dashboard/workflow/' . $sid]['title'] . ' (' . $num . ')';
    $count++;
  }
}

/* 
 * Implementation of hook_form_alter
 * adds views adjustment handling when workflows are added or removed
 */
function total_control_workflow_form_alter(&$form, $form_state, $form_id) {
  if ('workflow_state_add_form' == $form_id) {
    $form['#submit'][] = '_total_control_workflow_views_add_display';
  }
  if ('workflow_state_delete_form' == $form_id) {
    $form['#submit'][] = '_total_control_workflow_views_delete_display';
  }
}

/* Helper function.  Adds view display. Tab weight based on state weight. */
function _total_control_workflow_views_add_display($form, &$form_state) {

  // gather the workflow info we'll need
  $sid = $form_state['values']['sid'];
  $weight = $form_state['values']['weight'];
  $state = $form_state['values']['state'];

  // get the view
  $view = views_get_view('control_workflow');
  if ($form['sid']['#value']) {

    // if we're updating... we'll just need to adjust the menu tab weights
    menu_rebuild();
  }
  else {

    // if we're creating a new state...
    // create a new the panel pane display
    $handler = $view
      ->new_display('panel_pane', 'Pane: ' . $state, 'panel_pane_tcw_sid_' . $sid);
    $handler
      ->override_option('filters', array(
      'sid' => array(
        'operator' => 'in',
        'value' => array(
          $sid => $sid,
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => 'sid_op',
          'label' => 'Current State',
          'use_operator' => 0,
          'identifier' => 'sid',
          'optional' => 1,
          'single' => 1,
          'remember' => 0,
          'reduce' => 0,
        ),
        'id' => 'sid',
        'table' => 'workflow_node',
        'field' => 'sid',
        'relationship' => 'none',
        'override' => array(
          'button' => 'Use default',
        ),
      ),
    ));
    $handler
      ->override_option('title', $state . ' Summary');
    $handler
      ->override_option('pane_title', 'State: ' . $state);
    $handler
      ->override_option('pane_description', t('Items in state: ') . $state);
    $handler
      ->override_option('pane_category', array(
      'name' => 'Admin Dashboard',
      'weight' => '0',
    ));
    $handler
      ->override_option('allow', array(
      'use_pager' => FALSE,
      'items_per_page' => FALSE,
      'offset' => FALSE,
      'link_to_view' => FALSE,
      'more_link' => FALSE,
      'path_override' => FALSE,
      'title_override' => FALSE,
      'exposed_form' => FALSE,
    ));
    $handler
      ->override_option('argument_input', array());
    $handler
      ->override_option('link_to_view', 0);
    $handler
      ->override_option('inherit_panels_path', 0);

    // create a panel pane
    $handler = $view
      ->new_display('page', 'Page: ' . $state, 'page_tcw_sid_' . $sid);
    $handler
      ->override_option('fields', array(
      'title' => array(
        'label' => '',
        'alter' => array(
          'alter_text' => 0,
          'text' => '',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'link_to_node' => 1,
        'exclude' => 0,
        'id' => 'title',
        'table' => 'node',
        'field' => 'title',
        'relationship' => 'none',
        'override' => array(
          'button' => 'Override',
        ),
      ),
      'name' => array(
        'label' => 'Author',
        'alter' => array(
          'alter_text' => 0,
          'text' => '',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'link_to_user' => 1,
        'overwrite_anonymous' => 0,
        'anonymous_text' => '',
        'exclude' => 0,
        'id' => 'name',
        'table' => 'users',
        'field' => 'name',
        'override' => array(
          'button' => 'Use default',
        ),
        'relationship' => 'none',
      ),
      'sid_1' => array(
        'label' => '',
        'alter' => array(
          'alter_text' => 0,
          'text' => '',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'exclude' => 0,
        'id' => 'sid_1',
        'table' => 'workflow_node_history',
        'field' => 'sid',
        'relationship' => 'none',
      ),
      'sid' => array(
        'label' => '',
        'alter' => array(
          'alter_text' => 1,
          'text' => '-> [sid]',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'exclude' => 0,
        'id' => 'sid',
        'table' => 'workflow_node',
        'field' => 'sid',
        'relationship' => 'none',
      ),
      'stamp' => array(
        'label' => '',
        'alter' => array(
          'alter_text' => 1,
          'text' => '@ [stamp]',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'date_format' => 'small',
        'custom_date_format' => '',
        'exclude' => 0,
        'id' => 'stamp',
        'table' => 'workflow_node_history',
        'field' => 'stamp',
        'relationship' => 'none',
      ),
      'edit_node' => array(
        'label' => 'Edit',
        'alter' => array(
          'alter_text' => 0,
          'text' => '',
          'make_link' => 0,
          'path' => '',
          'alt' => '',
          'prefix' => '',
          'suffix' => '',
          'help' => '',
          'trim' => 0,
          'max_length' => '',
          'word_boundary' => 1,
          'ellipsis' => 1,
          'strip_tags' => 0,
          'html' => 0,
        ),
        'text' => 'edit',
        'exclude' => 0,
        'id' => 'edit_node',
        'table' => 'node',
        'field' => 'edit_node',
        'override' => array(
          'button' => 'Use default',
        ),
        'relationship' => 'none',
      ),
    ));
    $handler
      ->override_option('filters', array(
      'sid' => array(
        'operator' => 'in',
        'value' => array(
          $sid => $sid,
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => 'sid_op',
          'label' => 'Current State',
          'use_operator' => 0,
          'identifier' => 'sid',
          'optional' => 1,
          'single' => 1,
          'remember' => 0,
          'reduce' => 0,
        ),
        'id' => 'sid',
        'table' => 'workflow_node',
        'field' => 'sid',
        'relationship' => 'none',
        'override' => array(
          'button' => 'Use default',
        ),
      ),
      'type' => array(
        'operator' => 'in',
        'value' => array(),
        'group' => '0',
        'exposed' => TRUE,
        'expose' => array(
          'use_operator' => 0,
          'operator' => 'type_op',
          'identifier' => 'type',
          'label' => 'Content Type',
          'optional' => 1,
          'single' => 1,
          'remember' => 0,
          'reduce' => 0,
        ),
        'id' => 'type',
        'table' => 'node',
        'field' => 'type',
        'relationship' => 'none',
      ),
      'keys' => array(
        'operator' => 'optional',
        'value' => '',
        'group' => '0',
        'exposed' => TRUE,
        'expose' => array(
          'use_operator' => 0,
          'operator' => 'keys_op',
          'identifier' => 'keys',
          'label' => 'Search:',
          'optional' => 1,
          'remember' => 0,
        ),
        'id' => 'keys',
        'table' => 'search_index',
        'field' => 'keys',
        'relationship' => 'none',
      ),
      'uid' => array(
        'operator' => 'in',
        'value' => '',
        'group' => '0',
        'exposed' => TRUE,
        'expose' => array(
          'use_operator' => 0,
          'operator' => 'uid_op',
          'identifier' => 'uid',
          'label' => 'Author',
          'optional' => 1,
          'remember' => 0,
          'reduce' => 0,
        ),
        'id' => 'uid',
        'table' => 'users',
        'field' => 'uid',
        'relationship' => 'none',
      ),
    ));
    $handler
      ->override_option('title', 'state page');
    $handler
      ->override_option('items_per_page', 30);
    $handler
      ->override_option('style_plugin', 'table');
    $handler
      ->override_option('style_options', array(
      'grouping' => '',
      'override' => 1,
      'sticky' => 0,
      'order' => 'asc',
      'columns' => array(
        'title' => 'title',
        'sid_1' => 'sid_1',
        'sid' => 'sid',
        'stamp' => 'stamp',
      ),
      'info' => array(
        'title' => array(
          'sortable' => 1,
          'separator' => '',
        ),
        'sid_1' => array(
          'sortable' => 1,
          'separator' => '',
        ),
        'sid' => array(
          'sortable' => 0,
          'separator' => '',
        ),
        'stamp' => array(
          'sortable' => 1,
          'separator' => '',
        ),
      ),
      'default' => '-1',
    ));
    $handler
      ->override_option('path', 'admin/dashboard/workflow/' . $sid);
    $handler
      ->override_option('menu', array(
      'type' => 'tab',
      'title' => $state,
      'description' => '',
      'weight' => '0',
      'name' => 'navigation',
    ));
    $handler
      ->override_option('tab_options', array(
      'type' => 'none',
      'title' => '',
      'description' => '',
      'weight' => 0,
    ));
  }

  // save the view
  $view
    ->save();

  // update the menu tab weights
  menu_rebuild();
  return;
}

/* Helper function.  Removes view display. */
function _total_control_workflow_views_delete_display($form, &$form_state) {
  $sid = $form_state['values']['sid'];

  // get the view
  $view = views_get_view('control_workflow');

  // delete the corresponding display
  unset($view->display['panel_pane_tcw_sid_' . $sid]);

  // save the view
  $view
    ->save();
  return;
}

Functions

Namesort descending Description
total_control_workflow_ctools_plugin_directory Implementation of hook_ctools_plugin_dierctory() to let the system know we implement task and task_handler plugins.
total_control_workflow_form_alter
total_control_workflow_menu_alter Implementation of hook_menu_alter Change menu tab weights?
total_control_workflow_perm
_total_control_workflow_views_add_display
_total_control_workflow_views_delete_display