Skip to content

Commit

Permalink
My Progress: show learnpaths by categories - refs BT#18671
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed May 20, 2021
1 parent c18faa2 commit 7aca771
Showing 1 changed file with 140 additions and 123 deletions.
263 changes: 140 additions & 123 deletions main/inc/lib/tracking.lib.php
Expand Up @@ -5,6 +5,7 @@
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use CpChart\Cache as pCache;
Expand Down Expand Up @@ -2258,7 +2259,8 @@ public static function count_course_per_student($user_id, $include_sessions = tr
* @param string code
* @param int id (optional), filtered by exercise
* @param int id (optional), if param $session_id is null
* it'll return results including sessions, 0 = session is not filtered
* it'll return results including sessions, 0 = session is not
* filtered
*
* @return string value (number %) Which represents a round integer about the score average
*/
Expand Down Expand Up @@ -4025,7 +4027,8 @@ public static function count_student_assignments(
*
* @param int|array Student id
* @param string Course code
* @param int Session id if null(default) return count of messages including sessions, 0 = session is not filtered
* @param int Session id if null(default) return count of messages including sessions, 0 = session is not
* filtered
*
* @return int Count of messages
*/
Expand Down Expand Up @@ -5443,6 +5446,7 @@ public static function show_course_detail($user_id, $course_code, $session_id, $
$html = '';
if (isset($course_code)) {
$user_id = (int) $user_id;
$user = api_get_user_entity($user_id);
$session_id = (int) $session_id;
$course_info = api_get_course_info($course_code);
if (empty($course_info)) {
Expand All @@ -5464,7 +5468,7 @@ public static function show_course_detail($user_id, $course_code, $session_id, $
// Show exercise results of invisible exercises? see BT#4091
$quizzesHtml = self::generateQuizzesTable($course_info, $session_id);
// LP table results
$learningPathsHtml = self::generateLearningPathsTable($user_id, $course_info, $session_id);
$learningPathsHtml = self::generateLearningPathsTable($user, $course_info, $session_id);
$skillsHtml = self::displayUserSkills($user_id, $course_info['id'], $session_id);

$toolsHtml = [
Expand Down Expand Up @@ -7492,8 +7496,10 @@ private static function generateQuizzesTable(array $courseInfo, int $sessionId =
);
}

private static function generateLearningPathsTable(int $userId, array $courseInfo, int $sessionId = 0): string
private static function generateLearningPathsTable(User $user, array $courseInfo, int $sessionId = 0): string
{
$html = [];

$columnHeaders = [
'lp' => get_lang('LearningPath'),
'time' => get_lang('LatencyTimeSpent'),
Expand Down Expand Up @@ -7533,163 +7539,174 @@ function ($columHeader, $key) use ($trackingColumns) {

$columnHeadersKeys = array_keys($columnHeaders);

$learningpathsTable = new SortableTableFromArray([], 0, 0, 'learningpaths');
$learningpathsTable->setHeaders($columnHeaders);

// LP table results
$list = new LearnpathList(
api_get_user_id(),
$courseInfo,
$sessionId,
'lp.publicatedOn ASC',
true,
null,
true
);

$lpList = $list->get_flat_list();

if (empty($lpList)) {
return Display::return_message(get_lang('NoLearnpath'));
}
$categories = learnpath::getCategories($courseInfo['real_id'], true);
$countCategories = count($categories);

$webCodePath = api_get_path(WEB_CODE_PATH);

foreach ($lpList as $lpId => $learnpath) {
$learningpathData = [];
/** @var CLpCategory $category */
foreach ($categories as $category) {
// LP table results
$objLearnpathList = new LearnpathList(
$user->getId(),
$courseInfo,
$sessionId,
'lp.publicatedOn ASC',
true,
$category->getId(),
false
);
$lpList = $objLearnpathList->get_flat_list();

if (!$learnpath['lp_visibility']) {
continue;
}
$learningpathsTable = new SortableTableFromArray([], 0, 0, 'learningpaths');
$learningpathsTable->setHeaders($columnHeaders);

if ($addLpInvisibleCheckbox) {
if (!StudentFollowPage::isViewVisible($lpId, $userId, $courseInfo['real_id'], $sessionId)) {
foreach ($lpList as $lpId => $learnpath) {
$learningpathData = [];

if (!$learnpath['lp_visibility']) {
continue;
}
}

$url = $webCodePath.'lp/lp_controller.php?'
.http_build_query(
['cidReq' => $courseInfo['code'], 'id_session' => $sessionId, 'lp_id' => $lpId, 'action' => 'view']
);
if ($addLpInvisibleCheckbox) {
if (!StudentFollowPage::isViewVisible($lpId, $user->getId(), $courseInfo['real_id'], $sessionId)) {
continue;
}
}

if (in_array('lp', $columnHeadersKeys)) {
if ($learnpath['lp_visibility'] == 0) {
$learningpathData[] = $learnpath['lp_name'];
} else {
$learningpathData[] = Display::url(
$learnpath['lp_name'],
$url,
['target' => SESSION_LINK_TARGET]
$url = $webCodePath.'lp/lp_controller.php?'
.http_build_query(
['cidReq' => $courseInfo['code'], 'id_session' => $sessionId, 'lp_id' => $lpId, 'action' => 'view']
);

if (in_array('lp', $columnHeadersKeys)) {
if ($learnpath['lp_visibility'] == 0) {
$learningpathData[] = $learnpath['lp_name'];
} else {
$learningpathData[] = Display::url(
$learnpath['lp_name'],
$url,
['target' => SESSION_LINK_TARGET]
);
}
}
}

if (in_array('time', $columnHeadersKeys)) {
$time_spent_in_lp = self::get_time_spent_in_lp(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
if (in_array('time', $columnHeadersKeys)) {
$time_spent_in_lp = self::get_time_spent_in_lp(
$user->getId(),
$courseInfo['code'],
[$lpId],
$sessionId
);

$learningpathData[] = api_time_to_hms($time_spent_in_lp);
}
$learningpathData[] = api_time_to_hms($time_spent_in_lp);
}

if (in_array('progress', $columnHeadersKeys)) {
$progress = self::get_avg_student_progress(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
if (in_array('progress', $columnHeadersKeys)) {
$progress = self::get_avg_student_progress(
$user->getId(),
$courseInfo['code'],
[$lpId],
$sessionId
);

if (is_numeric($progress)) {
$progress = sprintf(get_lang('XPercent'), $progress);
if (is_numeric($progress)) {
$progress = sprintf(get_lang('XPercent'), $progress);
}

$learningpathData[] = $progress;
}

$learningpathData[] = $progress;
}
if (in_array('score', $columnHeadersKeys)) {
$percentage_score = self::get_avg_student_score(
$user->getId(),
$courseInfo['code'],
[$lpId],
$sessionId
);

if (in_array('score', $columnHeadersKeys)) {
$percentage_score = self::get_avg_student_score(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
if (is_numeric($percentage_score)) {
$percentage_score = sprintf(get_lang('XPercent'), $percentage_score);
} else {
$percentage_score = sprintf(get_lang('XPercent'), 0);
}

if (is_numeric($percentage_score)) {
$percentage_score = sprintf(get_lang('XPercent'), $percentage_score);
} else {
$percentage_score = sprintf(get_lang('XPercent'), 0);
$learningpathData[] = $percentage_score;
}

$learningpathData[] = $percentage_score;
}
if (in_array('best_score', $columnHeadersKeys)) {
$bestScore = self::get_avg_student_score(
$user->getId(),
$courseInfo['code'],
[$lpId],
$sessionId,
false,
false,
true
);

if (in_array('best_score', $columnHeadersKeys)) {
$bestScore = self::get_avg_student_score(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId,
false,
false,
true
);
if (is_numeric($bestScore)) {
$bestScore = sprintf(get_lang('XPercent'), $bestScore);
} else {
$bestScore = '-';
}

if (is_numeric($bestScore)) {
$bestScore = sprintf(get_lang('XPercent'), $bestScore);
} else {
$bestScore = '-';
$learningpathData[] = $bestScore;
}

$learningpathData[] = $bestScore;
}
if (in_array('last_connection', $columnHeadersKeys)) {
$lastConnectionInLp = self::get_last_connection_time_in_lp(
$user->getId(),
$courseInfo['code'],
$lpId,
$sessionId
);

if (in_array('last_connection', $columnHeadersKeys)) {
$lastConnectionInLp = self::get_last_connection_time_in_lp(
$userId,
$courseInfo['code'],
$lpId,
$sessionId
);
$lastConnection = '-';

$lastConnection = '-';
if (!empty($lastConnectionInLp)) {
$lastConnection = api_convert_and_format_date($lastConnectionInLp, DATE_TIME_FORMAT_LONG);
}

$learningpathData[] = $lastConnection;
}

if (in_array('student_follow_page_add_LP_subscription_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpSubscription(
$learnpath,
$user->getId(),
$courseInfo['real_id'],
$sessionId
);
}

if (!empty($lastConnectionInLp)) {
$lastConnection = api_convert_and_format_date($lastConnectionInLp, DATE_TIME_FORMAT_LONG);
if (in_array('student_follow_page_add_LP_acquisition_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpAcquisition(
$learnpath,
$user->getId(),
$courseInfo['real_id'],
$sessionId
);
}

$learningpathData[] = $lastConnection;
$learningpathsTable->addRow($learningpathData);
}

if (in_array('student_follow_page_add_LP_subscription_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpSubscription(
$learnpath,
$userId,
$courseInfo['real_id'],
$sessionId
);
if ($learningpathsTable->getRowCount() < 2) {
continue;
}

if (in_array('student_follow_page_add_LP_acquisition_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpAcquisition(
$learnpath,
$userId,
$courseInfo['real_id'],
$sessionId
);
if ($countCategories > 1) {
$html[] = Display::tag('h5', $category->getName());
}

$learningpathsTable->addRow($learningpathData);
$html[] = Display::div(
$learningpathsTable->toHtml(),
['class' => 'table-responsive']
);
}

return Display::div(
$learningpathsTable->toHtml(),
['class' => 'table-responsive']
);
return implode(PHP_EOL, $html);
}
}

Expand Down

0 comments on commit 7aca771

Please sign in to comment.