You are here

spaces_casetracker.module in Spaces 5.2

Same filename and directory in other branches
  1. 5 spaces_casetracker/spaces_casetracker.module

File

spaces_casetracker/spaces_casetracker.module
View source
<?php

/**
 * Implementation of hook_menu()
 */
function spaces_casetracker_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'spaces/team/autocomplete',
      'title' => t('Group Members'),
      'callback' => 'spaces_casetracker_users_autocomplete',
      'access' => user_access('access case tracker'),
      'type' => MENU_CALLBACK,
    );
  }
  return $items;
}

/**
 * Implementation of hook_help()
 */
function spaces_casetracker_help($page) {
  if (context_get('spaces', 'feature') == 'casetracker') {
    if (strpos('node/add', $page) === 0) {
    }
    else {
      return "<p>" . t('The casetracker allows you to file tickets for other team members and keep track of tasks that others have filed for you.') . "</p>";
    }
  }
}

/**
 * Implementation of hook_block()
 */
function spaces_casetracker_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks = array();
    $blocks[1]['info'] = t('Spaces: User Casetracker Stats');
    return $blocks;
  }
  else {
    if ($op == 'view') {
      switch ($delta) {
        case 1:
          $u = (object) array(
            'uid' => arg(1),
          );
          $u = user_load($u);
          $space = spaces_get_space();
          $block['subject'] = t('Case Stats for @user', array(
            '@user' => $u->name,
          ));
          $block['content'] = theme('spaces_casestats', spaces_casetracker_case_stats(arg(1), $space->sid), $u->name);
          return $block;
      }
    }
  }
}

/**
 * Implementation of hook_form_alter()
 */
function spaces_casetracker_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'casetracker_basic_case_node_form':
    case 'comment_form':

      // Implement batch creation
      if ($form_id == 'casetracker_basic_case_node_form') {
        $form['batch'] = array(
          '#type' => 'submit',
          '#value' => t('Submit + create another'),
          '#weight' => 50,
        );
        $form['#submit']['_spaces_casetracker_node_form_submit'] = array();
        array_reverse($form['#submit']);
      }
      $space = spaces_get_space();

      // Remove disallowed projects.
      if (isset($form['casetracker_project_information'])) {
        $pid = $form_id == 'casetracker_basic_case_node_form' ? 'pid' : 'prid';

        // "sigh." see casetracker_form_alter() for details.
        if (is_array($form['casetracker_project_information'][$pid]['#options'])) {
          foreach ($form['casetracker_project_information'][$pid]['#options'] as $key => $value) {
            $node = array(
              'nid' => $key,
              'type' => 'casetracker_basic_project',
            );
            $groups = og_get_node_groups((object) $node);
            if (!array_key_exists($space->sid, $groups)) {
              unset($form['casetracker_project_information'][$pid]['#options'][$key]);
            }
          }
        }
      }

      // Change the autocomplete callback to limit by group
      $form['casetracker_case_information']['assign_to']['#autocomplete_path'] = 'spaces/team/autocomplete/' . $space->sid;
      break;

    // Views filters
    // Handle exposed casetracker filters, sadly case tracker is dumb to og.
    case 'views_filters':
      switch ($form['#view_name']) {
        case 'spaces_cases_my':
        case 'spaces_cases_byproject':
        case 'spaces_cases_bycreated':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_project_options();
          break;
        case 'spaces_cases_byuser':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_user_options();
          break;
        case 'spaces_cases_filter':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_project_options();
          unset($form['filter1']['#options']);
          $form['filter1']['#options'] = spaces_casetracker_user_options();
          break;
      }
      break;
  }
}

/**
 * Custom submit handler for case node form for handling prepopulate &
 * batch creation
 */
function _spaces_casetracker_node_form_submit($form_id, $form_values) {
  if (trim($form_values['op']) == t('Submit + create another')) {
    $query = array();
    if (module_exists('prepopulate')) {
      if (isset($form_values['assign_to'])) {
        $query[] = 'edit[casetracker_case_information][assign_to]=' . $form_values['assign_to'];
      }
      if (isset($form_values['pid'])) {
        $query[] = 'edit[casetracker_project_information][pid]=' . $form_values['pid'];
      }
    }
    $query = implode('&', $query);
    drupal_goto('node/add/casetracker-basic-case', $query);
  }
}

/**
 *  Implementation of hook_default_views
 */
function spaces_casetracker_views_default_views() {
  $default_views = array(
    '_spaces_casetracker_views_cases',
    '_spaces_casetracker_views_cases_recent',
    '_spaces_casetracker_views_cases_bystatus',
    '_spaces_casetracker_views_cases_byuser',
    '_spaces_casetracker_views_cases_byproject',
    '_spaces_casetracker_views_cases_my',
    '_spaces_casetracker_views_cases_myblock',
    '_spaces_casetracker_views_cases_mycreated',
    '_spaces_casetracker_views_cases_filter',
    '_spaces_casetracker_views_cases_projects',
  );
  if (module_exists('spaces_user')) {
    $default_views[] = '_spaces_casetracker_views_user_cases';
    $default_views[] = '_spaces_casetracker_views_user_cases_created';
  }
  foreach ($default_views as $v) {
    $view = call_user_func($v);
    if (is_object($view) && $view->name) {
      $views[$view->name] = $view;
    }
  }
  return $views;
}

/**
 * hook_context_define()
 */
function spaces_casetracker_context_define() {
  $items = array();
  $items[] = array(
    'namespace' => 'spaces',
    'attribute' => 'feature',
    'value' => 'casetracker',
    'node' => array(
      'casetracker_basic_case',
      'casetracker_basic_project',
    ),
    'views' => _spaces_casetracker_views(),
    'block' => array(
      array(
        'module' => 'views',
        'delta' => 'spaces_cases_myblock',
        'region' => 'right',
        'weight' => -11,
      ),
    ),
    'spaces' => array(
      'label' => t('Casetracker'),
      'description' => t('A casetracker for managing projects.'),
      'types' => array(
        'og',
      ),
      'menu' => array(
        'cases' => array(
          'title' => t('Casetracker'),
        ),
        'cases/my' => array(
          'title' => t('My cases'),
        ),
        'cases/mycreated' => array(
          'title' => t('Created by me'),
        ),
        'cases/projects' => array(
          'title' => t('Projects'),
        ),
        'cases/filter' => array(
          'title' => t('Cases filter'),
        ),
        'cases/by-status' => array(
          'title' => t('Cases by status'),
        ),
        'cases/by-project' => array(
          'title' => t('Cases by project'),
        ),
        'cases/by-user' => array(
          'title' => t('Cases by user'),
        ),
      ),
    ),
  );
  if (module_exists('spaces_user')) {
    $items[] = array(
      'namespace' => 'spaces',
      'attribute' => 'feature',
      'value' => 'user_cases',
      'node' => array(
        'casetracker_basic_case',
      ),
      'views' => array(
        'spaces_user_cases',
        'spaces_user_cases_created',
      ),
      'block' => array(),
      'spaces' => array(
        'label' => t('Cases'),
        'description' => t('Shows cases authored by and assigned to a user.'),
        'types' => array(
          'user',
        ),
        'menu' => array(
          'user-cases' => array(
            'title' => t('Cases'),
          ),
          'user-cases/created' => array(
            'title' => t('Created cases'),
          ),
        ),
      ),
    );
  }
  return $items;
}
function _spaces_casetracker_views() {
  return array(
    'spaces_cases',
    'spaces_cases_my',
    'spaces_cases_mycreated',
    'spaces_cases_bystatus',
    'spaces_cases_byuser',
    'spaces_cases_byproject',
    'spaces_cases_filter',
    'spaces_cases_recent',
    'spaces_cases_projects',
    'spaces_cases_myblock',
  );
}

/**
 * Implementation of hook_views_pre_query()
 */
function spaces_casetracker_views_pre_query(&$view) {

  // Switch the assigned to filter to the userspace
  if ($view->name == 'spaces_user_cases') {
    $space = spaces_get_space();
    if ($space && $space->type == 'user') {
      foreach ($view->filter as $k => $filter) {
        if ($filter['field'] == 'casetracker_case.assign_to') {
          $view->filter[$k]['value'] = array(
            $space->sid,
          );
          $view->is_cacheable = false;
          break;
        }
      }
    }
  }
}

/**
 * Implementation of hook_views_post_view()
 */
function spaces_casetracker_views_post_view(&$view) {
  if ($view->build_type == 'page' && in_array($view->name, _spaces_casetracker_views())) {
    context_set('theme', 'layout', 'wide');
  }
}

/**
 * Build option array of project id's for the current group.
 */
function spaces_casetracker_project_options() {
  if ($space = spaces_get_space()) {
    $return = array();
    $results = db_query(db_rewrite_sql("SELECT ct.project_number, n.title FROM {node} n INNER JOIN {casetracker_project} ct ON n.nid = ct.nid INNER JOIN {og_ancestry} og ON n.nid = og.nid WHERE n.type IN (" . str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array(
      'casetracker_basic_project',
    )))) * 5 - 1, "'%s',") . ") AND og.group_nid = %d AND n.status = 1 ORDER BY n.title"), array_merge(array_filter(variable_get('casetracker_project_node_types', array(
      'casetracker_basic_project',
    ))), array(
      $space->sid,
    )));
    while ($row = db_fetch_object($results)) {
      $return[$row->project_number] = $row->project_number . " - " . $row->title;
    }
    return $return;
  }
}

/**
 * Build option array of users in the current group
 */
function spaces_casetracker_user_options() {
  $users = array();
  foreach (spaces_og_get_users() as $account) {
    $users[$account->uid] = $account->name;
  }
  return $users;
}

/**
 * Autocomplete callback.  This should be moved into casetracker eventually.
 */
function spaces_casetracker_users_autocomplete($gid, $string) {
  $matches = array();
  $result = db_query_range("SELECT name FROM {users} u INNER JOIN {og_uid} og ON u.uid = og.uid WHERE og.nid = %d AND LOWER(u.name) LIKE LOWER('%s%%')", $gid, $string, 0, 10);
  while ($user = db_fetch_object($result)) {
    $matches[$user->name] = check_plain($user->name);
  }
  print drupal_to_js($matches);
  exit;
}

/**
 * Casetracker: produce case stats for a user.
 */
function spaces_casetracker_case_stats($uid, $gid = NULL) {
  $status_closed = 7;
  $status_open = 6;
  $week = time() - 7 * 24 * 3600;
  $args = array();

  // ASSIGNED
  if ($gid) {
    $args[] = $gid;
    $q = "SELECT COUNT(c.nid) AS count FROM {casetracker_case} c INNER JOIN {og_ancestry} og ON c.nid = og.nid WHERE og.group_nid = %d AND c.case_status_id = %d AND c.assign_to = %d";
  }
  else {
    $q = "SELECT COUNT(nid) AS count FROM {casetracker_case} WHERE case_status_id = %d AND assign_to = %d";
  }
  $stats['assigned']['total_open'] = db_result(db_query($q, array_merge($args, array(
    $status_open,
    $uid,
  ))));
  $stats['assigned']['total_closed'] = db_result(db_query($q, array_merge($args, array(
    $status_closed,
    $uid,
  ))));
  if ($gid) {
    $q = "SELECT COUNT(c.nid) AS count FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {og_ancestry} og ON c.nid = og.nid WHERE og.group_nid = %d AND c.case_status_id = %d AND c.assign_to = %d AND n.created > %d";
  }
  else {
    $q = "SELECT COUNT(c.nid) AS count FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.case_status_id = %d AND c.assign_to = %d AND n.created > %d";
  }
  $stats['assigned']['week_open'] = db_result(db_query($q, array_merge($args, array(
    $status_open,
    $uid,
    $week,
  ))));
  $stats['assigned']['week_closed'] = db_result(db_query($q, array_merge($args, array(
    $status_closed,
    $uid,
    $week,
  ))));

  // CREATED
  if ($gid) {
    $q = "SELECT COUNT(c.nid) AS count FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {og_ancestry} og ON c.nid = og.nid WHERE og.group_nid = %d AND c.case_status_id = %d AND n.uid = %d";
  }
  else {
    $q = "SELECT COUNT(c.nid) AS count FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.case_status_id = %d AND n.uid = %d";
  }
  $stats['created']['total_open'] = db_result(db_query($q, array_merge($args, array(
    $status_open,
    $uid,
  ))));
  $stats['created']['total_closed'] = db_result(db_query($q, array_merge($args, array(
    $status_closed,
    $uid,
  ))));
  $q .= " AND n.created > %d";
  $stats['created']['week_open'] = db_result(db_query($q, array_merge($args, array(
    $status_open,
    $uid,
    $week,
  ))));
  $stats['created']['week_closed'] = db_result(db_query($q, array_merge($args, array(
    $status_closed,
    $uid,
    $week,
  ))));
  if ($gid) {
    $q = "SELECT COUNT(c.case_type_id) AS count, cs.case_state_name AS name FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {casetracker_case_states} cs ON c.case_type_id = cs.csid INNER JOIN {og_ancestry} og ON c.nid = og.nid WHERE og.group_nid = %d AND n.uid = %d GROUP BY c.case_type_id";
  }
  else {
    $q = "SELECT COUNT(c.case_type_id) AS count, cs.case_state_name AS name FROM {casetracker_case} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {casetracker_case_states} cs ON c.case_type_id = cs.csid WHERE n.uid = %d GROUP BY c.case_type_id";
  }
  $result = db_query($q, array_merge($args, array(
    $uid,
  )));
  while ($type = db_fetch_array($result)) {
    $stats['created']['breakdown'][$type['name']] = $type['count'];
  }
  return $stats;
}

/*
 *  Theme out casestat counts
 */
function _spaces_casestats_count($label, $count) {
  $class = strtolower($label);
  return "<span class='count {$class}'>{$count}</span><span class='label'>{$label}</span>";
}

/*
 *  Theme out casestats
 */
function theme_spaces_casestats($stats, $username) {
  drupal_add_css(drupal_get_path('module', 'spaces') . '/spaces.css');
  $labels = array(
    array(
      'data' => t('Assigned to !user', array(
        '!user' => $username,
      )),
      'colspan' => 2,
      'class' => 'halfpoint',
    ),
    array(
      'data' => t('Created by !user', array(
        '!user' => $username,
      )),
      'colspan' => 2,
    ),
  );
  $rows[] = array(
    array(
      'data' => t('This Week'),
      'colspan' => 2,
      'class' => 'header halfpoint',
    ),
    array(
      'data' => t('This Week'),
      'colspan' => 2,
      'class' => 'header',
    ),
  );
  $rows[] = array(
    _spaces_casestats_count(t('Open'), $stats['assigned']['week_open']),
    array(
      'data' => _spaces_casestats_count(t('Closed'), $stats['assigned']['week_closed']),
      'class' => 'halfpoint',
    ),
    _spaces_casestats_count(t('Open'), $stats['created']['week_open']),
    _spaces_casestats_count(t('Closed'), $stats['created']['week_closed']),
  );
  $rows[] = array(
    array(
      'data' => t('Total'),
      'colspan' => 2,
      'class' => 'header halfpoint',
    ),
    array(
      'data' => t('Total'),
      'colspan' => 2,
      'class' => 'header',
    ),
  );
  $rows[] = array(
    _spaces_casestats_count(t('Open'), $stats['assigned']['total_open']),
    array(
      'data' => _spaces_casestats_count(t('Closed'), $stats['assigned']['total_closed']),
      'class' => 'halfpoint',
    ),
    _spaces_casestats_count(t('Open'), $stats['created']['total_open']),
    _spaces_casestats_count(t('Closed'), $stats['created']['total_closed']),
  );
  $o = theme('table', $labels, $rows, array(
    'class' => 'casestats',
  ));

  /*** Breakdown ***/
  if ($stats['created']['breakdown']) {
    $total = array_sum($stats['created']['breakdown']);
    foreach ($stats['created']['breakdown'] as $label => $count) {
      $pct = floor($count / $total * 1000) * 0.1;
      $breakdown[] = "<span class='pct'>{$pct}%</span> " . t('in') . " {$label}";
    }
    $breakdown = implode(', ', $breakdown) . ".";
    $breakdown = "<div class='case-breakdown'><span class='label'>" . t('Cases created:') . "</span>{$breakdown}</div>";
  }
  return $o . $breakdown;
}

/* VIEWS */
function _spaces_casetracker_views_base() {
  $view = new stdClass();
  $view->access = array();
  $view->view_args_php = '';
  $view->menu = FALSE;
  $view->page = TRUE;
  $view->page_empty = '<?php print _spaces_views_empty("casetracker"); ?>';
  $view->page_empty_format = '2';
  $view->page_type = 'table';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '50';
  $view->sort = array();
  $view->argument = array();
  $view->field = array(
    'project' => array(
      'tablename' => 'casetracker_case',
      'field' => 'pid',
      'label' => 'Project',
      'handler' => 'spaces_views_handler_crayon_name',
      'options' => 'casetracker',
      'sortable' => '1',
    ),
    'title' => array(
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    'status' => array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'label' => 'Status',
    ),
    'assigned' => array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'label' => 'Assigned',
      'sortable' => '1',
    ),
    'priority' => array(
      'tablename' => 'casetracker_case',
      'field' => 'case_priority_id',
      'label' => 'Priority',
      'sortable' => '1',
    ),
    'changed' => array(
      'tablename' => 'node',
      'field' => 'changed',
      'label' => 'Updated',
      'handler' => 'views_handler_field_date_small',
      'sortable' => '1',
      'defaultsort' => 'DESC',
    ),
  );
  $view->filter = array(
    'type' => array(
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => 'casetracker_basic_case',
      ),
    ),
    'status' => array(
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    'spaces' => array(
      'tablename' => 'spaces',
      'field' => 'type',
      'operator' => 'all',
      'options' => '',
      'value' => 'all',
    ),
  );
  $view->exposed_filter = array();
  $view->requires = array(
    node,
    casetracker_case,
  );
  return $view;
}
function _spaces_casetracker_views_cases() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases';
  $view->description = t('Spaces > Casetracker');
  $view->menu = TRUE;
  $view->menu_title = t('Cases');
  $view->page = TRUE;
  $view->page_title = t('Cases');
  $view->url = 'cases';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  return $view;
}
function _spaces_casetracker_views_cases_recent() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_recent';
  $view->description = t('Spaces > Casetracker > Recent cases');
  $view->page = TRUE;
  $view->page_title = t('Recent Cases');
  $view->url = 'recent-cases';
  $view->block = TRUE;
  $view->block_title = t('Recent Cases');
  $view->block_empty = "<p class='views-empty'>" . t('No recent cases.') . "</p>";
  $view->block_empty_format = '1';
  $view->block_type = 'spaces_datetitle';
  $view->nodes_per_block = '5';
  $view->sort = array(
    array(
      'tablename' => 'node',
      'field' => 'created',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->field = array(
    array(
      'tablename' => 'og_node_data',
      'field' => 'title',
      'label' => 'Group',
      'handler' => 'spaces_views_handler_crayon_name',
      'options' => 'og',
    ),
    array(
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Case',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array(
      'tablename' => 'node',
      'field' => 'created',
      'label' => 'Created On',
      'handler' => 'views_handler_field_since',
      'options' => 1,
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'label' => 'Assigned To',
    ),
  );
  $view->filter['og'] = array(
    'tablename' => 'og_uid_node',
    'field' => 'currentuid',
    'operator' => '=',
    'options' => '',
    'value' => '***CURRENT_USER***',
  );
  $view->filter['spaces']['operator'] = 'active';
  $view->filter['changed'] = array(
    'tablename' => 'node',
    'field' => 'changed',
    'operator' => '>',
    'options' => -1 * SPACES_ARCHIVE_TIMESTAMP,
    'value' => 'now',
  );
  $view->requires = array(
    node,
    casetracker_case,
    og_node_data,
    og_uid_node,
  );
  return $view;
}
function _spaces_casetracker_views_cases_bystatus() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_bystatus';
  $view->description = t('Filter cases by status.');
  $view->menu = TRUE;
  $view->menu_title = t('Cases by status');
  $view->page = TRUE;
  $view->page_title = t('Cases by status');
  $view->url = 'cases/by-status';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->filter['status_id'] = array(
    'tablename' => 'casetracker_case',
    'field' => 'case_status_id',
    'operator' => 'OR',
    'options' => '',
    'value' => array(
      0 => '6',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'label' => t('Status'),
      'optional' => '0',
      'is_default' => '1',
      'operator' => '1',
      'single' => '1',
    ),
  );
  return $view;
}
function _spaces_casetracker_views_cases_byuser() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_byuser';
  $view->description = t('Filter cases by user.');
  $view->menu = TRUE;
  $view->menu_title = t('Cases by user');
  $view->page = TRUE;
  $view->page_title = t('Cases by user');
  $view->url = 'cases/by-user';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->filter['assign'] = array(
    'tablename' => 'casetracker_case',
    'field' => 'assign_to',
    'operator' => 'OR',
    'options' => '',
    'value' => array(
      0 => '29',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'label' => 'User',
      'optional' => '0',
      'is_default' => '0',
      'operator' => '1',
      'single' => '1',
    ),
  );
  return $view;
}
function _spaces_casetracker_views_cases_my() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_my';
  $view->description = 'My cases';
  $view->menu = TRUE;
  $view->menu_title = t('My cases');
  $view->page = TRUE;
  $view->page_title = 'My cases';
  $view->page_type = 'table';
  $view->url = 'cases/my';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->filter['user'] = array(
    'tablename' => 'casetracker_case',
    'field' => 'assign_to_currentuid',
    'operator' => '=',
    'options' => '',
    'value' => '***CURRENT_USER***',
  );
  $view->filter['project'] = array(
    'tablename' => 'casetracker_project',
    'field' => 'project_number',
    'operator' => 'OR',
    'options' => '',
    'value' => array(
      0 => '100',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_project',
      'field' => 'project_number',
      'label' => 'Project',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '1',
    ),
  );
  return $view;
}
function _spaces_casetracker_views_cases_myblock() {
  $view = new stdClass();
  $view->name = 'spaces_cases_myblock';
  $view->description = t('Provides a block listing of cases assigned to current user.');
  $view->access = array();
  $view->view_args_php = '';
  $view->page = FALSE;
  $view->block = TRUE;
  $view->block_title = t('My Cases');
  $view->block_empty = "<p class='views-empty'>" . t('No cases found.') . "</p>";
  $view->block_empty_format = '2';
  $view->block_type = 'spaces_datetitle';
  $view->nodes_per_block = '10';
  $view->sort = array(
    array(
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->argument = array();
  $view->field = array(
    array(
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'label' => '',
      'handler' => 'views_handler_field_since',
      'options' => 1,
    ),
    array(
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array(
      'tablename' => 'users',
      'field' => 'name',
      'label' => t('Author'),
    ),
  );
  $view->filter = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to_currentuid',
      'operator' => '=',
      'options' => '',
      'value' => '***CURRENT_USER***',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '6',
        1 => '8',
        2 => '9',
        3 => '10',
      ),
    ),
    array(
      'tablename' => 'spaces',
      'field' => 'type',
      'operator' => 'all',
      'options' => '',
      'value' => 'all',
    ),
  );
  $view->exposed_filter = array();
  $view->requires = array(
    node_comment_statistics,
    node,
    casetracker_case,
  );
  return $view;
}
function _spaces_casetracker_views_cases_byproject() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_byproject';
  $view->description = t('Filter cases by project.');
  $view->menu = TRUE;
  $view->menu_title = t('Cases by project');
  $view->page = TRUE;
  $view->page_title = 'Cases by project';
  $view->url = 'cases/by-project';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->filter['project'] = array(
    'tablename' => 'casetracker_project',
    'field' => 'project_number',
    'operator' => 'OR',
    'options' => '',
    'value' => array(
      0 => '100',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_project',
      'field' => 'project_number',
      'label' => 'Project',
      'optional' => '0',
      'is_default' => '1',
      'operator' => '1',
      'single' => '1',
    ),
  );
  $view->requires = array(
    node,
    casetracker_case,
    casetracker_project,
  );
  return $view;
}
function _spaces_casetracker_views_cases_mycreated() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_cases_mycreated';
  $view->description = t('A view of all cases made by the current user.');
  $view->menu = TRUE;
  $view->menu_title = t('Created by me');
  $view->page = TRUE;
  $view->page_title = t('Created by me');
  $view->url = 'cases/mycreated';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->filter['user'] = array(
    'tablename' => 'node',
    'field' => 'currentuid',
    'operator' => '=',
    'options' => '',
    'value' => '***CURRENT_USER***',
  );
  $view->filter['project'] = array(
    'tablename' => 'casetracker_project',
    'field' => 'project_number',
    'operator' => 'OR',
    'options' => '',
    'value' => array(
      0 => '100',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_project',
      'field' => 'project_number',
      'label' => 'Project',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '1',
    ),
  );
  return $view;
}
function _spaces_casetracker_views_cases_filter() {
  $view = new stdClass();
  $view->name = 'spaces_cases_filter';
  $view->description = t('A massive case filter form.');
  $view->access = array();
  $view->view_args_php = '';
  $view->menu = TRUE;
  $view->menu_title = t('Cases filter');
  $view->page = TRUE;
  $view->page_title = t('Cases filter');
  $view->page_empty = '<?php print _spaces_views_empty("casetracker"); ?>';
  $view->page_empty_format = '2';
  $view->page_type = 'table';
  $view->url = 'cases/filter';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '100';
  $view->argument = array();
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->field = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'pid',
      'label' => 'Project',
      'handler' => 'spaces_views_handler_crayon_name',
      'options' => 'casetracker',
      'sortable' => '1',
    ),
    array(
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'label' => 'Status',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'label' => 'Assigned',
      'sortable' => '1',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_priority_id',
      'label' => 'Priority',
      'sortable' => '1',
    ),
    array(
      'tablename' => 'node',
      'field' => 'changed',
      'label' => 'Updated',
      'handler' => 'views_handler_field_date_small',
      'sortable' => '1',
      'defaultsort' => 'DESC',
    ),
  );
  $view->filter = array(
    array(
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => 'casetracker_basic_case',
      ),
    ),
    array(
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array(
      'tablename' => 'casetracker_project',
      'field' => 'project_number',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '100',
      ),
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '1',
      ),
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_type_id',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '11',
      ),
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_priority_id',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '1',
      ),
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => '6',
      ),
    ),
    array(
      'tablename' => 'spaces',
      'field' => 'type',
      'operator' => 'all',
      'options' => '',
      'value' => 'all',
    ),
  );
  $view->exposed_filter = array(
    array(
      'tablename' => 'casetracker_project',
      'field' => 'project_number',
      'label' => 'Project',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '0',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'assign_to',
      'label' => 'For',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '0',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_type_id',
      'label' => 'Type',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '0',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_priority_id',
      'label' => 'Priority',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '0',
    ),
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'label' => 'Status',
      'optional' => '1',
      'is_default' => '0',
      'operator' => '1',
      'single' => '0',
    ),
  );
  $view->requires = array(
    node,
    casetracker_case,
    casetracker_project,
  );
  return $view;
}
function _spaces_casetracker_views_cases_projects() {
  $view = new stdClass();
  $view->name = 'spaces_cases_projects';
  $view->description = t('A listing of all projects.');
  $view->access = array();
  $view->view_args_php = '';
  $view->menu = TRUE;
  $view->menu_title = t('Projects');
  $view->page = TRUE;
  $view->page_title = t('Projects');
  $view->page_empty = '<?php print _spaces_views_empty("casetracker"); ?>';
  $view->page_empty_format = '2';
  $view->page_type = 'table';
  $view->url = 'cases/projects';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '99';
  $view->argument = array();
  $view->sort = array(
    array(
      'tablename' => 'node',
      'field' => 'title',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->field = array(
    array(
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Project',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array(
      'tablename' => 'node',
      'field' => 'created',
      'label' => '',
      'handler' => 'views_handler_field_date_custom',
      'options' => 'F j, Y',
    ),
    array(
      'tablename' => 'casetracker_case_node',
      'field' => 'nid',
      'label' => '',
    ),
  );
  $view->filter = array(
    array(
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array(
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array(
        0 => 'casetracker_basic_project',
      ),
    ),
    array(
      'tablename' => 'spaces',
      'field' => 'type',
      'operator' => 'all',
      'options' => '',
      'value' => 'all',
    ),
  );
  $view->exposed_filter = array();
  $view->requires = array(
    node,
    casetracker_case_node,
  );
  return $view;
}
function _spaces_casetracker_views_user_cases() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_user_cases';
  $view->description = 'A view of all cases by date.';
  $view->page = TRUE;
  $view->page_title = 'Cases';
  $view->url = 'user-cases';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->filter['assign'] = array(
    'tablename' => 'casetracker_case',
    'field' => 'assign_to',
    'operator' => 'AND',
    'options' => '',
    'value' => array(
      0 => '1',
    ),
  );
  unset($view->filter['spaces']);
  return $view;
}
function _spaces_casetracker_views_user_cases_created() {
  $view = _spaces_casetracker_views_base();
  $view->name = 'spaces_user_cases_created';
  $view->description = 'A view of all cases by date.';
  $view->view_args_php = '
    $space = spaces_get_space();
      if ($space && $space->type == \'user\') {
        $view->page_title = t(\'Cases created by !user\', array(\'!user\' => $space->title));
      }
  ';
  $view->page = TRUE;
  $view->page_title = 'Cases created by';
  $view->url = 'user-cases/created';
  $view->sort = array(
    array(
      'tablename' => 'casetracker_case',
      'field' => 'case_status_id',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->requires = array(
    casetracker_case,
    node,
    spaces,
  );
  return $view;
}

Functions

Namesort descending Description
spaces_casetracker_block Implementation of hook_block()
spaces_casetracker_case_stats Casetracker: produce case stats for a user.
spaces_casetracker_context_define hook_context_define()
spaces_casetracker_form_alter Implementation of hook_form_alter()
spaces_casetracker_help Implementation of hook_help()
spaces_casetracker_menu Implementation of hook_menu()
spaces_casetracker_project_options Build option array of project id's for the current group.
spaces_casetracker_users_autocomplete Autocomplete callback. This should be moved into casetracker eventually.
spaces_casetracker_user_options Build option array of users in the current group
spaces_casetracker_views_default_views Implementation of hook_default_views
spaces_casetracker_views_post_view Implementation of hook_views_post_view()
spaces_casetracker_views_pre_query Implementation of hook_views_pre_query()
theme_spaces_casestats
_spaces_casestats_count
_spaces_casetracker_node_form_submit Custom submit handler for case node form for handling prepopulate & batch creation
_spaces_casetracker_views
_spaces_casetracker_views_base
_spaces_casetracker_views_cases
_spaces_casetracker_views_cases_byproject
_spaces_casetracker_views_cases_bystatus
_spaces_casetracker_views_cases_byuser
_spaces_casetracker_views_cases_filter
_spaces_casetracker_views_cases_my
_spaces_casetracker_views_cases_myblock
_spaces_casetracker_views_cases_mycreated
_spaces_casetracker_views_cases_projects
_spaces_casetracker_views_cases_recent
_spaces_casetracker_views_user_cases
_spaces_casetracker_views_user_cases_created