示例#1
0
 /**
  * Generates the workload by time period graph.
  *
  * @param string $type
  */
 public function WorkloadTimePeriodGraph($type)
 {
     $usr_id = Auth::getUserID();
     // get timezone of current user
     $user_prefs = Prefs::get($usr_id);
     if ($type == 'email') {
         $data = Report::getEmailWorkloadByTimePeriod($user_prefs['timezone'], true);
         $graph_title = ev_gettext('Email by Time Period');
         $event_type = ev_gettext('emails');
     } else {
         $data = Report::getWorkloadByTimePeriod($user_prefs['timezone'], true);
         $graph_title = ev_gettext('Workload by Time Period');
         $event_type = ev_gettext('actions');
     }
     // TRANSLATORS: %s = Timezone name
     $xtitle = ev_gettext('Hours (%s)', Date_Helper::getTimezoneShortNameByUser($usr_id));
     // rebuild data for phplot format
     $plotData = array();
     $legends = array();
     $i = 1;
     foreach ($data as $performer => $values) {
         foreach ($values as $hour => $value) {
             $plotData[(int) $hour][0] = $hour;
             $plotData[(int) $hour][$i] = $value;
         }
         $legends[$i] = ucfirst($performer) . ' ' . $event_type;
         $i++;
     }
     $plot = $this->create(900, 350);
     $plot->SetImageBorderType('plain');
     $plot->SetPlotType('bars');
     $plot->SetDataType('text-data');
     $plot->SetDataValues($plotData);
     $plot->SetTitle($graph_title);
     $plot->SetLegend($legends);
     $plot->SetYTitle($event_type);
     $plot->SetXTitle($xtitle);
     $plot->SetXTickLabelPos('none');
     $plot->SetXTickPos('none');
     $plot->SetYDataLabelPos('plotin');
     $plot->SetYLabelType('printf', '%.0f%%');
     $plot->group_frac_width = 1;
     $plot->DrawGraph();
 }
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with this program; if not, write to:                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: Bryan Alsdorf <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('reports/workload_time_period.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
$usr_id = Auth::getUserID();
if (!Access::canAccessReports(Auth::getUserID())) {
    echo 'Invalid role';
    exit;
}
$prj_id = Auth::getCurrentProject();
// get timezone of current user
$user_prefs = Prefs::get($usr_id);
if (@$_GET['type'] == 'email') {
    $data = Report::getEmailWorkloadByTimePeriod(@$user_prefs['timezone']);
} else {
    $data = Report::getWorkloadByTimePeriod(@$user_prefs['timezone']);
}
$tpl->assign(array('data' => $data, 'type' => @$_GET['type'], 'user_tz' => Date_Helper::getTimezoneShortNameByUser($usr_id)));
$tpl->displayTemplate();
$usr_id = Auth::getUserID();
if (Auth::getCurrentRole() <= User::getRoleID("Customer")) {
    echo "Invalid role";
    exit;
}
/**
 * Generates the workload by time period graph.
 */
// get timezone of current user
$user_prefs = Prefs::get($usr_id);
if (@$HTTP_GET_VARS["type"] == "email") {
    $data = Report::getEmailWorkloadByTimePeriod(@$user_prefs["timezone"], true);
    $graph_title = "Email by Time Period";
    $event_type = "emails";
} else {
    $data = Report::getWorkloadByTimePeriod(@$user_prefs["timezone"], true);
    $graph_title = "Workload by Time Period";
    $event_type = "actions";
}
$plots = array();
foreach ($data as $performer => $values) {
    ksort($values);
    ksort($data[$performer]);
    // Create a bar pot
    $bplot = new BarPlot(array_values($values));
    if ($performer == "customer") {
        $color = "#99ccff";
    } else {
        $color = "#ffcc00";
    }
    $bplot->SetFillColor($color);