Internal: Fix certificate generation and content issues - refs BT#21007

pull/5413/head
christianbeeznst 1 year ago
parent 7ceafb9a06
commit 4167bc334b
  1. 46
      public/main/gradebook/lib/be/category.class.php
  2. 3
      public/main/inc/lib/SkillModel.php
  3. 24
      public/main/inc/lib/certificate.lib.php
  4. 79
      public/main/my_space/myStudents.php
  5. 4
      public/main/template/default/gradebook/custom_certificate.html.twig

@ -2215,12 +2215,16 @@ class Category implements GradebookItem
public static function userFinishedCourse(
int $userId,
GradebookCategory $category,
bool $recalculateScore = false
bool $recalculateScore = false,
?int $courseId = null,
?int $sessionId = null
): bool {
$currentScore = self::getCurrentScore(
$userId,
$category,
$recalculateScore
$recalculateScore,
$courseId,
$sessionId
);
$minCertificateScore = $category->getCertifMinScore();
@ -2230,21 +2234,21 @@ class Category implements GradebookItem
/**
* Get the current score (as percentage) on a gradebook category for a user.
*
* @param int $userId The user id
* @param bool $recalculate
*
* @return float The score
*/
public static function getCurrentScore(
$userId,
int $userId,
GradebookCategory $category,
$recalculate = false
) {
bool $recalculate = false,
?int $courseId = null,
?int $sessionId = null
): float|int {
if ($recalculate) {
return self::calculateCurrentScore(
$userId,
$category
$category,
$courseId,
$sessionId
);
}
@ -2660,13 +2664,27 @@ class Category implements GradebookItem
*
* @return float The score
*/
private static function calculateCurrentScore(int $userId, GradebookCategory $category)
{
private static function calculateCurrentScore(
int $userId,
?GradebookCategory $category = null,
?int $courseId = null,
?int $sessionId = null,
): float|int {
if (null === $category) {
return 0;
}
$categoryList = self::load($category->getId());
$categoryList = self::load(
null,
null,
$courseId,
null,
null,
$sessionId
);
/* @var Category $category */
$category = $categoryList[0] ?? null;
if (null === $category) {

@ -1706,7 +1706,8 @@ class SkillModel extends Model
ON s.id = sru.skill_id
WHERE sru.user_id = $userId";
$result = Database::query($sql);
$query = Database::query($sql);
$result = Database::store_result($query, 'ASSOC');
$skills = [];
foreach ($result as $item) {

@ -576,7 +576,7 @@ class Certificate extends Model
/**
* @return string
*/
public function generateCustomCertificate(string $fileName = '')
public function generateCustomCertificate(string $fileName = ''): string
{
$certificateRepo = Container::getGradeBookCertificateRepository();
$certificateRepo->registerUserInfoAboutCertificate(0, $this->user_id, 100, $fileName);
@ -602,20 +602,30 @@ class Certificate extends Model
foreach ($session['courses'] as $course) {
$course = api_get_course_entity($course['real_id']);
$courseId = $course->getId();
/* @var GradebookCategory $category */
$category = $gradeBookRepo->findOneBy(['course' => $course, 'session' => $session['session_id']]);
if (null !== $category) {
$result = Category::userFinishedCourse(
$this->user_id,
$category,
true
true,
$courseId,
$session['session_id']
);
$lpList = new LearnpathList(
$this->user_id,
api_get_course_info_by_id($courseId),
$session['session_id']
);
$lpFlatList = $lpList->get_flat_list();
// Find time spent in LP
$timeSpent = Tracking::get_time_spent_in_lp(
$this->user_id,
$course,
[],
!empty($lpFlatList) ? array_keys($lpFlatList) : [],
$session['session_id']
);
@ -667,7 +677,7 @@ class Certificate extends Model
$tplContent->assign('terms_validation_date', $termsValidationDate);
// Ofaj
$tplContent->assign('time_in_platform_in_hours', round($timeInSeconds / 3600, 1));
$tplContent->assign('time_in_platform_in_hours', round($timeInSeconds/3600, 1));
$tplContent->assign(
'certificate_generated_date_no_time',
api_get_local_time(
@ -696,9 +706,9 @@ class Certificate extends Model
$tplContent->assign('sessions', $sessionsApproved);
$tplContent->assign('courses', $coursesApproved);
$tplContent->assign('time_spent_in_lps', api_time_to_hms($totalTimeInLearningPaths));
$tplContent->assign('time_spent_in_lps_in_hours', round($totalTimeInLearningPaths / 3600, 1));
$tplContent->assign('time_spent_in_lps_in_hours', round($totalTimeInLearningPaths/3600, 1));
$layoutContent = $tplContent->get_template('gradebook/custom_certificate.tpl');
$layoutContent = $tplContent->get_template('gradebook/custom_certificate.html.twig');
$content = $tplContent->fetch($layoutContent);
return $content;
@ -707,7 +717,7 @@ class Certificate extends Model
/**
* Ofaj.
*/
public function generatePdfFromCustomCertificate()
public function generatePdfFromCustomCertificate(): void
{
$orientation = api_get_setting('document.certificate_pdf_orientation');

@ -1130,10 +1130,10 @@ if (null !== $course) {
$session
);
$messages = Container::getForumPostRepository()->countUserForumPosts($user, $course, $session);
$links = Tracking::count_student_visited_links($studentId, $courseId, $sessionId);
$chat_last_connection = Tracking::chat_last_connection($studentId, $courseId, $sessionId);
$documents = Tracking::countStudentDownloadedDocuments($studentId, $courseId, $sessionId);
$uploaded_documents = Tracking::count_student_uploaded_documents($studentId, $courseCode, $sessionId);
$links = Tracking::count_student_visited_links($studentId, $course->getId(), $sessionId);
$chat_last_connection = Tracking::chat_last_connection($studentId, $course->getId(), $sessionId);
$documents = Tracking::countStudentDownloadedDocuments($studentId, $course->getId(), $sessionId);
$uploaded_documents = Tracking::count_student_uploaded_documents($studentId, $course->getCode(), $sessionId);
$tpl->assign('title', $course->getTitle());
@ -1146,15 +1146,15 @@ if (null !== $course) {
'upload_documents' => $uploaded_documents,
'course_first_access' => Tracking::get_first_connection_date_on_the_course(
$studentId,
$courseId,
$course->getId(),
$sessionId
),
'course_last_access' => Tracking::get_last_connection_date_on_the_course(
$studentId,
['real_id' => $courseId],
['real_id' => $course->getId()],
$sessionId
),
'count_access_dates' => Tracking::getNumberOfCourseAccessDates($studentId, $courseId, $sessionId),
'count_access_dates' => Tracking::getNumberOfCourseAccessDates($studentId, $course->getId(), $sessionId),
];
} else {
$details = false;
@ -1559,6 +1559,10 @@ if (empty($details)) {
),
];
if (empty($courseId) && null !== $course) {
$courseId = $course->getId();
}
$timeCourse = null;
if (Tracking::minimumTimeAvailable($sessionId, $courseId)) {
$timeCourse = Tracking::getCalculateTime($studentId, $courseId, $sessionId);
@ -1790,18 +1794,6 @@ if (empty($details)) {
echo Display::tag('td', $start_time);
}
/* if ($hookLpTracking) {
$hookContents = $hookLpTracking->notifyTrackingContent($lp_id, $studentId);
foreach ($hookContents as $hookContent) {
if (isset($hookContent['value'])) {
$contentToExport[] = strip_tags($hookContent['value']);
echo Display::tag('td', $hookContent['value'], $hookContent['attrs']);
}
}
}*/
$csv_content[] = $contentToExport;
if (true === $any_result) {
@ -1861,21 +1853,6 @@ if (empty($details)) {
echo '<th>'.get_lang('Attempts').'</th>';
echo '<th>'.get_lang('Latest attempt').'</th>';
echo '<th>'.get_lang('All attempts').'</th>';
/*$hookQuizTracking = HookMyStudentsQuizTracking::create();
if ($hookQuizTracking) {
$hookHeaders = array_map(
function ($hookHeader) {
if (isset($hookHeader['value'])) {
return Display::tag('th', $hookHeader['value'], $hookHeader['attrs']);
}
},
$hookQuizTracking->notifyTrackingHeader()
);
echo implode(PHP_EOL, $hookHeaders);
}*/
echo '</tr></thead><tbody>';
$csv_content[] = [];
@ -1885,40 +1862,6 @@ if (empty($details)) {
get_lang('Average score in learning paths'),
get_lang('Attempts'),
];
/*if ($hookQuizTracking) {
$hookHeaders = array_map(
function ($hookHeader) {
if (isset($hookHeader['value'])) {
return strip_tags($hookHeader['value']);
}
},
$hookQuizTracking->notifyTrackingHeader()
);
$csvContentIndex = count($csv_content) - 1;
$csv_content[$csvContentIndex] = array_merge($csv_content[$csvContentIndex], $hookHeaders);
}*/
/*$t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
$sessionCondition = api_get_session_condition(
$sessionId,
true,
true,
'quiz.session_id'
);
$sql = "SELECT quiz.title, id
FROM $t_quiz AS quiz
WHERE
quiz.c_id = ".$courseInfo['real_id']." AND
active IN (0, 1)
$sessionCondition
ORDER BY quiz.title ASC ";
$result_exercices = Database::query($sql);
$i = 0;*/
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
$repo = Container::getQuizRepository();

@ -42,10 +42,10 @@
{{ complete_name }}
</h3>
<p style="font-size: 16px;">
{{ 'User has participate dans de platforme %s the contrat date %s certificate date %s time %s' | trans | format(_s.site_name, certificate_generated_date_no_time, terms_validation_date_no_time, time_in_platform_in_hours)}}
{{ 'User has participate dans de platforme %s the contrat date %s certificate date %s' | trans | format(_s.site_name, certificate_generated_date_no_time, terms_validation_date_no_time, time_in_platform_in_hours)}}
</p>
<br />
<p style="font-size: 16px;">{{ 'This preparation corresponds to a volume of approximately %s training hours.' | trans | format(time_in_platform_in_hours)}}</p><br />
<p style="font-size: 16px;">{{ 'This preparation corresponds to a volume of approximately %s training hours.' | trans | format(time_spent_in_lps_in_hours)}}</p><br />
<p style="font-size: 16px;">{{ 'The following contents have been validated' | trans }}:</p>
{% if sessions %}
<ul style="color: #672290; font-size: 16px;">

Loading…
Cancel
Save