function _casetracker_dashboard_createProjectCountArray in Case Tracker 5
Function to combine project - states and case count to one big array
Parameters
array projects:
array states:
array count:
Return value
array
1 call to _casetracker_dashboard_createProjectCountArray()
- _casetracker_dashboard_states in ./
casetracker_dashboard.module - Function to get an overview of all projects and their states count
File
- ./
casetracker_dashboard.module, line 308
Code
function _casetracker_dashboard_createProjectCountArray($_projects, $_states, $_caseCount) {
$overview = array();
// init vars
$info = array();
$completedKeys = array();
// get the state keys that have to be counted as done
$statesDone = variable_get('casetracker_dashboard_states_done', array());
foreach ($statesDone as $key => $done) {
if (true === $done) {
$completedKeys[] = $key;
}
}
// create the states count array
// && the total array
$totals = array(
'project' => array(
'data' => t('Total'),
'class' => 'project',
),
);
foreach ($_states as $key => $value) {
$totals['state_' . $key] = $info['state_' . $key] = array(
'data' => 0,
);
}
$totals['todo'] = $info['todo'] = array(
'data' => 0,
'class' => 'devider',
);
$totals['done'] = $info['done'] = array(
'data' => 0,
);
$totals['total'] = $info['total'] = array(
'data' => 0,
'class' => 'devider',
);
$totals['completed'] = $info['completed'] = array(
'data' => 0,
'class' => 'percent',
);
// first add all possible projects as an extra array to the projects array
foreach ($_projects as $key => $project) {
$link = l($project['title'], 'casetracker/cases/' . $key . '/all');
$overview[$key]['project'] = array(
'data' => $link,
'class' => 'project',
);
$overview[$key] = array_merge($overview[$key], $info);
}
// loop through the counts and add the counts to the array
foreach ($_caseCount as $count) {
$nid = (int) $count->nid;
$csid = (int) $count->csid;
$overview[$nid]['state_' . $csid]['data'] = (int) $count->number_of_cases;
$totals['state_' . $csid]['data'] += (int) $count->number_of_cases;
if (in_array($csid, $completedKeys)) {
$overview[$nid]['done']['data'] += (int) $count->number_of_cases;
$totals['done']['data'] += (int) $count->number_of_cases;
}
else {
$overview[$nid]['todo']['data'] += (int) $count->number_of_cases;
$totals['todo']['data'] += (int) $count->number_of_cases;
}
$overview[$nid]['total']['data'] += (int) $count->number_of_cases;
$totals['total']['data'] += (int) $count->number_of_cases;
}
// loop through the projects and count the percentage of completed cases
foreach ($overview as $key => $project) {
if (0 < $project['total']['data']) {
$overview[$key]['completed']['data'] = round($project['done']['data'] / $project['total']['data'] * 100);
}
else {
$overview[$key]['completed']['data'] = 100;
}
}
// calculate the overview %
if (0 < $totals['todo'] && 0 < $totals['total']['data']) {
$totals['completed']['data'] = round($totals['done']['data'] / $totals['total']['data'] * 100);
}
else {
$totals['completed']['data'] = 100;
}
$overview['totals'] = array(
'data' => $totals,
'class' => 'totals',
);
return $overview;
}