From 41380c91c313dbcbc047657c7a155aeea36d16d6 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 16 Dec 2014 17:07:35 -0500 Subject: [PATCH] Add skills report for DRH role - refs BT#9084 --- main/inc/lib/skill.lib.php | 60 ++++++++++++++++ main/mySpace/course.php | 7 ++ main/mySpace/index.php | 4 ++ main/mySpace/session.php | 7 ++ main/mySpace/skills.php | 82 ++++++++++++++++++++++ main/mySpace/student.php | 6 +- main/mySpace/teachers.php | 6 +- main/template/default/my_space/skills.tpl | 84 +++++++++++++++++++++++ 8 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 main/mySpace/skills.php create mode 100644 main/template/default/my_space/skills.tpl diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 7c75a772c9..65299c2aff 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -1028,4 +1028,64 @@ class Skill extends Model return false; } + public function listAchievedByCourse($courseId) + { + $courseId = intval($courseId); + + if ($courseId == 0) { + return array(); + } + + $list = array(); + + $sql = "SELECT course.id c_id, course.title c_name, user.user_id, user.lastname, " + . "user.firstname, user.username, skill.id skill_id, skill.name skill_name, sru.acquired_skill_at " + . "FROM {$this->table_skill_rel_user} AS sru " + . "INNER JOIN {$this->table_course} " + . "ON sru.course_id = course.id " + . "INNER JOIN {$this->table_user} " + . "ON sru.user_id = user.user_id " + . "INNER JOIN {$this->table} " + . "ON sru.skill_id = skill.id " + . "WHERE course.id = $courseId"; + + $result = Database::query($sql); + + while ($row = Database::fetch_assoc($result)) { + $list[] = $row; + } + + return $list; + } + + public function listUsersWhoAchieved($skillId) + { + $skillId = intval($skillId); + + if ($skillId == 0) { + return array(); + } + + $list = array(); + + $sql = "SELECT course.id c_id, course.title c_name, user.user_id, user.lastname, " + . "user.firstname, user.username, skill.id skill_id, skill.name skill_name, sru.acquired_skill_at " + . "FROM {$this->table_skill_rel_user} AS sru " + . "INNER JOIN {$this->table_course} " + . "ON sru.course_id = course.id " + . "INNER JOIN {$this->table_user} " + . "ON sru.user_id = user.user_id " + . "INNER JOIN {$this->table} " + . "ON sru.skill_id = skill.id " + . "WHERE skill.id = $skillId"; + + $result = Database::query($sql); + + while ($row = Database::fetch_assoc($result)) { + $list[] = $row; + } + + return $list; + } + } diff --git a/main/mySpace/course.php b/main/mySpace/course.php index f9b82e75d8..29ac29c6aa 100755 --- a/main/mySpace/course.php +++ b/main/mySpace/course.php @@ -113,6 +113,13 @@ if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) { } } + if (api_is_drh()) { + $menu_items[] = Display::url( + Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM), + 'skills.php' + ); + } + echo '
'; $nb_menu_items = count($menu_items); if ($nb_menu_items > 1) { diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 93a566a1a8..0fbaf5efae 100755 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -107,6 +107,10 @@ if ($is_drh) { $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php'); $menu_items[] = Display::url(Display::return_icon('empty_evaluation.png', get_lang('CompanyReport'), array(), ICON_SIZE_MEDIUM), 'company_reports.php'); $menu_items[] = Display::url(Display::return_icon('evaluation_rate.png', get_lang('CompanyReportResumed'), array(), ICON_SIZE_MEDIUM), 'company_reports_resumed.php'); + $menu_items[] = Display::url( + Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM), + 'skills.php' + ); } echo '
'; diff --git a/main/mySpace/session.php b/main/mySpace/session.php index 61f14de7b2..cd9b1efff8 100755 --- a/main/mySpace/session.php +++ b/main/mySpace/session.php @@ -60,6 +60,13 @@ if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) { ); } + if (api_is_drh()) { + $menu_items[] = Display::url( + Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM), + 'skills.php' + ); + } + echo '
'; $nb_menu_items = count($menu_items); if ($nb_menu_items > 1) { diff --git a/main/mySpace/skills.php b/main/mySpace/skills.php new file mode 100644 index 0000000000..7c4fb385ae --- /dev/null +++ b/main/mySpace/skills.php @@ -0,0 +1,82 @@ + "index.php", "name" => get_lang('MySpace')); + +$toolName = get_lang('Skills'); + +$selectedCourse = isset($_REQUEST['course']) ? intval($_REQUEST['course']) : null; +$selectedSkill = isset($_REQUEST['skill']) ? intval($_REQUEST['skill']) : 0; + +$action = null; + +if (!empty($selectedCourse)) { + $action = 'filterByCourse'; +} else if (!empty($selectedSkill)) { + $action = 'filterBySkill'; +} + +$userId = api_get_user_id(); + +$courses = CourseManager::getCoursesFollowedByUser( + $userId, DRH, null, null, null, null, false +); + +$tableRows = array(); +$reportTitle = null; + +$objSkill = new Skill(); +$skills = $objSkill->get_all(); + +switch ($action) { + case 'filterByCourse': + $course = api_get_course_info_by_id($selectedCourse); + + $reportTitle = sprintf(get_lang('AchievedSkillByCourseX'), $course['name']); + + $tableRows = $objSkill->listAchievedByCourse($selectedCourse); + break; + case 'filterBySkill': + $skill = $objSkill->get($selectedSkill); + + $reportTitle = sprintf(get_lang('StudentsWhoAchievedTheSkillX'), $skill['name']); + + $students = UserManager::getUsersFollowedByUser($userId, STUDENT, false, false, false, null, null, null, null, + null, null, DRH); + + foreach ($students as $student) { + $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $student['user_id']); + } + + break; +} + +foreach ($tableRows as &$row) { + $row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']); + $row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER); +} + +/* + * View + */ +$tpl = new Template($toolName); + +$tpl->assign('courses', $courses); +$tpl->assign('skills', $skills); + +$tpl->assign('selectedCourse', $selectedCourse); +$tpl->assign('selectedSkill', $selectedSkill); + +$tpl->assign('reportTitle', $reportTitle); +$tpl->assign('rows', $tableRows); + +$contentTemplate = $tpl->get_template('my_space/skills.tpl'); + +$tpl->display($contentTemplate); diff --git a/main/mySpace/student.php b/main/mySpace/student.php index c72e0d6cfa..762bd831a4 100755 --- a/main/mySpace/student.php +++ b/main/mySpace/student.php @@ -186,7 +186,11 @@ if (api_is_drh()) { Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#'), Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'), Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'), - Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php') + Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php'), + Display::url( + Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM), + 'skills.php' + ) ); $nb_menu_items = count($menu_items); diff --git a/main/mySpace/teachers.php b/main/mySpace/teachers.php index 99f20d2d40..7df6a193e7 100755 --- a/main/mySpace/teachers.php +++ b/main/mySpace/teachers.php @@ -186,7 +186,11 @@ if (api_is_drh()) { Display::url(Display::return_icon('user.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), 'student.php'), Display::url(Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'), Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'), - Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php') + Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php'), + Display::url( + Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM), + 'skills.php' + ) ); $nb_menu_items = count($menu_items); diff --git a/main/template/default/my_space/skills.tpl b/main/template/default/my_space/skills.tpl new file mode 100644 index 0000000000..9c8afc575c --- /dev/null +++ b/main/template/default/my_space/skills.tpl @@ -0,0 +1,84 @@ +{% extends "default/layout/main.tpl" %} + +{% block body %} +
+ + +

{{ 'Skills' | get_lang }}

+ +
+
+
+ + + +
+
+
+
+ + + +
+
+
+ + + + {% if rows %} + + + + + + + + + + + {% for row in rows %} + + + + + + + {% endfor %} + +
{{ 'Course' | get_lang }}{{ 'Skill' | get_lang }}{{ 'Student' | get_lang }}{{ 'Date' | get_lang }}
{{ row.c_name }}{{ row.skill_name }}{{ row.completeName }}{{ row.achievedAt }}
+ {% else %} +
+ {{ 'NoResults' | get_lang }} +
+ {% endif %} +
+{% endblock %} \ No newline at end of file