View source
<?php
class tmgmt_handler_field_tmgmt_progress extends views_handler_field_entity {
function pre_render(&$values) {
parent::pre_render($values);
if ($this->entity_type == 'tmgmt_job') {
$tjids = array();
foreach ($values as $value) {
if ($value->tmgmt_job_state == TMGMT_JOB_STATE_ABORTED) {
continue;
}
$tjids[] = $value->tjid;
}
tmgmt_job_statistics_load($tjids);
}
}
function render($values) {
$object = $this
->get_value($values);
if ($object
->isAborted()) {
return t('N/A');
}
$counts = array(
'@accepted' => $object
->getCountAccepted(),
'@reviewed' => $object
->getCountReviewed(),
'@translated' => $object
->getCountTranslated(),
'@pending' => $object
->getCountPending(),
);
$id = $object
->internalIdentifier();
if (module_exists('google_chart_tools')) {
draw_chart($this
->build_progressbar_settings($id, $counts));
return '<div id="progress' . $id . '"></div>';
}
$title = t('Accepted: @accepted, reviewed: @reviewed, translated: @translated, pending: @pending.', $counts);
return sprintf('<span title="%s">%s</span>', $title, implode('/', $counts));
}
function build_progressbar_settings($id, $counts, $prefix = 'progress') {
$settings['chart'][$prefix . $id] = array(
'header' => array(
t('Accepted'),
t('Reviewed'),
t('Translated'),
t('Pending'),
),
'rows' => array(
array(
$counts['@accepted'],
$counts['@reviewed'],
$counts['@translated'],
$counts['@pending'],
),
),
'columns' => array(
'',
),
'chartType' => 'PieChart',
'containerId' => $prefix . $id,
'options' => array(
'backgroundColor' => 'transparent',
'colors' => array(
'#00b600',
'#60ff60',
'#ffff00',
'#6060ff',
),
'forceIFrame' => FALSE,
'chartArea' => array(
'left' => 0,
'top' => 0,
'width' => '50%',
'height' => '100%',
),
'fontSize' => 9,
'title' => t('Progress'),
'titlePosition' => 'none',
'width' => 60,
'height' => 50,
'isStacked' => TRUE,
'legend' => array(
'position' => 'none',
),
'pieSliceText' => 'none',
),
);
return $settings;
}
}