-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcasetracker_console.module
182 lines (171 loc) · 4.95 KB
/
casetracker_console.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
// $Id$
/**
* @file
* Casetracker Console module provides overview of Case Tracker Projects.
*/
include_once('casetracker_console.features.inc');
/**
* Preprocessor for theme('views_view_table').
*/
function casetracker_console_preprocess_views_view_table(&$vars) {
$view = $vars['view'];
if ($view->name != 'casetracker_console') {
return;
}
drupal_add_css(drupal_get_path('module', 'casetracker_console') . '/casetracker_console.css');
foreach ($vars['rows'] as $key => $row) {
foreach ($row as $field => $value) {
if ($field != 'title') {
$vars['rows'][$key][$field] = _casetracker_console_listing_link($field, $value, $view->result[$key]->nid, $view);
}
}
}
}
/**
* Helper function to convert pure counts into a link to the main case listing.
*
* If I could find a way to approach this without a hard-coded dependency on
* how the casetracker_cases view has configured it's path and exposed filters,
* this would make a cool Views handler, or extension to the casetracker_count
* handler in CT core.
*
* @param $field
* The Views key for the field/column.
* @param $value
* The value of the field.
* @param $pid
* The project node id.
* @param $view
* The views object.
*
* @return
* Converting the value into a link to the casetracker case.
*/
function _casetracker_console_listing_link($field, $value, $pid, $view) {
static $inactive_states;
$status = $view->display['default']->display_options['fields'][$field]['type'];
$status = substr($status, -1);
$query = array('pid' => $pid);
if ($field != 'case_count_5') {
$query['case_status_id'] = $status;
}
if (module_exists('atrium_casetracker')) {
if (empty($inactive_states)) {
$inactive_states = atrium_casetracker_get_inactive_states();
}
if (in_array($status, $inactive_states)) {
$query['case_status_closed'] = 1;
}
}
return l($value, 'casetracker/filter', array(
'query' => $query,
'html' => TRUE,
));
}
/**
* Implementation of hook_context_default_contexts_alter().
*/
function casetracker_console_context_default_contexts_alter(&$contexts) {
if (module_exists('atrium_casetracker')) {
$contexts['casetracker_listing']->conditions['views']['values'][] = 'casetracker_console';
}
}
/**
* Implementation of hook_views_default_views_alter().
*/
function casetracker_console_views_default_views_alter(&$views) {
if (module_exists('atrium_casetracker')) {
_casetracker_console_spaces_filter($views['casetracker_console']);
_casetracker_console_spaces_access($views['casetracker_console']);
}
$total = array_pop($views['casetracker_console']->display['default']->display_options['fields']);
$statuses = casetracker_realm_load('status');
$increment = 0;
foreach ($statuses as $status => $label) {
_casetracker_console_add_column($status, $label, ++$increment, $views['casetracker_console']);
}
$total_id = 'case_count_' . ++$increment;
$total['id'] = $total_id;
$views['casetracker_console']->display['default']->display_options['fields'][$total_id] = $total;
}
/**
* Integrate a View with 'Spaces: Content in current space' filter.
*
* @param
* View object.
*/
function _casetracker_console_spaces_filter($view) {
$view->display['default']->display_options['filters']['current'] = array(
'operator' => 'all',
'value' => '',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'current',
'table' => 'spaces',
'field' => 'current',
'relationship' => 'none',
);
}
/**
* Integrate a View with the Spaces feature access handler.
*
* @param $view
* View object.
*/
function _casetracker_console_spaces_access($view) {
$view->display['default']->display_options['access'] = array(
'type' => 'spaces_feature',
'spaces_feature' => 'atrium_casetracker',
'perm' => 'access content',
);
}
/**
* Insert a case status column into the View.
*
* @param $state
* Case Tracker State ID.
* @param $label
* Human-readable label/name of the CT State.
* @param $increment
* The column counter, used to mark field indeces.
* @param $view
* The View object.
*/
function _casetracker_console_add_column($state, $label, $increment, $view) {
$id = 'case_count_' . $increment;
$view->display['default']->display_options['fields'][$id] = array(
'label' => $label,
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'type' => 'status-' . $state,
'exclude' => 0,
'id' => $id,
'table' => 'casetracker_case',
'field' => 'case_count',
'relationship' => 'none',
);
}