forked from grayside/casetracker_console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcasetracker_console.module
256 lines (237 loc) · 6.9 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
// $Id$
/**
* @file
* Casetracker Console module provides overview of Case Tracker Projects.
*/
include_once('casetracker_console.features.inc');
/**
* Implements hook_init()
*/
function casetracker_console_init() {
if (automodal_request_is_child()) {
drupal_add_css(drupal_get_path('module', 'casetracker_console') . '/fix_modal.css');
}
}
/**
* Implementation of hook_block().
*/
function casetracker_console_block($op = 'list', $delta = 0) {
switch ($op) {
case 'list':
$blocks['filters'] = array('info' => t('Atrium: Case Tracker Console filter'));
return $blocks;
case 'view':
return _casetracker_console_block_filters();
}
}
/**
* Filter block.
*/
function _casetracker_console_block_filters($set = '') {
static $filters;
if (!empty($set)) {
$filters = $set;
return;
}
if (!empty($filters)) {
return array('subject' => t('Filter results'), 'content' => $filters);
}
return array();
}
/**
* 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);
}
}
}
}
/**
* Preprocessor for theme('views_view').
*/
function casetracker_console_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->name == 'casetracker_console') {
// Whisk away exposed filter for display in a block
_casetracker_console_block_filters($vars['exposed']);
$vars['exposed'] = '';
}
}
/**
* 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 ($status > 0) {
$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) || $status == 0) {
$query['case_status_closed'] = 1;
}
}
if ($view->exposed_input['field_due_date_value']) {
$query['field_due_date_value[value]'] = $view->exposed_input['field_due_date_value']['value']['date'];
}
return l($value, 'casetracker/filter', array(
'query' => $query,
'attributes' => array('class' => 'automodal'),
'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']);
}
if (is_array($views['casetracker_console']->display['default']->display_options['fields']))
$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_filter_' . ++$increment;
$total['id'] = $total_id;
$views['casetracker_console']->display['default']->display_options['fields'][$total_id] = $total;
}
/**
* Implements hook_views_query_alter()
*/
function casetracker_console_views_query_alter(&$view, &$query) {
if ($view->name != 'casetracker_console')
return;
// Unset filters others than Case Tracker project, node published & spaces
// from $query object to prevent get empty results on view
$keys = array('0');
foreach ($query->where as $key => $value) {
if (!in_array($key, $keys)) {
$query->where_date = $query->where[$key];
unset($query->where[$key]);
}
}
}
/**
* 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_filter_' . $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_filter',
'relationship' => 'none',
);
}