-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow_progress_bar.module
106 lines (95 loc) · 2.51 KB
/
workflow_progress_bar.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
<?php
/**
* Implements hook_block_info().
*/
function workflow_progress_bar_block_info() {
$blocks = array();
$blocks['progress'] = array(
'info' => t('Workflow Progress Bar'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function workflow_progress_bar_block_view($delta = '') {
$block = array();
if ($delta == 'progress') {
$nid = "0";
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if ($node->type == '[your_node_type]') {
$status = get_bar_status(workflow_node_current_state($node));
$block['content'] = theme(
'workflow_progress_bar',
array(
'status' => $status
)
);
}
}
}
return $block;
}
/**
* Implements hook_theme().
*/
function workflow_progress_bar_theme() {
return array(
'workflow_progress_bar' => array(
'template' => 'progress-bar',
'path' => drupal_get_path('module', 'workflow_progress_bar') . '/templates',
'variables' => array(
"status" => array(
"percentage" => 0,
"active_nodes" => 0
)
)
)
);
}
// get percentage and active nodes
function get_bar_status($status) {
switch ($status) {
case 1: {
$percentage = 0;
$active_nodes = 1;
break;
}
case 2: {
$percentage = 25;
$active_nodes = 2;
break;
}
case 3: {
$percentage = 0;
$active_nodes = 1;
break;
}
case 4: {
$percentage = 50;
$active_nodes = 3;
break;
}
case 5: {
$percentage = 75;
$active_nodes = 4;
break;
}
case 6: {
$percentage = 100;
$active_nodes = 5;
break;
}
default : {
$percentage = 0;
$active_nodes = 0;
}
}
$bar_status = array(
"percentage" => $percentage,
"active_nodes" => $active_nodes
);
return $bar_status;
}