Skip to content

Commit 927d0de

Browse files
committed
Refactor career diagram code BT#18720
1 parent 036fa15 commit 927d0de

File tree

10 files changed

+166
-147
lines changed

10 files changed

+166
-147
lines changed

main/admin/user_information.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@
702702
echo SessionManager::getCareerDiagramPerSession($session['session_id'], $userId);
703703
}
704704
}
705-
echo MyStudents::getBlockForCareers($userId);
705+
echo Display::page_subheader(get_lang('Careers'), null, 'h3', ['class' => 'section-title']);
706+
echo MyStudents::userCareersTable($userId);
706707
}
707708

708709
echo Display::page_subheader(get_lang('SessionList'), null, 'h3', ['class' => 'section-title']);

main/auth/my_progress.php

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,24 @@
6464
$course_info = api_get_course_info_by_id($result['c_id']);
6565
$course_image = '<img src="'.$course_info['course_image_large'].'">';
6666
$dates .= '<li><a href="#'.$login.'">'.api_convert_and_format_date($login, DATE_FORMAT_SHORT).'</a></li>';
67-
$issues .= '<li id ="'.$login.'">';
68-
$issues .= '<div class="img-course">'.$course_image.'</div>';
6967

70-
$issues .= '<div class="text-course">';
71-
$issues .= '<p>'.sprintf(
68+
$entered = sprintf(
7269
get_lang('YouHaveEnteredTheCourseXInY'),
7370
'" '.$courseInfo['name'].' "',
7471
api_convert_and_format_date($login, DATE_TIME_FORMAT_LONG)
75-
).'</p>';
76-
$issues .= '</div>';
77-
$issues .= '</li>';
72+
);
73+
74+
$issues .= '<li id ="'.$login.'">
75+
<div class="img-course">'.$course_image.'</div>
76+
<div class="text-course">
77+
<p>'.$entered.'</p>
78+
</div>
79+
</li>';
7880
$count++;
7981
}
8082
}
8183

82-
$content = Tracking::show_user_progress($user_id, $sessionId);
84+
$content = Tracking::showUserProgress($user_id, $sessionId);
8385
$showAllSessionCourses = api_get_configuration_value('my_progress_session_show_all_courses');
8486

8587
if ($showAllSessionCourses && !empty($sessionId) && empty($courseCode)) {
@@ -98,26 +100,26 @@
98100
}
99101

100102
if (!empty($dates)) {
101-
if (!empty($content)) {
102-
$content .= '';
103-
}
104103
$content .= Display::page_subheader(get_lang('Timeline'));
105-
$content .= '<div class="row">';
106-
$content .= '<div class="col-md-12">';
107-
$content .= '<div id="my_timeline">';
108-
$content .= '<ul id="dates">'.$dates.'</ul>';
109-
$content .= '<ul id="issues">'.$issues.'</ul>';
110-
$content .= '<div id="grad_left"></div>';
111-
$content .= '<div id="grad_right"></div>';
112-
$content .= '<a href="#" id="prev"></a>';
113-
$content .= '<a href="#" id="next"></a>';
114-
$content .= '</div></div>';
104+
$content .= '
105+
<div class="row">
106+
<div class="col-md-12">
107+
<div id="my_timeline">
108+
<ul id="dates">'.$dates.'</ul>
109+
<ul id="issues">'.$issues.'</ul>
110+
<div id="grad_left"></div>
111+
<div id="grad_right"></div>
112+
<a href="#" id="prev"></a>
113+
<a href="#" id="next"></a>
114+
</div>
115+
</div>
116+
</div>
117+
';
115118
}
116119

117120
if (api_get_configuration_value('private_messages_about_user_visible_to_user') === true) {
118121
$allowMessages = api_get_configuration_value('private_messages_about_user');
119122
if ($allowMessages === true) {
120-
// Messages
121123
$content .= Display::page_subheader2(get_lang('Messages'));
122124
$content .= MessageManager::getMessagesAboutUserToString(api_get_user_info());
123125
}
@@ -128,27 +130,6 @@
128130
$message = Display::return_message(get_lang('NoDataAvailable'), 'warning');
129131
}
130132

131-
if ($allowCareerUser) {
132-
$careers = UserManager::getUserCareers($user_id);
133-
134-
if (!empty($careers)) {
135-
$title = Display::page_subheader(get_lang('Careers'), null, 'h3', ['class' => 'section-title']);
136-
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
137-
$table->setHeaderContents(0, 0, get_lang('Career'));
138-
$table->setHeaderContents(0, 1, get_lang('Diagram'));
139-
140-
$row = 1;
141-
foreach ($careers as $careerData) {
142-
$table->setCellContents($row, 0, $careerData['name']);
143-
$url = api_get_path(WEB_CODE_PATH).'user/career_diagram.php?career_id='.$careerData['id'];
144-
$diagram = Display::url(get_lang('Diagram'), $url);
145-
$table->setCellContents($row, 1, $diagram);
146-
$row++;
147-
}
148-
$content = $title.$table->toHtml().$content;
149-
}
150-
}
151-
152133
$tpl = new Template($nameTools);
153134
$tpl->assign('message', $message);
154135
$tpl->assign('content', $content);

main/inc/lib/MyStudents.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22

33
/* For licensing terms, see /license.txt */
44

5-
/**
6-
* Class MyStudents.
7-
*/
85
class MyStudents
96
{
10-
public static function getBlockForCareers(int $studentId): ?string
7+
public static function userCareersTable(int $studentId): string
118
{
129
if (!api_get_configuration_value('allow_career_users')) {
13-
return null;
10+
return '';
1411
}
1512

1613
$careers = UserManager::getUserCareers($studentId);
1714

1815
if (empty($careers)) {
19-
return null;
16+
return '';
17+
}
18+
19+
return self::getCareersTable($careers);
20+
}
21+
22+
public static function getCareersTable(array $careers): string
23+
{
24+
if (empty($careers)) {
25+
return '';
2026
}
2127

2228
$webCodePath = api_get_path(WEB_CODE_PATH);
@@ -28,11 +34,11 @@ public static function getBlockForCareers(int $studentId): ?string
2834
];
2935

3036
$data = array_map(
31-
function (array $careerData) use ($webCodePath, $iconDiagram) {
32-
$url = $webCodePath.'user/career_diagram.php?career_id='.$careerData['id'];
37+
function (array $careerInfo) use ($webCodePath, $iconDiagram) {
38+
$url = $webCodePath.'user/career_diagram.php?career_id='.$careerInfo['id'];
3339

3440
return [
35-
$careerData['name'],
41+
$careerInfo['name'],
3642
Display::url($iconDiagram, $url),
3743
];
3844
},
@@ -43,10 +49,10 @@ function (array $careerData) use ($webCodePath, $iconDiagram) {
4349
$table->setHeaders($headers);
4450
$table->setData($data);
4551

46-
return Display::page_subheader(get_lang('Careers'), null, 'h3', ['class' => 'section-title'])
47-
.$table->toHtml();
52+
return $table->toHtml();
4853
}
4954

55+
5056
public static function getBlockForSkills(int $studentId, int $courseId, int $sessionId): string
5157
{
5258
$allowAll = api_get_configuration_value('allow_teacher_access_student_skills');

main/inc/lib/sessionmanager.lib.php

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9631,45 +9631,59 @@ public static function insertUsersInCourse(
96319631
}
96329632
}
96339633

9634+
public static function getCareersFromSession(int $sessionId): array
9635+
{
9636+
$extraFieldValueSession = new ExtraFieldValue('session');
9637+
$extraFieldValueCareer = new ExtraFieldValue('career');
9638+
9639+
$value = $extraFieldValueSession->get_values_by_handler_and_field_variable($sessionId, 'careerid');
9640+
$careers = [];
9641+
if (isset($value['value']) && !empty($value['value'])) {
9642+
$careerList = str_replace(['[', ']'], '', $value['value']);
9643+
$careerList = explode(',', $careerList);
9644+
$careerManager = new Career();
9645+
foreach ($careerList as $career) {
9646+
$careerIdValue = $extraFieldValueCareer->get_item_id_from_field_variable_and_field_value(
9647+
'external_career_id',
9648+
$career
9649+
);
9650+
if (isset($careerIdValue['item_id']) && !empty($careerIdValue['item_id'])) {
9651+
$finalCareerId = $careerIdValue['item_id'];
9652+
$careerInfo = $careerManager->get($finalCareerId);
9653+
if (!empty($careerInfo)) {
9654+
$careers[] = $careerInfo;
9655+
}
9656+
}
9657+
}
9658+
}
9659+
9660+
return $careers;
9661+
}
9662+
96349663
public static function getCareerDiagramPerSession($sessionId, $userId): string
96359664
{
96369665
$sessionId = (int) $sessionId;
96379666
$userId = (int) $userId;
96389667

9639-
$extraFieldValueSession = new ExtraFieldValue('session');
9640-
$extraFieldValueCareer = new ExtraFieldValue('career');
9641-
96429668
$visibility = api_get_session_visibility($sessionId, null, false, $userId);
96439669
$content = '';
96449670
if (SESSION_AVAILABLE === $visibility) {
9645-
$value = $extraFieldValueSession->get_values_by_handler_and_field_variable($sessionId, 'careerid');
9646-
if (isset($value['value']) && !empty($value['value'])) {
9647-
$careerList = str_replace(['[', ']'], '', $value['value']);
9648-
$careerList = explode(',', $careerList);
9649-
9650-
foreach ($careerList as $career) {
9651-
$careerIdValue = $extraFieldValueCareer->get_item_id_from_field_variable_and_field_value(
9652-
'external_career_id',
9653-
$career
9654-
);
9655-
if (isset($careerIdValue['item_id']) && !empty($careerIdValue['item_id'])) {
9656-
$finalCareerId = $careerIdValue['item_id'];
9657-
$career = new Career();
9658-
$careerInfo = $career->get($finalCareerId);
9659-
if (!empty($careerInfo)) {
9660-
$careerUrl = api_get_path(WEB_CODE_PATH).
9661-
'user/career_diagram.php?iframe=1&career_id='.$finalCareerId.'&user_id='.$userId;
9662-
$content .= '
9663-
<iframe
9664-
onload="resizeIFrame(this)"
9665-
style="width:100%;"
9666-
border="0"
9667-
frameborder="0"
9668-
src="'.$careerUrl.'"
9669-
></iframe>';
9670-
}
9671-
}
9672-
}
9671+
$careerList = self::getCareersFromSession($sessionId);
9672+
9673+
if (empty($careerList)) {
9674+
return '';
9675+
}
9676+
9677+
foreach ($careerList as $career) {
9678+
$careerUrl = api_get_path(WEB_CODE_PATH).'user/career_diagram.php?iframe=1&career_id='.$career['id'].'&user_id='.$userId;
9679+
$content .= '
9680+
<iframe
9681+
onload="resizeIframe(this)"
9682+
style="width:100%;"
9683+
border="0"
9684+
frameborder="0"
9685+
src="'.$careerUrl.'"
9686+
></iframe>';
96739687
}
96749688
}
96759689

@@ -9680,12 +9694,6 @@ public static function getCareerDiagramPerSession($sessionId, $userId): string
96809694
//iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
96819695
iFrame.height = iFrame.contentWindow.document.body.scrollHeight + 20;
96829696
}
9683-
/*window.addEventListener("DOMContentLoaded", function(e) {
9684-
var iframes = document.querySelectorAll("iframe");
9685-
for( var i = 0; i < iframes.length; i++) {
9686-
resizeIFrame(iframes[i]);
9687-
}
9688-
});*/
96899697
</script>
96909698
';
96919699
}

0 commit comments

Comments
 (0)