Skip to content

Commit

Permalink
Add assigned users course list for HRM - refs BT#12955
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jul 13, 2017
1 parent ac37de8 commit 762861a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
75 changes: 75 additions & 0 deletions main/auth/hrm_courses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/* For licensing terms, see /license.txt */

use Chamilo\CoreBundle\Entity\CourseRelUser,
Chamilo\CoreBundle\Entity\SessionRelCourseRelUser,
Chamilo\CoreBundle\Entity\Course;

require_once __DIR__.'/../inc/global.inc.php';

api_block_anonymous_users(true);

$isHrm = api_is_drh();

if (!$isHrm) {
api_not_allowed(true);
}

function formatCourseInfo(Course $course, $sessionId = 0, $showCourseCode = false)
{
$sysCoursePath = api_get_path(SYS_COURSE_PATH).$course->getDirectory();
$webCoursePath = api_get_path(WEB_COURSE_PATH).$course->getDirectory();

return [
'visibility' => $course->getVisibility(),
'link' => api_get_course_url($course->getCode(), $sessionId),
'category' => $course->getCategoryCode(),
'title' => $course->getTitle(),
'title_cut' => $course->getTitle(),
'code_course' => $showCourseCode ? $course->getCode() : null,
'image' => file_exists($sysCoursePath.'/course-pic.png')
? $webCoursePath.'/course-pic.png'
: Display::returnIconPath('session_default.png'),
'teachers' => api_get_setting('display_teacher_in_courselist') === 'true'
? $teachers = CourseManager::getTeachersFromCourse($course->getId(), true)
: []
];
}

$showCourseCode = api_get_configuration_value('display_coursecode_in_courselist') === 'true';

$hrm = api_get_user_entity(api_get_user_id());
$assignedUsers = UserManager::get_users_followed_by_drh($hrm->getId());
$users = [];

$courseController = new IndexManager('');

foreach ($assignedUsers as $assignedUserId => $assignedUserInfo) {
$assignedUser = api_get_user_entity($assignedUserId);

if (!$assignedUser) {
continue;
}

$userInfo = [
'username' => $assignedUser->getUsername(),
'complete_name' => $assignedUser->getCompleteName(),
'picture_url' => UserManager::getUserPicture($assignedUserId),
'course_list' => $courseController->returnCoursesAndSessions($assignedUserId)['html']
];

$users[$assignedUser->getId()] = $userInfo;
}

$toolName = get_lang('HrmAssignedUsersCourseList');

$view = new Template($toolName);
$view->assign('users', $users);

$content = $view->fetch(
$view->get_template('auth/hrm_courses.tpl')
);

$view->assign('header', $toolName);
$view->assign('content', $content);
$view->display_one_col_template();
9 changes: 5 additions & 4 deletions main/inc/lib/course.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3669,7 +3669,8 @@ public static function returnCourses($user_id, $load_dirs = false)
// We simply display the title of the category.
$courseInCategory = self::returnCoursesCategories(
$row['id'],
$load_dirs
$load_dirs,
$user_id
);

$params = [
Expand All @@ -3681,7 +3682,7 @@ public static function returnCourses($user_id, $load_dirs = false)
}

// Step 2: We display the course without a user category.
$coursesNotCategory = self::returnCoursesCategories(0, $load_dirs);
$coursesNotCategory = self::returnCoursesCategories(0, $load_dirs, $user_id);

if ($coursesNotCategory) {
$listItems['not_category'] = $coursesNotCategory;
Expand All @@ -3697,9 +3698,9 @@ public static function returnCourses($user_id, $load_dirs = false)
* @param bool $load_dirs Whether to show the document quick-loader or not
* @return string
*/
public static function returnCoursesCategories($user_category_id, $load_dirs = false)
public static function returnCoursesCategories($user_category_id, $load_dirs = false, $user_id = 0)
{
$user_id = api_get_user_id();
$user_id = $user_id ?: api_get_user_id();
$user_category_id = (int) $user_category_id;

// Table definitions
Expand Down
10 changes: 9 additions & 1 deletion main/inc/lib/userportal.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ public function return_navigation_links()
*/
public function return_course_block()
{
$isHrm = api_is_drh();
$show_create_link = false;
$show_course_link = false;
if (api_is_allowed_to_create_course()) {
Expand Down Expand Up @@ -1114,6 +1115,13 @@ public function return_course_block()
];
}

if ($isHrm) {
$items[] = [
'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
'title' => get_lang('HrmAssignedUsersCourseList')
];
}

// Course catalog
if ($show_course_link) {
if (!api_is_drh()) {
Expand Down Expand Up @@ -1785,7 +1793,7 @@ public function returnCoursesAndSessions($user_id)
}

return [
'html' => $specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse,
'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
'session_count' => $sessionCount,
'course_count' => $courseCount
];
Expand Down
18 changes: 18 additions & 0 deletions main/template/default/auth/hrm_courses.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% for user in users %}
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">
<img src="{{ user.picture_url }}" alt="{{ user.complete_name }}">
{{ user.complete_name }}
<small>{{ user.username }}</small>
</h3>
</div>
<div class="panel-body">
{% if not user.course_list %}
<div class="alert alert-warning">{{ 'UserHasNoCourse'|get_lang }}</div>
{% else %}
{{ user.course_list }}
{% endif %}
</div>
</div>
{% endfor %}

0 comments on commit 762861a

Please sign in to comment.