|
|
|
|
@ -8,8 +8,6 @@ use CpChart\Image as pImage; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class MySpace. |
|
|
|
|
* |
|
|
|
|
* @package chamilo.reporting |
|
|
|
|
*/ |
|
|
|
|
class MySpace |
|
|
|
|
{ |
|
|
|
|
@ -2125,12 +2123,22 @@ class MySpace |
|
|
|
|
'.Display::return_icon('2rightarrow.png', get_lang('Details')).' |
|
|
|
|
</a> |
|
|
|
|
</center>'; |
|
|
|
|
|
|
|
|
|
$scoreInCourse = null; |
|
|
|
|
if (null !== $avg_score_in_course) { |
|
|
|
|
if (is_numeric($avg_score_in_course)) { |
|
|
|
|
$scoreInCourse = $avg_score_in_course.'%'; |
|
|
|
|
} else { |
|
|
|
|
$scoreInCourse = $avg_score_in_course; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$csv_content[] = [ |
|
|
|
|
api_html_entity_decode($row_course[1], ENT_QUOTES, $charset), |
|
|
|
|
$nb_students_in_course, |
|
|
|
|
$avg_time_spent_in_course, |
|
|
|
|
is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', |
|
|
|
|
is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course.'%' : $avg_score_in_course, |
|
|
|
|
$scoreInCourse, |
|
|
|
|
is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', |
|
|
|
|
$avg_messages_in_course, |
|
|
|
|
$avg_assignments_in_course, |
|
|
|
|
@ -2956,6 +2964,7 @@ class MySpace |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param string $start_date |
|
|
|
|
* @param string $end_date |
|
|
|
|
* @param bool $addUserIp |
|
|
|
|
* |
|
|
|
|
* @author Jorge Frisancho Jibaja |
|
|
|
|
* @author Julio Montoya <gugli100@gmail.com> fixing the function |
|
|
|
|
@ -2969,14 +2978,15 @@ class MySpace |
|
|
|
|
$course_info, |
|
|
|
|
$sessionId, |
|
|
|
|
$start_date, |
|
|
|
|
$end_date |
|
|
|
|
$end_date, |
|
|
|
|
$addUserIp = false |
|
|
|
|
) { |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
|
|
|
|
$user_id = (int) $user_id; |
|
|
|
|
$connections = []; |
|
|
|
|
if (!empty($course_info)) { |
|
|
|
|
$courseId = (int) $course_info['real_id']; |
|
|
|
|
$end_date = add_day_to($end_date); |
|
|
|
|
$end_date = self::add_day_to($end_date); |
|
|
|
|
|
|
|
|
|
$start_date = Database::escape_string($start_date); |
|
|
|
|
$end_date = Database::escape_string($end_date); |
|
|
|
|
@ -2984,7 +2994,8 @@ class MySpace |
|
|
|
|
$sql = "SELECT |
|
|
|
|
login_course_date, |
|
|
|
|
logout_course_date, |
|
|
|
|
TIMESTAMPDIFF(SECOND, login_course_date, logout_course_date) duration |
|
|
|
|
TIMESTAMPDIFF(SECOND, login_course_date, logout_course_date) duration, |
|
|
|
|
user_ip |
|
|
|
|
FROM $table |
|
|
|
|
WHERE |
|
|
|
|
user_id = $user_id AND |
|
|
|
|
@ -2996,47 +3007,50 @@ class MySpace |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
|
|
|
|
|
while ($row = Database::fetch_array($rs)) { |
|
|
|
|
$connections[] = [ |
|
|
|
|
$item = [ |
|
|
|
|
'login' => $row['login_course_date'], |
|
|
|
|
'logout' => $row['logout_course_date'], |
|
|
|
|
'duration' => $row['duration'], |
|
|
|
|
]; |
|
|
|
|
if ($addUserIp) { |
|
|
|
|
$item['user_ip'] = $row['user_ip']; |
|
|
|
|
} |
|
|
|
|
$connections[] = $item; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $connections; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param $user_id |
|
|
|
|
* @param array $course_info |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param null $start_date |
|
|
|
|
* @param null $end_date |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
function get_stats($user_id, $course_info, $sessionId, $start_date = null, $end_date = null) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
|
|
|
|
$result = []; |
|
|
|
|
if (!empty($course_info)) { |
|
|
|
|
$stringStartDate = ''; |
|
|
|
|
$stringEndDate = ''; |
|
|
|
|
if ($start_date != null && $end_date != null) { |
|
|
|
|
$end_date = add_day_to($end_date); |
|
|
|
|
/** |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param array $course_info |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param null $start_date |
|
|
|
|
* @param null $end_date |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function getStats($user_id, $course_info, $sessionId, $start_date = null, $end_date = null) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
|
|
|
|
$result = []; |
|
|
|
|
if (!empty($course_info)) { |
|
|
|
|
$stringStartDate = ''; |
|
|
|
|
$stringEndDate = ''; |
|
|
|
|
if ($start_date != null && $end_date != null) { |
|
|
|
|
$end_date = self::add_day_to($end_date); |
|
|
|
|
|
|
|
|
|
$start_date = Database::escape_string($start_date); |
|
|
|
|
$end_date = Database::escape_string($end_date); |
|
|
|
|
$start_date = Database::escape_string($start_date); |
|
|
|
|
$end_date = Database::escape_string($end_date); |
|
|
|
|
|
|
|
|
|
$stringStartDate = "AND login_course_date BETWEEN '$start_date' AND '$end_date'"; |
|
|
|
|
$stringEndDate = "AND logout_course_date BETWEEN '$start_date' AND '$end_date'"; |
|
|
|
|
} |
|
|
|
|
$user_id = (int) $user_id; |
|
|
|
|
$courseId = (int) $course_info['real_id']; |
|
|
|
|
$sessionCondition = api_get_session_condition($sessionId); |
|
|
|
|
$sql = "SELECT |
|
|
|
|
$stringStartDate = "AND login_course_date BETWEEN '$start_date' AND '$end_date'"; |
|
|
|
|
$stringEndDate = "AND logout_course_date BETWEEN '$start_date' AND '$end_date'"; |
|
|
|
|
} |
|
|
|
|
$user_id = (int) $user_id; |
|
|
|
|
$courseId = (int) $course_info['real_id']; |
|
|
|
|
$sessionCondition = api_get_session_condition($sessionId); |
|
|
|
|
$sql = "SELECT |
|
|
|
|
SEC_TO_TIME(AVG(time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg, |
|
|
|
|
SEC_TO_TIME(SUM(time_to_sec(timediff(logout_course_date,login_course_date)))) as total, |
|
|
|
|
count(user_id) as times |
|
|
|
|
@ -3047,284 +3061,253 @@ function get_stats($user_id, $course_info, $sessionId, $start_date = null, $end_ |
|
|
|
|
$sessionCondition |
|
|
|
|
ORDER BY login_course_date ASC"; |
|
|
|
|
|
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
if ($row = Database::fetch_array($rs)) { |
|
|
|
|
$foo_avg = $row['avrg']; |
|
|
|
|
$foo_total = $row['total']; |
|
|
|
|
$foo_times = $row['times']; |
|
|
|
|
$result = [ |
|
|
|
|
'avg' => $foo_avg, |
|
|
|
|
'total' => $foo_total, |
|
|
|
|
'times' => $foo_times, |
|
|
|
|
]; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
if ($row = Database::fetch_array($rs)) { |
|
|
|
|
$foo_avg = $row['avrg']; |
|
|
|
|
$foo_total = $row['total']; |
|
|
|
|
$foo_times = $row['times']; |
|
|
|
|
$result = [ |
|
|
|
|
'avg' => $foo_avg, |
|
|
|
|
'total' => $foo_total, |
|
|
|
|
'times' => $foo_times, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function add_day_to($end_date) |
|
|
|
|
{ |
|
|
|
|
$foo_date = strtotime($end_date); |
|
|
|
|
$foo_date = strtotime(' +1 day', $foo_date); |
|
|
|
|
$foo_date = date('Y-m-d', $foo_date); |
|
|
|
|
|
|
|
|
|
return $foo_date; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converte an array to a table in html. |
|
|
|
|
* |
|
|
|
|
* @param array $result |
|
|
|
|
* |
|
|
|
|
* @author Jorge Frisancho Jibaja |
|
|
|
|
* |
|
|
|
|
* @version OCT-22- 2010 |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
function convert_to_string($result) |
|
|
|
|
{ |
|
|
|
|
$html = '<table class="table">'; |
|
|
|
|
if (!empty($result)) { |
|
|
|
|
foreach ($result as $key => $data) { |
|
|
|
|
$html .= '<tr><td>'; |
|
|
|
|
$html .= api_get_local_time($data['login']); |
|
|
|
|
$html .= '</td>'; |
|
|
|
|
$html .= '<td>'; |
|
|
|
|
|
|
|
|
|
$html .= api_time_to_hms(api_strtotime($data['logout']) - api_strtotime($data['login'])); |
|
|
|
|
$html .= '</tr></td>'; |
|
|
|
|
} |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
$html .= '</table>'; |
|
|
|
|
|
|
|
|
|
return $html; |
|
|
|
|
} |
|
|
|
|
public static function add_day_to($end_date) |
|
|
|
|
{ |
|
|
|
|
$foo_date = strtotime($end_date); |
|
|
|
|
$foo_date = strtotime(' +1 day', $foo_date); |
|
|
|
|
$foo_date = date('Y-m-d', $foo_date); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This function draw the graphic to be displayed on the user view as an image. |
|
|
|
|
* |
|
|
|
|
* @param array $sql_result |
|
|
|
|
* @param string $start_date |
|
|
|
|
* @param string $end_date |
|
|
|
|
* @param string $type |
|
|
|
|
* |
|
|
|
|
* @author Jorge Frisancho Jibaja |
|
|
|
|
* |
|
|
|
|
* @version OCT-22- 2010 |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
function grapher($sql_result, $start_date, $end_date, $type = '') |
|
|
|
|
{ |
|
|
|
|
if (empty($start_date)) { |
|
|
|
|
$start_date = ''; |
|
|
|
|
} |
|
|
|
|
if (empty($end_date)) { |
|
|
|
|
$end_date = ''; |
|
|
|
|
} |
|
|
|
|
if ($type == '') { |
|
|
|
|
$type = 'day'; |
|
|
|
|
return $foo_date; |
|
|
|
|
} |
|
|
|
|
$main_year = $main_month_year = $main_day = []; |
|
|
|
|
|
|
|
|
|
$period = new DatePeriod( |
|
|
|
|
new DateTime($start_date), |
|
|
|
|
new DateInterval('P1D'), |
|
|
|
|
new DateTime($end_date) |
|
|
|
|
); |
|
|
|
|
/** |
|
|
|
|
* This function draw the graphic to be displayed on the user view as an image. |
|
|
|
|
* |
|
|
|
|
* @param array $sql_result |
|
|
|
|
* @param string $start_date |
|
|
|
|
* @param string $end_date |
|
|
|
|
* @param string $type |
|
|
|
|
* |
|
|
|
|
* @author Jorge Frisancho Jibaja |
|
|
|
|
* |
|
|
|
|
* @version OCT-22- 2010 |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public static function grapher($sql_result, $start_date, $end_date, $type = '') |
|
|
|
|
{ |
|
|
|
|
if (empty($start_date)) { |
|
|
|
|
$start_date = ''; |
|
|
|
|
} |
|
|
|
|
if (empty($end_date)) { |
|
|
|
|
$end_date = ''; |
|
|
|
|
} |
|
|
|
|
if ($type == '') { |
|
|
|
|
$type = 'day'; |
|
|
|
|
} |
|
|
|
|
$main_year = $main_month_year = $main_day = []; |
|
|
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
$main_day[$date->format('d-m-Y')] = 0; |
|
|
|
|
} |
|
|
|
|
$period = new DatePeriod( |
|
|
|
|
new DateTime($start_date), |
|
|
|
|
new DateInterval('P1D'), |
|
|
|
|
new DateTime($end_date) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$period = new DatePeriod( |
|
|
|
|
new DateTime($start_date), |
|
|
|
|
new DateInterval('P1M'), |
|
|
|
|
new DateTime($end_date) |
|
|
|
|
); |
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
$main_day[$date->format('d-m-Y')] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
$main_month_year[$date->format('m-Y')] = 0; |
|
|
|
|
} |
|
|
|
|
$period = new DatePeriod( |
|
|
|
|
new DateTime($start_date), |
|
|
|
|
new DateInterval('P1M'), |
|
|
|
|
new DateTime($end_date) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$i = 0; |
|
|
|
|
if (is_array($sql_result) && count($sql_result) > 0) { |
|
|
|
|
foreach ($sql_result as $key => $data) { |
|
|
|
|
$login = api_strtotime($data['login']); |
|
|
|
|
$logout = api_strtotime($data['logout']); |
|
|
|
|
//creating the main array |
|
|
|
|
if (isset($main_month_year[date('m-Y', $login)])) { |
|
|
|
|
$main_month_year[date('m-Y', $login)] += float_format(($logout - $login) / 60, 0); |
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
$main_month_year[$date->format('m-Y')] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$i = 0; |
|
|
|
|
if (is_array($sql_result) && count($sql_result) > 0) { |
|
|
|
|
foreach ($sql_result as $key => $data) { |
|
|
|
|
$login = api_strtotime($data['login']); |
|
|
|
|
$logout = api_strtotime($data['logout']); |
|
|
|
|
//creating the main array |
|
|
|
|
if (isset($main_month_year[date('m-Y', $login)])) { |
|
|
|
|
$main_month_year[date('m-Y', $login)] += float_format(($logout - $login) / 60, 0); |
|
|
|
|
} |
|
|
|
|
if (isset($main_day[date('d-m-Y', $login)])) { |
|
|
|
|
$main_day[date('d-m-Y', $login)] += float_format(($logout - $login) / 60, 0); |
|
|
|
|
} |
|
|
|
|
if ($i > 500) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
if (isset($main_day[date('d-m-Y', $login)])) { |
|
|
|
|
$main_day[date('d-m-Y', $login)] += float_format(($logout - $login) / 60, 0); |
|
|
|
|
switch ($type) { |
|
|
|
|
case 'day': |
|
|
|
|
$main_date = $main_day; |
|
|
|
|
break; |
|
|
|
|
case 'month': |
|
|
|
|
$main_date = $main_month_year; |
|
|
|
|
break; |
|
|
|
|
case 'year': |
|
|
|
|
$main_date = $main_year; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if ($i > 500) { |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
$labels = array_keys($main_date); |
|
|
|
|
if (count($main_date) == 1) { |
|
|
|
|
$labels = $labels[0]; |
|
|
|
|
$main_date = $main_date[$labels]; |
|
|
|
|
} |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
switch ($type) { |
|
|
|
|
case 'day': |
|
|
|
|
$main_date = $main_day; |
|
|
|
|
break; |
|
|
|
|
case 'month': |
|
|
|
|
$main_date = $main_month_year; |
|
|
|
|
break; |
|
|
|
|
case 'year': |
|
|
|
|
$main_date = $main_year; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$labels = array_keys($main_date); |
|
|
|
|
if (count($main_date) == 1) { |
|
|
|
|
$labels = $labels[0]; |
|
|
|
|
$main_date = $main_date[$labels]; |
|
|
|
|
} |
|
|
|
|
/* Create and populate the pData object */ |
|
|
|
|
$myData = new pData(); |
|
|
|
|
$myData->addPoints($main_date, 'Serie1'); |
|
|
|
|
if (count($main_date) != 1) { |
|
|
|
|
$myData->addPoints($labels, 'Labels'); |
|
|
|
|
$myData->setSerieDescription('Labels', 'Months'); |
|
|
|
|
$myData->setAbscissa('Labels'); |
|
|
|
|
} |
|
|
|
|
$myData->setSerieWeight('Serie1', 1); |
|
|
|
|
$myData->setSerieDescription('Serie1', get_lang('MyResults')); |
|
|
|
|
$myData->setAxisName(0, get_lang('Minutes')); |
|
|
|
|
$myData->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true); |
|
|
|
|
|
|
|
|
|
// Cache definition |
|
|
|
|
$cachePath = api_get_path(SYS_ARCHIVE_PATH); |
|
|
|
|
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]); |
|
|
|
|
$chartHash = $myCache->getHash($myData); |
|
|
|
|
|
|
|
|
|
if ($myCache->isInCache($chartHash)) { |
|
|
|
|
//if we already created the img |
|
|
|
|
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
|
|
|
|
$myCache->saveFromCache($chartHash, $imgPath); |
|
|
|
|
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
|
|
|
|
} else { |
|
|
|
|
/* Define width, height and angle */ |
|
|
|
|
$mainWidth = 760; |
|
|
|
|
$mainHeight = 230; |
|
|
|
|
$angle = 50; |
|
|
|
|
|
|
|
|
|
/* Create the pChart object */ |
|
|
|
|
$myPicture = new pImage($mainWidth, $mainHeight, $myData); |
|
|
|
|
|
|
|
|
|
/* Turn of Antialiasing */ |
|
|
|
|
$myPicture->Antialias = false; |
|
|
|
|
/* Draw the background */ |
|
|
|
|
$settings = ["R" => 255, "G" => 255, "B" => 255]; |
|
|
|
|
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings); |
|
|
|
|
|
|
|
|
|
/* Add a border to the picture */ |
|
|
|
|
$myPicture->drawRectangle( |
|
|
|
|
0, |
|
|
|
|
0, |
|
|
|
|
$mainWidth - 1, |
|
|
|
|
$mainHeight - 1, |
|
|
|
|
["R" => 0, "G" => 0, "B" => 0] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/* Create and populate the pData object */ |
|
|
|
|
$myData = new pData(); |
|
|
|
|
$myData->addPoints($main_date, 'Serie1'); |
|
|
|
|
if (count($main_date) != 1) { |
|
|
|
|
$myData->addPoints($labels, 'Labels'); |
|
|
|
|
$myData->setSerieDescription('Labels', 'Months'); |
|
|
|
|
$myData->setAbscissa('Labels'); |
|
|
|
|
} |
|
|
|
|
$myData->setSerieWeight('Serie1', 1); |
|
|
|
|
$myData->setSerieDescription('Serie1', get_lang('MyResults')); |
|
|
|
|
$myData->setAxisName(0, get_lang('Minutes')); |
|
|
|
|
$myData->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true); |
|
|
|
|
/* Set the default font */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 10, ] |
|
|
|
|
); |
|
|
|
|
/* Write the chart title */ |
|
|
|
|
$myPicture->drawText( |
|
|
|
|
$mainWidth / 2, |
|
|
|
|
30, |
|
|
|
|
get_lang('TimeSpentInTheCourse'), |
|
|
|
|
[ |
|
|
|
|
"FontSize" => 12, |
|
|
|
|
"Align" => TEXT_ALIGN_BOTTOMMIDDLE, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Cache definition |
|
|
|
|
$cachePath = api_get_path(SYS_ARCHIVE_PATH); |
|
|
|
|
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]); |
|
|
|
|
$chartHash = $myCache->getHash($myData); |
|
|
|
|
/* Set the default font */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 8, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($myCache->isInCache($chartHash)) { |
|
|
|
|
//if we already created the img |
|
|
|
|
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
|
|
|
|
$myCache->saveFromCache($chartHash, $imgPath); |
|
|
|
|
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
|
|
|
|
} else { |
|
|
|
|
/* Define width, height and angle */ |
|
|
|
|
$mainWidth = 760; |
|
|
|
|
$mainHeight = 230; |
|
|
|
|
$angle = 50; |
|
|
|
|
|
|
|
|
|
/* Create the pChart object */ |
|
|
|
|
$myPicture = new pImage($mainWidth, $mainHeight, $myData); |
|
|
|
|
|
|
|
|
|
/* Turn of Antialiasing */ |
|
|
|
|
$myPicture->Antialias = false; |
|
|
|
|
/* Draw the background */ |
|
|
|
|
$settings = ["R" => 255, "G" => 255, "B" => 255]; |
|
|
|
|
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings); |
|
|
|
|
|
|
|
|
|
/* Add a border to the picture */ |
|
|
|
|
$myPicture->drawRectangle( |
|
|
|
|
0, |
|
|
|
|
0, |
|
|
|
|
$mainWidth - 1, |
|
|
|
|
$mainHeight - 1, |
|
|
|
|
["R" => 0, "G" => 0, "B" => 0] |
|
|
|
|
); |
|
|
|
|
/* Define the chart area */ |
|
|
|
|
$myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80); |
|
|
|
|
|
|
|
|
|
/* Draw the scale */ |
|
|
|
|
$scaleSettings = [ |
|
|
|
|
'XMargin' => 10, |
|
|
|
|
'YMargin' => 10, |
|
|
|
|
'Floating' => true, |
|
|
|
|
'GridR' => 200, |
|
|
|
|
'GridG' => 200, |
|
|
|
|
'GridB' => 200, |
|
|
|
|
'DrawSubTicks' => true, |
|
|
|
|
'CycleBackground' => true, |
|
|
|
|
'LabelRotation' => $angle, |
|
|
|
|
'Mode' => SCALE_MODE_ADDALL_START0, |
|
|
|
|
]; |
|
|
|
|
$myPicture->drawScale($scaleSettings); |
|
|
|
|
|
|
|
|
|
/* Turn on Antialiasing */ |
|
|
|
|
$myPicture->Antialias = true; |
|
|
|
|
|
|
|
|
|
/* Enable shadow computing */ |
|
|
|
|
$myPicture->setShadow( |
|
|
|
|
true, |
|
|
|
|
[ |
|
|
|
|
"X" => 1, |
|
|
|
|
"Y" => 1, |
|
|
|
|
"R" => 0, |
|
|
|
|
"G" => 0, |
|
|
|
|
"B" => 0, |
|
|
|
|
"Alpha" => 10, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/* Set the default font */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 10, ] |
|
|
|
|
); |
|
|
|
|
/* Write the chart title */ |
|
|
|
|
$myPicture->drawText( |
|
|
|
|
$mainWidth / 2, |
|
|
|
|
30, |
|
|
|
|
get_lang('TimeSpentInTheCourse'), |
|
|
|
|
[ |
|
|
|
|
"FontSize" => 12, |
|
|
|
|
"Align" => TEXT_ALIGN_BOTTOMMIDDLE, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
/* Draw the line chart */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 10, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
$myPicture->drawSplineChart(); |
|
|
|
|
$myPicture->drawPlotChart( |
|
|
|
|
[ |
|
|
|
|
"DisplayValues" => true, |
|
|
|
|
"PlotBorder" => true, |
|
|
|
|
"BorderSize" => 1, |
|
|
|
|
"Surrounding" => -60, |
|
|
|
|
"BorderAlpha" => 80, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/* Set the default font */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 8, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
/* Do NOT Write the chart legend */ |
|
|
|
|
|
|
|
|
|
/* Define the chart area */ |
|
|
|
|
$myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80); |
|
|
|
|
|
|
|
|
|
/* Draw the scale */ |
|
|
|
|
$scaleSettings = [ |
|
|
|
|
'XMargin' => 10, |
|
|
|
|
'YMargin' => 10, |
|
|
|
|
'Floating' => true, |
|
|
|
|
'GridR' => 200, |
|
|
|
|
'GridG' => 200, |
|
|
|
|
'GridB' => 200, |
|
|
|
|
'DrawSubTicks' => true, |
|
|
|
|
'CycleBackground' => true, |
|
|
|
|
'LabelRotation' => $angle, |
|
|
|
|
'Mode' => SCALE_MODE_ADDALL_START0, |
|
|
|
|
]; |
|
|
|
|
$myPicture->drawScale($scaleSettings); |
|
|
|
|
|
|
|
|
|
/* Turn on Antialiasing */ |
|
|
|
|
$myPicture->Antialias = true; |
|
|
|
|
|
|
|
|
|
/* Enable shadow computing */ |
|
|
|
|
$myPicture->setShadow( |
|
|
|
|
true, |
|
|
|
|
[ |
|
|
|
|
"X" => 1, |
|
|
|
|
"Y" => 1, |
|
|
|
|
"R" => 0, |
|
|
|
|
"G" => 0, |
|
|
|
|
"B" => 0, |
|
|
|
|
"Alpha" => 10, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
/* Write and save into cache */ |
|
|
|
|
$myCache->writeToCache($chartHash, $myPicture); |
|
|
|
|
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
|
|
|
|
$myCache->saveFromCache($chartHash, $imgPath); |
|
|
|
|
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Draw the line chart */ |
|
|
|
|
$myPicture->setFontProperties( |
|
|
|
|
[ |
|
|
|
|
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf', |
|
|
|
|
"FontSize" => 10, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
$myPicture->drawSplineChart(); |
|
|
|
|
$myPicture->drawPlotChart( |
|
|
|
|
[ |
|
|
|
|
"DisplayValues" => true, |
|
|
|
|
"PlotBorder" => true, |
|
|
|
|
"BorderSize" => 1, |
|
|
|
|
"Surrounding" => -60, |
|
|
|
|
"BorderAlpha" => 80, |
|
|
|
|
] |
|
|
|
|
return '<img src="'.$imgPath.'">'; |
|
|
|
|
} else { |
|
|
|
|
return api_convert_encoding( |
|
|
|
|
'<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>', |
|
|
|
|
'UTF-8' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/* Do NOT Write the chart legend */ |
|
|
|
|
|
|
|
|
|
/* Write and save into cache */ |
|
|
|
|
$myCache->writeToCache($chartHash, $myPicture); |
|
|
|
|
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
|
|
|
|
$myCache->saveFromCache($chartHash, $imgPath); |
|
|
|
|
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
|
|
|
|
} |
|
|
|
|
$html = '<img src="'.$imgPath.'">'; |
|
|
|
|
|
|
|
|
|
return $html; |
|
|
|
|
} else { |
|
|
|
|
$foo_img = api_convert_encoding( |
|
|
|
|
'<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>', |
|
|
|
|
'UTF-8' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $foo_img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|