Moving code to functions - refs BT#18671

pull/3864/head
Angel Fernando Quiroz Campos 5 years ago
parent 8e8bc1ef52
commit 64ff3f0a06
  1. 89
      main/inc/lib/MyStudents.php
  2. 2
      main/inc/lib/skill.lib.php
  3. 53
      main/mySpace/myStudents.php
  4. 14
      main/mySpace/student_follow_export.php
  5. 8
      main/template/default/my_space/student_follow_pdf.tpl

@ -0,0 +1,89 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class MyStudents.
*/
class MyStudents
{
public static function getBlockForCareers(int $studentId): ?string
{
if (!api_get_configuration_value('allow_career_users')) {
return null;
}
$careers = UserManager::getUserCareers($studentId);
if (empty($careers)) {
return null;
}
$webCodePath = api_get_path(WEB_CODE_PATH);
$langDiagram = get_lang('Diagram');
$headers = [
get_lang('Career'),
get_lang('Diagram'),
];
$data = array_map(
function (array $careerData) use ($webCodePath, $langDiagram) {
$url = $webCodePath.'user/career_diagram.php?career_id='.$careerData['id'];
return [
$careerData['name'],
Display::url($langDiagram, $url),
];
},
$careers
);
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$table->setHeaders($headers);
$table->setData($data);
return Display::page_subheader(get_lang('Careers'), null, 'h3', ['class' => 'section-title'])
.$table->toHtml();
}
public static function getBlockForSkills(int $studentId, int $courseId, int $sessionId): string
{
$allowAll = api_get_configuration_value('allow_teacher_access_student_skills');
if ($allowAll) {
// Show all skills
return Tracking::displayUserSkills($studentId, 0, 0, true);
}
// Default behaviour - Show all skills depending the course and session id
return Tracking::displayUserSkills($studentId, $courseId, $sessionId);
}
public static function getBlockForClasses($student_id): ?string
{
$userGroupManager = new UserGroup();
$userGroups = $userGroupManager->getNameListByUser(
$student_id,
UserGroup::NORMAL_CLASS
);
if (empty($userGroups)) {
return null;
}
$headers = [get_lang('Classes')];
$data = array_map(
function ($class) {
return [$class];
},
$userGroups
);
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$table->setHeaders($headers);
$table->setData($data);
return $table->toHtml();
}
}

@ -1458,7 +1458,7 @@ class Skill extends Model
}
if ($addTitle) {
$tableResult .= Display::page_subheader2(get_lang('AchievedSkills'));
$tableResult .= Display::page_subheader(get_lang('AchievedSkills'));
$tableResult .= '<div class="skills-badges">';
}

@ -943,62 +943,17 @@ $content = $tpl->fetch($templateName);
echo $content;
// Careers.
if (api_get_configuration_value('allow_career_users')) {
$careers = UserManager::getUserCareers($student_id);
if (!empty($careers)) {
echo '<br /><br />';
echo Display::page_subheader(get_lang('Careers'), null, 'h3', ['class' => 'section-title']);
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$table->setHeaderContents(0, 0, get_lang('Career'));
$table->setHeaderContents(0, 1, get_lang('Diagram'));
$row = 1;
foreach ($careers as $careerData) {
$table->setCellContents($row, 0, $careerData['name']);
$url = api_get_path(WEB_CODE_PATH).'user/career_diagram.php?career_id='.$careerData['id'];
$diagram = Display::url(get_lang('Diagram'), $url);
$table->setCellContents($row, 1, $diagram);
$row++;
}
echo $table->toHtml();
}
}
echo MyStudents::getBlockForCareers($student_id);
$allowAll = api_get_configuration_value('allow_teacher_access_student_skills');
if ($allowAll) {
// Show all skills
echo Tracking::displayUserSkills(
$student_id,
0,
0,
true
);
} else {
// Default behaviour - Show all skills depending the course and session id
echo Tracking::displayUserSkills(
echo MyStudents::getBlockForSkills(
$student_id,
$courseInfo ? $courseInfo['real_id'] : 0,
$sessionId
);
}
echo '<br /><br />';
echo '<div class="row">
<div class="col-sm-5">';
if (!empty($userGroups)) {
echo '<table class="table table-striped table-hover">
<thead>
<tr>
<th>';
echo get_lang('Classes');
echo '</th>
</tr>
</thead>
<tbody>';
foreach ($userGroups as $class) {
echo '<tr><td>'.$class.'</td></tr>';
}
echo '</tbody></table>';
}
echo '<div class="row"><div class="col-sm-5">';
echo MyStudents::getBlockForClasses($student_id);
echo '</div></div>';
$exportCourseList = [];

@ -506,6 +506,9 @@ if ($form->validate()) {
$view = new Template('', false, false, false, true, false, false);
$view->assign('user_info', $studentInfo);
$view->assign('carrers', MyStudents::getBlockForCareers($studentInfo['id']));
$view->assign('skills', Tracking::displayUserSkills($studentInfo['id']));
$view->assign('classes', MyStudents::getBlockForClasses($studentInfo['id']));
$view->assign('courses_info', $coursesInfo);
$template = $view->get_template('my_space/student_follow_pdf.tpl');
@ -517,7 +520,7 @@ if ($form->validate()) {
];
$css = api_get_print_css();
$css .= '
$css = '
.user-info { clear: both; }
.user-info__col { float: left; width: 33.33%; }
';
@ -527,7 +530,14 @@ if ($form->validate()) {
try {
$pdf->content_to_pdf(
$view->fetch($template),
$css
$css,
get_lang('StudentDetails'),
null,
'D',
false,
null,
false,
true
);
} catch (MpdfException $e) {
echo Display::return_message(get_lang('ErrorWhileBuildingReport'), 'error');

@ -35,6 +35,14 @@
<hr>
</div>
{{ carrers }}
{{ skills }}
<br><br>
{{ classes }}
{% for course_info in courses_info %}
<pagebreak>

Loading…
Cancel
Save