Skip to content

Commit

Permalink
Format time with PHP - refs BT#9087
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Feb 6, 2015
1 parent 27da74e commit 5cfacae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
15 changes: 10 additions & 5 deletions main/admin/teacher_time_report.php
Expand Up @@ -81,6 +81,7 @@
$selectedFrom,
$selectedUntil
);
$formatedTime = api_format_time($totalTime);

$timeReport->data[] = array(
'session' => null,
Expand All @@ -95,7 +96,7 @@
'username' => $teacher['username'],
'completeName' => api_get_person_name($teacher['firstname'], $teacher['lastname'])
),
'totalTime' => $totalTime
'totalTime' => $formatedTime
);
}

Expand All @@ -113,6 +114,7 @@
$selectedFrom,
$selectedUntil
);
$formatedTime = api_format_time($totalTime);

$timeReport->data[] = array(
'session' => array(
Expand All @@ -130,7 +132,7 @@
'username' => $coach['username'],
'completeName' => api_get_person_name($coach['firstname'], $coach['lastname'])
),
'totalTime' => $totalTime
'totalTime' => $formatedTime
);
}
}
Expand Down Expand Up @@ -167,6 +169,7 @@
$selectedFrom,
$selectedUntil
);
$formatedTime = api_format_time($totalTime);

$timeReport->data[] = array(
'session' => $sessionData,
Expand All @@ -178,7 +181,7 @@
'username' => $coach['username'],
'completeName' => api_get_person_name($coach['firstname'], $coach['lastname'])
),
'totalTime' => $totalTime
'totalTime' => $formatedTime
);
}
}
Expand Down Expand Up @@ -213,6 +216,7 @@
$selectedFrom,
$selectedUntil
);
$formatedTime = api_format_time($totalTime);

$timeReport->data[] = array(
'session' => null,
Expand All @@ -221,7 +225,7 @@
'name' => $courseInfo['title']
),
'coach' => $teacherData,
'totalTime' => $totalTime
'totalTime' => $formatedTime
);
}
}
Expand All @@ -244,6 +248,7 @@
$selectedFrom,
$selectedUntil
);
$formatedTime = api_format_time($totalTime);

$timeReport->data[] = array(
'session' => $sessionData,
Expand All @@ -252,7 +257,7 @@
'name' => $courseInfo['title']
),
'coach' => $teacherData,
'totalTime' => $totalTime
'totalTime' => $formatedTime
);
}
}
Expand Down
22 changes: 22 additions & 0 deletions main/inc/lib/main_api.lib.php
Expand Up @@ -7513,3 +7513,25 @@ function api_site_use_cookie_warning_cookie_exist()
{
return isset($_COOKIE['ChamiloUsesCookies']);
}

/**
* Given a number of seconds, format the time to show hours, minutes and seconds
* @param int $time The time in seconds
* @param string $originFormat Optional. PHP o JS
* @return string (00h00'00")
*/
function api_format_time($time, $originFormat = 'php')
{
$h = get_lang('h');
$hours = $time / 3600;
$mins = ($time % 3600) / 60;
$secs = ($time % 60);

if ($originFormat == 'js') {
$scormTime = trim(sprintf("%02d : %02d : %02d", $hours, $mins, $secs));
} else {
$scormTime = trim(sprintf("%02d$h%02d'%02d\"", $hours, $mins, $secs));
}

return $scormTime;

This comment has been minimized.

Copy link
@jmontoyaa

jmontoyaa Feb 9, 2015

Member

Replace $scormTime with $formattedTime

}
10 changes: 5 additions & 5 deletions main/inc/lib/usermanager.lib.php
Expand Up @@ -5007,13 +5007,13 @@ public static function getUsersByOfficialCode($officialCode)
}

/**
* Calc the expended time (hh::mm:ss) by a user in a course
* Calc the expended time (in seconds) by a user in a course
* @param int $userId The user id
* @param string $courseCode The course id
* @param int $sessionId Optional. The session id
* @param string $from Optional. From date
* @param string $until Optional. Until date
* @return string The time
* @return int The time
*/
public static function getExpendedTimeInCourses($userId, $courseCode, $sessionId = 0, $from = '', $until = '')
{
Expand All @@ -5034,18 +5034,18 @@ public static function getExpendedTimeInCourses($userId, $courseCode, $sessionId
}

$trackResult = Database::select(
'SEC_TO_TIME(SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date))) as total_time',
'SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as total_time',
$trackCourseAccessTable,
array(
'where' => $whereConditions
), 'first'
);

if ($trackResult != false) {
return $trackResult['total_time'] ? $trackResult['total_time'] : '00:00:00';
return $trackResult['total_time'] ? $trackResult['total_time'] : 0;
}

return '00:00:00';
return 0;
}

}

2 comments on commit 5cfacae

@jmontoyaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should the function "api_format_time" in the newscorm too and remove the old code.

@jmontoyaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget that comment I just check that it was done here:
fe3852b

Please sign in to comment.