-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaestro.views.inc
1668 lines (1537 loc) · 72.6 KB
/
maestro.views.inc
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* maestro.views.inc
* Contains all Views related API calls and default view creation information
*/
function maestro_views_data() {
$data = array();
$data['maestro_queue']['table']['group'] = t('Maestro');
$data['maestro_template_data']['table']['group'] = t('Maestro');
/* Table Definitions */
$data['maestro_project_content'] = array (
'table' => array(
'group' => t('Maestro'),
'join' => array(
'maestro_queue' => array(
'left_field' => 'id',
'field' => 'task_id',
),
),
),
'content_type' => array (
'title' => t('Content Type'),
'help' => t('Content Type as defined by the workflow template process variable'),
'field' => array (
'handler' => 'views_handler_field', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_content_type',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
'nid' => array (
'title' => t('Content Node ID'),
'help' => t('Node ID - links to node'),
'field' => array (
'handler' => 'views_handler_field', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
'tracking_id' => array (
'title' => t('Tracking ID'),
'help' => t('Workflow Instance or Project ID'),
'field' => array (
'handler' => 'views_handler_field', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
)
);
$data['maestro_template'] = array (
'table' => array(
'group' => t('Maestro'),
'join' => array(
'maestro_queue' => array(
'left_table' => 'maestro_template_data', // The template table joins via the template_data table to the queue table
'left_field' => 'template_id',
'field' => 'id',
),
),
),
'template_name' => array (
'title' => t('Template Name'),
'help' => t('Name of the Workflow Template'),
'field' => array (
'handler' => 'views_handler_field', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_templatename',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
);
$data['maestro_template_variables'] = array (
'table' => array(
'group' => t('Maestro'),
'join' => array(
'maestro_queue' => array(
'left_table' => 'maestro_template', // The template_variables table joins via the template table to the queue table
'left_field' => 'id',
'field' => 'template_id',
),
),
),
'variable_name' => array (
'real field' => 'variable_name',
'title' => t('Process Variable Name'),
'help' => t('Display single Process Variable Name'),
'field' => array (
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'maestro_handler_filter_process_variable',
),
),
'variable_names' => array (
'real field' => 'variable_name',
'title' => t('Process Variables'),
'help' => t('Displays all the Process Variables and their values'),
'field' => array (
'handler' => 'views_handler_field_maestro_process_variables', //using a custom field handler
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
);
$data['maestro_process'] = array (
'table' => array(
'group' => t('Maestro'),
'join' => array(
'maestro_queue' => array(
'left_field' => 'process_id',
'field' => 'id',
),
),
),
'id' => array (
'title' => t('Process Table Record ID'),
'help' => t('Unique Process Identifier'),
'field' => array (
'click sortable' => TRUE,
)
),
);
$data['maestro_process_variables'] = array (
'table' => array(
'group' => t('Maestro'),
'join' => array(
'maestro_queue' => array(
'left_field' => 'process_id',
'field' => 'process_id',
),
),
),
'template_variable_id' => array (
'title' => t('Template Variable ID'),
'help' => t('Variable ID'),
'field' => array (
'click sortable' => TRUE,
)
),
'variable_value' => array (
'title' => t('Process Variable Value'),
'help' => t('Process Variable value - use with Process Variable Name'),
'field' => array (
'handler' => 'views_handler_field_maestro_process_variable', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_variable_value',
),
),
);
// Workflow template tasks
$data['maestro_template_data']['table']['join'] = array( //this one allows the template data fields to be available in the queue table view
'maestro_queue' => array(
'left_field' => 'template_data_id',
'field' => 'id',
),
);
// Workflow Engine Queue
$data['maestro_queue']['table']['base'] = array(
'field' => 'id',
'title' => t('Maestro Queue'),
'help' => t("Queue holds all of the production data for tasks"),
'weight' => -11,
);
$data['users']['table']['join'] = array( //telling the users table that we're joined to it by uid
'maestro_queue' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
// Production Assignments - active tasks that and their assignment data
$data['maestro_production_assignments'] = array(
'table' => array(
'group' => t('Maestro'),
'join' => array( //telling the queue table that we're joined to it by taskID
'maestro_queue' => array(
'left_field' => 'id',
'field' => 'task_id',
),
),
),
'assign_id' => array (
'title' => t('Assignment Value'),
'help' => t('Production Assignment Record Value'),
'field' => array (
'click sortable' => TRUE,
)
),
);
// Views Field definitions
$data['maestro_template_data']['taskname'] = array(
'title' => t('Task Name'),
'help' => t('A Reference to the template data table'),
'field' => array(
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_taskname',
),
);
$data['maestro_queue']['assigned_users'] = array(
'real field' => 'id', // Need to pass in the queue_id to the handler
'title' => t('Assigned Users'),
'help' => t('All of the assigned users'),
'field' => array (
'handler' => 'views_handler_field_maestro_assigned_users',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_assigned_user',
),
);
$data['maestro_queue']['template_data_id'] = array(
'title' => t('Template Data ID'),
'help' => t('A Reference to the template data table'),
'field' => array (
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
);
$data['maestro_queue']['id'] = array(
'title' => t('Queue Task ID'),
'help' => t('The workflow engine\'s unique task id'),
'field' => array (
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
);
$data['maestro_queue']['process_id'] = array (
'title' => t('Process ID'),
'help' => t('Unique Process Identifier'),
'field' => array (
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
);
$data['maestro_queue']['created_date'] = array (
'title' => t('Assigned Date'),
'help' => t('Task Assigned Date'),
'field' => array (
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['maestro_queue']['started_date'] = array (
'title' => t('Started Date'),
'help' => t('Task Started Date'),
'field' => array (
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['maestro_queue']['task_class_name'] = array (
'title' => t('Task Type'),
'help' => t('Task Type'),
'field' => array(
'handler' => 'views_handler_field_maestro_tasktype',
'click sortable' => TRUE,
),
);
$data['maestro_queue']['completed_date'] = array (
'title' => t('Completed Date'),
'help' => t('Task Completed Date'),
'field' => array (
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['maestro_queue']['engine_version'] = array (
'title' => t('Engine Version'),
'help' => t('Version of the engine used to run this task'),
'field' => array (
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['maestro_queue']['is_interactive'] = array (
'title' => t('Interactive Flag'),
'help' => t('Set to 1 for interactive. 0 for non-interactive'),
'field' => array (
'handler' => 'views_handler_field_maestro_interactive',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['maestro_queue']['status'] = array (
'title' => t('Status'),
'help' => t('Task Status'),
'field' => array (
'handler' => 'views_handler_field_maestro_status', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'maestro_handler_filter_status',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['maestro_queue']['uid'] = array (
'title' => t('Completed By'),
'help' => t('The user who completed the task'),
'field' => array (
'handler' => 'views_handler_field_maestro_uid', //using a custom field handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/*** Views Filter Handlers ***/
/**
* Views Filter Handler for the maestro workflow status
*/
class maestro_handler_filter_status extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
global $base_path;
@include_once($base_path . drupal_get_path('module','maestro') . '/maestro_constants.class.php');
$reflect = new ReflectionClass('MaestroTaskStatusCodes');
$statusConstants = $reflect->getConstants();
$options = array();
foreach ($statusConstants as $label => $value) {
$options[$value] = MaestroTaskStatusCodes::getStatusLabel($value);
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Workflow Status'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
// Get status value
$status_value = '';
if(isset($this->view->exposed_input['status'])) {
$status_value = check_plain($this->view->exposed_input['status']);
} else if (empty($status_value) AND isset($this->options['value'])) {
$status_value = $this->options['value'];
}
// Setup query
$this->query->add_where($this->options['group'],$field,$status_value,'=');
}
}
/**
* Views Filter Handler for the maestro content type - only active workflow content types
*/
class maestro_handler_filter_content_type extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('maestro_project_content', 'a');
$query->fields('a', array('content_type'));
$query->distinct(TRUE);
$content_type_result = $query->execute();
$options = array();
foreach ($content_type_result as $rec) {
$type = check_plain($rec->content_type);
$options[$type] = $type;
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Content Type'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
// Get content type value
$content_type_value = '';
if(isset($this->view->exposed_input['content_type'])) {
$content_type_value = check_plain($this->view->exposed_input['content_type']);
} elseif (empty($content_type_value) AND isset($this->options['value'])) {
$content_type_value = $this->options['value'];
}
// Setup query
$this->query->add_where($this->options['group'],$field,$content_type_value,'=');
}
}
/**
* Views Filter Handler for the maestro taskname
* Return a list of unique interactive task names from all workflow templates
*/
class maestro_handler_filter_taskname extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('maestro_template_data', 'a');
$query->fields('a', array('id','taskname'));
$query->condition('a.is_interactive', 1, '=');
$query->distinct(TRUE);
$taskname_result = $query->execute();
$options = array();
foreach ($taskname_result as $rec) {
$taskname = check_plain($rec->taskname);
$options[$rec->id] = $taskname;
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Task Name'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.id";
// Get taskname value
$taskname_value = '';
if(isset($this->view->exposed_input['taskname'])) {
$taskname_value = check_plain($this->view->exposed_input['taskname']);
} elseif (empty($taskname_value) AND isset($this->options['value'])) {
$taskname_value = $this->options['value'];
}
// Setup query
$this->query->add_where($this->options['group'],$field,$taskname_value,'=');
}
}
/**
* Views Filter Handler for the maestro template Name
* Return a list of the maestro workflow templates
*/
class maestro_handler_filter_templatename extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('maestro_template', 'a');
$query->fields('a', array('id','template_name'));
$taskname_result = $query->execute();
$options = array();
foreach ($taskname_result as $rec) {
$template = check_plain($rec->template_name);
$options[$rec->id] = $template;
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Template Name'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.id";
// Get templatename value
$templatename_value = '';
if(isset($this->view->exposed_input['template_name'])) {
$templatename_value = check_plain($this->view->exposed_input['template_name']);
} elseif (empty($templatename_value) AND isset($this->options['value'])) {
$templatename_value = $this->options['value'];
}
// Setup query
$this->query->add_where($this->options['group'],$field,$templatename_value,'=');
}
}
/**
* Views Filter Handler for the maestro content type - only active workflow content types
*/
class maestro_handler_filter_process_variable extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('maestro_template_variables', 'a');
$query->fields('a', array('variable_name'));
$query->distinct(TRUE);
$result = $query->execute();
$options = array();
foreach ($result as $rec) {
$name = check_plain($rec->variable_name);
$options[$name] = $name;
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Process Variable'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
// Get variable value
$variable_value = '';
if(isset($this->view->exposed_input['variable_name'])) {
$variable_value = check_plain($this->view->exposed_input['variable_name']);
} elseif (empty($variable_value) AND isset($this->options['value'])) {
$variable_value = $this->options['value'];
}
/* The selected variable may be used for different templates.
* We need to find the variable id's since we don't have a single template
*/
$query = db_select('maestro_template_variables', 'a');
$query->fields('a', array('id'));
$query->condition('a.variable_name',$variable_value,'=');
$result = $query->execute();
$template_variables = array();
foreach ($result as $rec) {
$template_variables[] = $rec->id;
}
// Setup query: Requires that the variable_value field be seleted as that is what adds the maestro_process_variables table.
//$this->query->add_field('maestro_process_variables','template_variable_id');
$this->query->add_where(0,'maestro_process_variables.template_variable_id', $template_variables);
}
}
/**
* Views Filter Handler for the task assigned user
*/
class maestro_handler_filter_assigned_user extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('users', 'a');
$query->fields('a', array('uid','name'));
$query->condition('a.status',1,'=');
$query->orderBy('name');
$result = $query->execute();
$options = array();
foreach ($result as $rec) {
$name = check_plain($rec->name);
$options[$rec->uid] = $name;
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Assigned User'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
// Get variable value
$variable_value = '';
if(isset($this->view->exposed_input['assigned_users'])) {
$assigned_user = check_plain($this->view->exposed_input['assigned_users']);
} elseif (empty($variable_value) AND isset($this->options['value'])) {
$assigned_user = $this->options['value'];
}
if(!empty($assigned_user) AND $assigned_user != 'All') {
/* Assume we are looking for currently assigned tasks
* Tasks in the ready state - use the production_assignment table
*
* If the task status filter is being used and State 'Completed' is selected
* then we need to just check the queue table (uid field).
*
* Any other state makes no sense to use the 'assigned users' filter for
*
*/
if (isset($this->view->exposed_input['status'])) {
if($this->view->exposed_input['status'] == MaestroTaskStatusCodes::STATUS_READY OR $this->view->exposed_input['status'] == 'All') {
/* Task is assignment is done by 3 types (1: by user, 2: by role, 3: by group)
* Need to determine all the roles and groups the selected filter user is in
* and then modify the query.
*/
$expression = '(maestro_production_assignments.assign_id IN (:uids) AND maestro_production_assignments.assign_type = 1) ';
$args = array(':uids' => array($assigned_user));
/* Add filter condition for roles if user is a member of any roles */
$query = db_select('users_roles', 'a');
$query->fields('a', array('rid'));
$query->condition('a.uid',$assigned_user,'=');
$result = $query->execute();
$rids = array();
foreach ($result as $rec) {
$rids[] = $rec->rid;
}
if (!empty($rids)) {
$expression .= 'OR (maestro_production_assignments.assign_id IN (:rids) AND maestro_production_assignments.assign_type = 2) ';
$args[':rids'] = $rids;
}
/* Add filter condition for groups if enabled and user is any groups */
if (module_exists('og')) {
$query = db_select('field_data_group_audience', 'a');
$query->addField('a','group_audience_gid', 'gid');
$query->condition('a.entity_type','user','=');
$query->condition('a.entity_id',$assigned_user,'=');
$result = $query->execute();
$gids = array();
foreach ($result as $rec) {
$gids[] = $rec->gid;
}
if (!empty($gids)) {
$expression .= 'OR (maestro_production_assignments.assign_id IN (:gids) AND maestro_production_assignments.assign_type = 3)';
$args[':gids'] = $gids;
}
}
// Setup query: Requires that the variable_value field be seleted as that is what adds the maestro_process_variables table.
$this->query->add_field('maestro_production_assignments','assign_id');
$this->query->add_where(0,'1', 1);
$this->query->add_where_expression(1, $expression, $args);
} elseif ($this->view->exposed_input['status'] == MaestroTaskStatusCodes::STATUS_COMPLETE) {
/* Looking for completed tasks - which are by a single user and only need to now use the queue table */
$this->query->add_where(0,'maestro_queue.uid', $assigned_user);
}
}
}
}
}
/**
* Views Filter Handler for the maestro content type - only active workflow content types
*/
class maestro_handler_filter_variable_value extends views_handler_filter {
/**
* Shortcut to display the exposed options form.
*/
function value_form(&$form, &$form_state) {
$query = db_select('maestro_process_variables', 'a');
$query->fields('a', array('variable_value'));
$query->distinct(TRUE);
$result = $query->execute();
$options = array();
foreach ($result as $rec) {
$value = check_plain($rec->variable_value);
$options[$value] = $value;
}
natsort($options);
$form['value'] = array(
'#type' => 'select',
'#title' => t('Variable Value'),
'#options' => $options
);
return $form;
}
/**
* Change the query.
*/
function query() {
// Ensure table alias has been set
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
// Get variable value
$variable_value = '';
if(isset($this->view->exposed_input['variable_value'])) {
$variable_value = check_plain($this->view->exposed_input['variable_value']);
} elseif (empty($variable_value) AND isset($this->options['value'])) {
$variable_value = $this->options['value'];
}
if (!empty($variable_value)) {
$this->query->add_where(0,'maestro_process_variables.variable_value', $variable_value);
}
}
}
/*** View Handlers for the Field Value Display ***/
/**
* Field handler to display the Maestro Status
*/
class views_handler_field_maestro_status extends views_handler_field_numeric {
function render($values) {
global $base_path;
@include_once($base_path . drupal_get_path('module','maestro') . '/maestro_constants.class.php');
$value = $values->{$this->field_alias};
return MaestroTaskStatusCodes::getStatusLabel($value);
}
}
/**
* Field handler to display the Maestro Interactive Task
*/
class views_handler_field_maestro_interactive extends views_handler_field_numeric {
function render($values) {
if ($values->maestro_queue_is_interactive == 1) {
return t('Interactive');
} else {
return t('Non-Interactive');
}
}
}
/**
* Field handler to display the Maestro Task Type
*/
class views_handler_field_maestro_tasktype extends views_handler_field_numeric {
function render($values) {
return str_replace('MaestroTaskType','',$values->maestro_queue_task_class_name);
}
}
/**
* Field handler to display the Completed User
*/
class views_handler_field_maestro_uid extends views_handler_field_numeric {
function render($values) {
$value = $values->{$this->field_alias};
if ($value==0 && isset($value)) {
return 'Maestro';
}
elseif (!isset($value)) {
return t('Not yet completed');
}
else {
return $value;
}
}
}
/**
* Field handler to display the assigned users
*/
class views_handler_field_maestro_assigned_users extends views_handler_field_numeric {
function render($values) {
$output = '';
$taskid = $values->{$this->field_alias};
$maestro = Maestro::createMaestroObject(1);
if ($maestro->engine()->getTaskStatus($taskid) == MaestroTaskStatusCodes::STATUS_READY ) {
$assigned = $maestro->engine()->getAssigned($taskid);
foreach ($assigned as $type => $assignments) {
if ($type == 'USER') {
foreach ($assignments as $assignment) {
if($output != '') $output .= "<br>";
$output .= t('User') . ": {$assignment}";
}
} elseif ($type == 'ROLE') {
foreach ($assignments as $assignment) {
if($output != '') $output .= "<br>";
$output .= t('Role') . ": {$assignment}";
}
} elseif ($type == 'GROUP') {
foreach ($assignments as $assignment) {
if($output != '') $output .= "<br>";
$output .= t('Group') . ": {$assignment}";
}
}
}
if($output == '') {
$output = t('Maestro');
}
} else {
$output = 'N/A';
}
return $output;
}
}
/**
* Field handler to display the values for all the current process variables
*/
class views_handler_field_maestro_process_variables extends views_handler_field {
function render($values) {
$output = '';
$query = db_select('maestro_queue', 'a');
$query->join('maestro_process_variables', 'b', 'b.process_id = a.process_id');
$query->join('maestro_template_variables', 'c', 'b.template_variable_id = c.id');
$query->addField('a','process_id');
$query->addField('b','variable_value');
$query->addField('c','variable_name');
$query->condition('a.id', $values->id, '=');
$res = $query->execute();
foreach ($res as $rec) {
if($output != '') $output .= "<br>";
$output .= "{$rec->variable_name}: {$rec->variable_value}";
}
return $output;
}
}
/**
* Field handler to display the single process variable value
*/
class views_handler_field_maestro_process_variable extends views_handler_field {
function render($values) {
$output = '';
$query = db_select('maestro_queue', 'a');
$query->join('maestro_process_variables', 'b', 'b.process_id = a.process_id');
$query->join('maestro_template_variables', 'c', 'b.template_variable_id = c.id');
$query->addField('b','variable_value');
$query->condition('a.id', $values->id, '=');
$query->condition('c.variable_name', $values->maestro_template_variables_variable_name, '=');
$res = $query->execute()->fetchAssoc();
if ($res) {
return $res['variable_value'];
} else {
return 'N/A';
}
}
}
/**
* HOOK views_pre_execute
* Need to alter the SQL query for the join on the process_variables table
*/
function maestro_views_pre_execute(&$view) {
$query = $view->build_info['query'];
$tables =& $query->getTables();
$fields =& $query->getFields();
$where =& $query->conditions();
if(isset($view->exposed_input['variable_name']) OR isset($fields['maestro_template_variables_variable_name'])) {
/* The query object in $view is a selectQuery object
To eliminate the duplicate records, needed to change the
order of the joins and use a more specific join condition.
The join of the process_variables table was creating
the duplicates even with DISTINCT query option.
Reference: http://drupal.org/node/310077
*/
$process_variables = $tables['maestro_process_variables'];
unset($tables['maestro_process_variables']);
$template_variables = $tables['maestro_template_variables'];
unset($tables['maestro_template_variables']);
$tables['maestro_process_variables'] = $process_variables;
$tables['maestro_template_variables'] = $template_variables;
$tables['maestro_template_variables']['condition'] = "maestro_template.id = maestro_template_variables.template_id AND " .
"maestro_process_variables.template_variable_id = maestro_template_variables.id AND " .
"maestro_process_variables.process_id = maestro_queue.process_id";
}
}