Add configuration "allow_private_skills" see BT#12902

- Skills can only visible for admins, teachers (related to a user via a course)
  and HRM users (if related to a user).
- Add new function to handle permissions in the skill tool
- Use Skill::isAllow() to block pages.
pull/2487/head
jmontoyaa 8 years ago
parent be7672d6ba
commit 940cfc55ab
  1. 2
      main/admin/index.php
  2. 11
      main/admin/skill_badge.php
  3. 15
      main/admin/skill_badge_create.php
  4. 5
      main/admin/skill_badge_list.php
  5. 6
      main/admin/skill_create.php
  6. 5
      main/admin/skill_edit.php
  7. 15
      main/admin/skill_list.php
  8. 5
      main/admin/skills.php
  9. 24
      main/admin/skills_gradebook.php
  10. 13
      main/admin/skills_profile.php
  11. 11
      main/admin/skills_wheel.php
  12. 2
      main/admin/user_information.php
  13. 11
      main/badge/assign.php
  14. 18
      main/badge/issued.php
  15. 29
      main/badge/issued_all.php
  16. 3
      main/badge/issuer.php
  17. 17
      main/gradebook/get_badges.php
  18. 3
      main/gradebook/lib/be/category.class.php
  19. 3
      main/gradebook/lib/fe/catform.class.php
  20. 6
      main/inc/ajax/skill.ajax.php
  21. 15
      main/inc/lib/course.lib.php
  22. 85
      main/inc/lib/skill.lib.php
  23. 4
      main/inc/lib/social.lib.php
  24. 9
      main/inc/lib/tracking.lib.php
  25. 116
      main/inc/lib/usermanager.lib.php
  26. 4
      main/inc/lib/userportal.lib.php
  27. 4
      main/install/configuration.dist.php
  28. 5
      main/mySpace/myStudents.php
  29. 6
      main/social/message_for_group_form.inc.php
  30. 46
      main/social/my_skills_report.php
  31. 29
      main/social/profile.php
  32. 10
      main/social/profile_friends_and_groups.inc.php
  33. 5
      main/social/skills_ranking.php
  34. 6
      main/social/skills_tree.php
  35. 22
      main/social/skills_wheel.php
  36. 4
      main/template/default/skill/drh_report.tpl
  37. 2
      main/template/default/skill/student_boss_report.tpl
  38. 2
      main/template/default/skill/student_report.tpl

@ -407,7 +407,7 @@ if (api_is_platform_admin()) {
$blocks['settings']['search_form'] = null;
// Skills
if (api_get_setting('allow_skills_tool') == 'true') {
if (Skill::isToolAvailable()) {
$blocks['skills']['icon'] = Display::return_icon(
'skill-badges.png',
get_lang('Skills'),

@ -11,9 +11,9 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
api_not_allowed(true);
}
api_protect_admin_script();
Skill::isAllow();
$backpack = 'https://backpack.openbadges.org/';
$configBackpack = api_get_setting('openbadges_backpack');
@ -33,10 +33,11 @@ $toolbar = Display::url(
'list_badges.png',
get_lang('ManageSkills'),
null,
ICON_SIZE_MEDIUM),
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH).'admin/skill_list.php',
['title' => get_lang('ManageSkills')]
);
);
$tpl = new Template(get_lang('Badges'));
$tpl->assign('backpack', $backpack);

@ -13,21 +13,18 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
api_not_allowed(true);
}
api_protect_admin_script();
Skill::isAllow();
$this_section = SECTION_PLATFORM_ADMIN;
$skillId = intval($_GET['id']);
$objSkill = new Skill();
$skill = $objSkill->get($skillId);
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/css/core.css" rel="stylesheet">';
// Add badge studio paths
$badgeStudio = [
'core' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/',
'media' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/',
@ -45,13 +42,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'id' => $skillId
);
if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) || !empty($_POST['badge_studio_image'])) {
if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) ||
!empty($_POST['badge_studio_image'])
) {
$dirPermissions = api_get_permissions_for_new_directories();
$fileName = sha1($_POST['name']);
$badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';
$existsBadgesDirectory = is_dir($badgePath);
if (!$existsBadgesDirectory) {
@ -68,7 +64,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
$skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
if (!empty($_POST['badge_studio_image'])) {
$badgeImage = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $_POST['badge_studio_image']));
file_put_contents($skillImagePath, $badgeImage);

@ -13,9 +13,8 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
api_not_allowed(true);
}
api_protect_admin_script();
Skill::isAllow();
$this_section = SECTION_PLATFORM_ADMIN;

@ -16,10 +16,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
@ -49,7 +46,6 @@ $allSkills = $objSkill->get_all();
$allGradebooks = $objGradebook->find('all');
// This procedure is for check if there is already a Skill with no Parent (Root by default)
$isAlreadyRootSkill = false;
foreach ($allSkills as $checkedSkill) {

@ -16,10 +16,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));

@ -14,10 +14,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$skillId = isset($_GET['id']) ? intval($_GET['id']) : 0;
@ -115,7 +112,7 @@ switch ($action) {
//no break
default:
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$toolbar = Display::url(
Display::return_icon(
'add.png',
@ -125,7 +122,7 @@ switch ($action) {
api_get_path(WEB_CODE_PATH).'admin/skill_create.php',
['title' => get_lang('CreateSkill')]
);
$toolbar .= Display::url(
Display::return_icon(
'wheel_skill.png',
@ -135,7 +132,7 @@ switch ($action) {
api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
['title' => get_lang('SkillsWheel')]
);
$toolbar .= Display::url(
Display::return_icon(
'edit-skill.png',
@ -145,7 +142,7 @@ switch ($action) {
api_get_path(WEB_CODE_PATH).'admin/skill_badge_list.php',
['title' => get_lang('BadgesManagement')]
);
$toolbar .= Display::url(
Display::return_icon(
'import_csv.png',
@ -155,7 +152,7 @@ switch ($action) {
api_get_path(WEB_CODE_PATH).'admin/skills_import.php',
['title' => get_lang('ImportSkillsListCSV')]
);
$extraField = new ExtraField('skill');
$arrayVals = $extraField->get_handler_field_info_by_tags('tags');
$tags = [];

@ -11,10 +11,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
//Adds the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');

@ -11,19 +11,14 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
//Adds the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display';
// setting breadcrumbs
$tool_name = get_lang('SkillsAndGradebooks');
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
if ($action == 'add_skill') {
@ -31,11 +26,9 @@ if ($action == 'add_skill') {
$tool_name = get_lang('Add');
}
Display::display_header($tool_name);
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
//The order is important you need to check the the $column variable in the model.ajax.php file
@ -84,13 +77,13 @@ $extra_params['height'] = 'auto';
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
//certificates
if (rowObject[4] == 1) {
return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL).'</a>'.'\';
} else {
return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL).''.'\';
}
}';
//certificates
if (rowObject[4] == 1) {
return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL).'</a>'.'\';
} else {
return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL).''.'\';
}
}';
?>
<script>
$(function() {
@ -120,7 +113,6 @@ switch ($action) {
}
}
$form->display();
//echo Display::tag('h2',$gradebook_info['name']);
break;
}
Display::display_footer();

@ -12,24 +12,19 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
$interbreadcrumb[] = array(
'url' => 'index.php',
"name" => get_lang('PlatformAdmin'),
);
$skill = new Skill();
$skill_profile = new SkillProfile();
$skill_rel_user = new SkillRelUser();
$skill = new Skill();
$skill_profile = new SkillProfile();
$skill_rel_user = new SkillRelUser();
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php';
$tpl = new Template(get_lang('Skills'));
$form = new FormValidator('profile_search');
$form->addElement('header', get_lang('SearchSkills'));

@ -11,10 +11,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(false, true);
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
Skill::isAllow();
//Adds the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_js('d3/d3.v3.5.4.min.js');
@ -60,7 +57,11 @@ $dialogForm->addLabel(
);
$dialogForm->addLabel(
get_lang('Description'),
Display::tag('p', null, ['id' => 'description', 'class' => 'form-control-static'])
Display::tag(
'p',
null,
['id' => 'description', 'class' => 'form-control-static']
)
);
$tpl->assign('dialogForm', $dialogForm->returnForm());

@ -107,7 +107,7 @@ if (api_is_platform_admin()) {
api_get_path(WEB_CODE_PATH).'admin/add_drh_to_user.php?u='.$userId
);
if (api_get_setting('allow_skills_tool') == 'true') {
if (Skill::isAllow($userId, false)) {
$actions[] = Display::url(
Display::return_icon(
'skill-badges.png',

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use \Skill as SkillManager;
use Chamilo\CoreBundle\Entity\Skill;
use Chamilo\CoreBundle\Entity\SkillRelUser;
use Chamilo\UserBundle\Entity\User;
@ -14,18 +15,14 @@ use Chamilo\UserBundle\Entity\User;
require_once __DIR__.'/../inc/global.inc.php';
if (!api_is_platform_admin(false, true) &&
!api_is_student_boss()
) {
api_not_allowed(true);
}
$userId = isset($_REQUEST['user']) ? (int) $_REQUEST['user'] : 0;
if (empty($userId)) {
api_not_allowed(true);
}
SkillManager::isAllow($userId);
$entityManager = Database::getManager();
$skillRepo = $entityManager->getRepository('ChamiloCoreBundle:Skill');
$skillRelSkill = $entityManager->getRepository('ChamiloCoreBundle:SkillRelSkill');
@ -132,7 +129,6 @@ $form->setDefaults($formDefaultValues);
if ($form->validate()) {
$values = $form->exportValues();
$skill = $skillRepo->find($values['skill']);
if (!$skill) {
@ -191,7 +187,6 @@ if ($form->validate()) {
$form->setDefaults(['user_name' => $user->getCompleteName()]);
$form->freeze(['user_name']);
if (api_is_drh()) {
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'mySpace/index.php',

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SkillRelUserComment;
/**
* Show information about the issued badge
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
@ -11,9 +13,8 @@ require_once __DIR__.'/../inc/global.inc.php';
$issue = isset($_REQUEST['issue']) ? intval($_REQUEST['issue']) : 0;
if (!$issue) {
header('Location: '.api_get_path(WEB_PATH));
exit;
if (empty($issue)) {
api_not_allowed(true);
}
$entityManager = Database::getManager();
@ -42,6 +43,8 @@ if (!$user || !$skill) {
exit;
}
Skill::isAllow($user->getId());
$userInfo = [
'id' => $user->getId(),
'complete_name' => $user->getCompleteName()
@ -120,7 +123,6 @@ $acquiredLevel = [];
$profile = $skillRepo->find($skillId)->getProfile();
if (!$profile) {
$skillRelSkill = new SkillRelSkill();
$parents = $skillRelSkill->get_skill_parents($skillId);
@ -142,7 +144,6 @@ if (!$profile) {
}
if ($profile) {
$profileId = $profile->getId();
$levels = $skillLevelRepo->findBy([
@ -159,7 +160,6 @@ if ($profile) {
$profileId = key($profileLevel);
$acquiredLevel[$profileId] = $profileLevel[$profileId];
}
}
$formAcquiredLevel = new FormValidator('acquired_level');
@ -196,14 +196,14 @@ $form->addButtonSend(get_lang('Send'));
if ($form->validate() && $allowComment) {
$values = $form->exportValues();
$skillUserComment = new Chamilo\CoreBundle\Entity\SkillRelUserComment();
$skillUserComment = new SkillRelUserComment();
$skillUserComment
->setFeedbackDateTime(new DateTime)
->setFeedbackGiver($currentUser)
->setFeedbackText($values['comment'])
->setFeedbackValue($values['value'] ? $values['value'] : null)
->setSkillRelUser($skillIssue);
->setSkillRelUser($skillIssue)
;
$entityManager->persist($skillUserComment);
$entityManager->flush();

@ -12,16 +12,14 @@ $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
if (!$userId || !$skillId) {
header('Location: '.api_get_path(WEB_PATH));
exit;
api_not_allowed(true);
}
$entityManager = Database::getManager();
$user = $entityManager->find('ChamiloUserBundle:User', $userId);
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
$skillRepo = $entityManager->getRepository('ChamiloCoreBundle:Skill');
$skillUserRepo = $entityManager->getRepository('ChamiloCoreBundle:SkillRelUser');
$skillLevelRepo = $entityManager->getRepository('ChamiloSkillBundle:Level');
Skill::isAllow($userId);
$em = Database::getManager();
$user = $em->find('ChamiloUserBundle:User', $userId);
$skill = $em->find('ChamiloCoreBundle:Skill', $skillId);
$currentUserId = api_get_user_id();
@ -34,6 +32,11 @@ if (!$user || !$skill) {
exit;
}
$skillRepo = $em->getRepository('ChamiloCoreBundle:Skill');
$skillUserRepo = $em->getRepository('ChamiloCoreBundle:SkillRelUser');
$skillLevelRepo = $em->getRepository('ChamiloSkillBundle:Level');
$userSkills = $skillUserRepo->findBy([
'user' => $user,
'skill' => $skill
@ -57,7 +60,7 @@ $skillInfo = [
$allUserBadges = [];
foreach ($userSkills as $index => $skillIssue) {
$currentUser = $entityManager->find('ChamiloUserBundle:User', $currentUserId);
$currentUser = $em->find('ChamiloUserBundle:User', $currentUserId);
$allowDownloadExport = $currentUser ? $currentUser->getId() === $user->getId() : false;
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $user) : false;
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
@ -164,8 +167,8 @@ foreach ($userSkills as $index => $skillIssue) {
$level = $skillLevelRepo->find($values['acquired_level']);
$skillIssue->setAcquiredLevel($level);
$entityManager->persist($skillIssue);
$entityManager->flush();
$em->persist($skillIssue);
$em->flush();
header("Location: ".$skillIssue->getIssueUrlAll());
exit;
@ -195,8 +198,8 @@ foreach ($userSkills as $index => $skillIssue) {
->setFeedbackValue($values['value'] ? $values['value'] : null)
->setSkillRelUser($skillIssue);
$entityManager->persist($skillUserComment);
$entityManager->flush();
$em->persist($skillUserComment);
$em->flush();
header("Location: ".$skillIssue->getIssueUrlAll());
exit;

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show information about the OpenBadge issuer
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
@ -14,4 +15,4 @@ $json = array(
'url' => api_get_path(WEB_PATH)
);
echo json_encode($json);
echo json_encode($json);

@ -9,31 +9,28 @@
require_once __DIR__.'/../inc/global.inc.php';
if (api_get_setting('allow_skills_tool') !== 'true') {
$userId = isset($_GET['user']) ? (int) $_GET['user'] : 0;
if (empty($userId)) {
api_not_allowed(true);
}
$userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
Skill::isAllow($userId);
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
if ($userId === 0) {
exit;
}
$objSkillRelUser = new SkillRelUser();
$userSkills = $objSkillRelUser->get_user_skills($userId, $courseId, $sessionId);
if (empty($userSkills)) {
exit;
api_not_allowed(true);
}
$assertions = array();
foreach ($userSkills as $skill) {
$skillId = current($skill);
$assertionUrl = api_get_path(WEB_CODE_PATH)."badge/assertion.php?";
$assertionUrl = api_get_path(WEB_CODE_PATH).'badge/assertion.php?';
$assertionUrl .= http_build_query(array(
'user' => $userId,
'skill' => $skillId,

@ -2118,7 +2118,6 @@ class Category implements GradebookItem
// A student always sees only the teacher's repartition
$scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT);
$userFinishedCourse = self::userFinishedCourse(
$user_id,
$cats_course[0],
@ -2132,7 +2131,7 @@ class Category implements GradebookItem
return false;
}
$skillToolEnabled = api_get_setting('allow_skills_tool') == 'true';
$skillToolEnabled = Skill::hasAccessToUserSkill(api_get_user_id(), $user_id);
$userHasSkills = false;
if ($skillToolEnabled) {

@ -232,7 +232,7 @@ class CatForm extends FormValidator
$skillsDefaults = [];
if (api_is_platform_admin() || api_is_drh()) {
if (api_get_setting('allow_skills_tool') == 'true') {
if (Skill::isToolAvailable()) {
$skillSelect = $this->addElement(
'select_ajax',
'skills',
@ -250,7 +250,6 @@ class CatForm extends FormValidator
// The magic should be here
$skills = $this->category_object->get_skills();
foreach ($skills as $skill) {
$skillsDefaults[] = $skill['id'];

@ -8,12 +8,10 @@ require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
if (api_get_setting('allow_skills_tool') != 'true') {
exit;
}
api_block_anonymous_users();
Skill::isAllow();
$skill = new Skill();
$gradebook = new Gradebook();
$skill_gradebook = new SkillRelGradebook();

@ -4287,18 +4287,15 @@ class CourseManager
'session_category_id' => $session_category_id
);
if (api_get_setting('allow_skills_tool') === 'true') {
$entityManager = Database::getManager();
$objUser = $entityManager->find('ChamiloUserBundle:User', $user_id);
$objCourse = $entityManager->find('ChamiloCoreBundle:Course', $course['real_id']);
$objSession = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
if (Skill::isAllow($user_id, false)) {
$em = Database::getManager();
$objUser = $em->find('ChamiloUserBundle:User', $user_id);
$objCourse = $em->find('ChamiloCoreBundle:Course', $course['real_id']);
$objSession = $em->find('ChamiloCoreBundle:Session', $session_id);
$skill = $entityManager
->getRepository('ChamiloCoreBundle:Skill')
->getLastByUser($objUser, $objCourse, $objSession);
$skill = $em->getRepository('ChamiloCoreBundle:Skill')->getLastByUser($objUser, $objCourse, $objSession);
$output['skill'] = null;
if ($skill) {
$output['skill']['name'] = $skill->getName();
$output['skill']['icon'] = $skill->getIcon();

@ -1594,4 +1594,89 @@ class Skill extends Model
return false;
}
/**
* If $studentId is set then check if current user has the right to see
* the page.
* @param int $studentId check if current user has access to see $studentId
* @param bool $blockPage raise a api_not_allowed()
*
* @return bool
*/
public static function isAllow($studentId = 0, $blockPage = true)
{
if (self::isToolAvailable()) {
if (api_is_platform_admin()) {
//return true;
}
if (!empty($studentId)) {
$currentUserId = api_get_user_id();
if ((int) $currentUserId === (int) $studentId) {
return true;
}
$haveAccess = self::hasAccessToUserSkill(
$currentUserId,
$studentId
);
if ($haveAccess) {
return true;
}
}
}
if ($blockPage) {
api_not_allowed(true);
}
return false;
}
/**
* @return bool
*/
public static function isToolAvailable()
{
$allowTool = api_get_setting('allow_skills_tool');
if ($allowTool == 'true') {
return true;
}
return false;
}
/**
* @param $currentUserId
* @param $studentId
* @return bool
*/
public static function hasAccessToUserSkill($currentUserId, $studentId)
{
if (self::isToolAvailable()) {
if (api_is_platform_admin()) {
return true;
}
$allow = api_get_configuration_value('allow_private_skills');
if ($allow === true) {
if (api_is_teacher()) {
return UserManager::isTeacherOfStudent(
$currentUserId,
$studentId
);
}
if (api_is_drh()) {
return UserManager::is_user_followed_by_drh(
$studentId,
$currentUserId
);
}
}
}
return false;
}
}

@ -2055,8 +2055,8 @@ class SocialManager extends UserManager
*/
public static function getSkillBlock($userId)
{
if (api_get_setting('allow_skills_tool') !== 'true') {
return null;
if (Skill::isAllow($userId, false) === false) {
return '';
}
$skill = new Skill();

@ -6342,20 +6342,19 @@ class Tracking
*/
public static function displayUserSkills($userId, $courseId = 0, $sessionId = 0)
{
if (Skill::isAllow($userId, false) === false) {
return '';
}
$userId = intval($userId);
$courseId = intval($courseId);
$sessionId = intval($sessionId);
if (api_get_setting('allow_skills_tool') !== 'true') {
return '';
}
$filter = ['user' => $userId];
$filter['course'] = $courseId ?: null;
$filter['session'] = $sessionId ?: null;
$em = Database::getManager();
$skillsRelUser = $em->getRepository('ChamiloCoreBundle:SkillRelUser')->findBy($filter);
$html = '

@ -4571,8 +4571,7 @@ class UserManager
$relationType,
$deleteUsersBeforeInsert = false,
$deleteOtherAssignedUsers = true
)
{
) {
$userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -4583,26 +4582,30 @@ class UserManager
if ($deleteOtherAssignedUsers) {
if (api_get_multiple_access_url()) {
// Deleting assigned users to hrm_id
$sql = "SELECT s.user_id FROM $userRelUserTable s
INNER JOIN $userRelAccessUrlTable a ON (a.user_id = s.user_id)
WHERE
friend_user_id = $userId AND
relation_type = $relationType AND
access_url_id = ".api_get_current_access_url_id();
$sql = "SELECT s.user_id
FROM $userRelUserTable s
INNER JOIN $userRelAccessUrlTable a
ON (a.user_id = s.user_id)
WHERE
friend_user_id = $userId AND
relation_type = $relationType AND
access_url_id = ".api_get_current_access_url_id();
} else {
$sql = "SELECT user_id FROM $userRelUserTable
WHERE friend_user_id = $userId
AND relation_type = $relationType";
$sql = "SELECT user_id
FROM $userRelUserTable
WHERE
friend_user_id = $userId AND
relation_type = $relationType";
}
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$sql = "DELETE FROM $userRelUserTable
WHERE
user_id = {$row['user_id']} AND
friend_user_id = $userId AND
relation_type = $relationType";
WHERE
user_id = {$row['user_id']} AND
friend_user_id = $userId AND
relation_type = $relationType";
Database::query($sql);
}
}
@ -4620,7 +4623,6 @@ class UserManager
if (is_array($subscribedUsersId)) {
foreach ($subscribedUsersId as $subscribedUserId) {
$subscribedUserId = intval($subscribedUserId);
$sql = "INSERT IGNORE INTO $userRelUserTable (user_id, friend_user_id, relation_type)
VALUES ($subscribedUserId, $userId, $relationType)";
@ -4757,9 +4759,14 @@ class UserManager
$cat = Category::load($category_id);
$displayscore = ScoreDisplay::instance();
if (isset($cat) && $displayscore->is_custom()) {
$grade = $displayscore->display_score(array($score, $cat[0]->get_weight()), SCORE_DIV_PERCENT_WITH_CUSTOM);
$grade = $displayscore->display_score(
array($score, $cat[0]->get_weight()),
SCORE_DIV_PERCENT_WITH_CUSTOM
);
} else {
$grade = $displayscore->display_score(array($score, $cat[0]->get_weight()));
$grade = $displayscore->display_score(
array($score, $cat[0]->get_weight())
);
}
$row['grade'] = $grade;
@ -4860,13 +4867,17 @@ class UserManager
/**
*
* @param int student id
* @param int years
* @param bool show warning_message
* @param bool return_timestamp
* @param int $student_id
* @param int $years
* @param bool $warning_message show warning_message
* @param bool $return_timestamp return_timestamp
*/
public static function delete_inactive_student($student_id, $years = 2, $warning_message = false, $return_timestamp = false)
{
public static function delete_inactive_student(
$student_id,
$years = 2,
$warning_message = false,
$return_timestamp = false
) {
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date FROM '.$tbl_track_login.'
WHERE login_user_id = '.intval($student_id).'
@ -5090,8 +5101,10 @@ class UserManager
public static function getTeachersList()
{
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$resultData = Database::select('user_id, lastname, firstname, username', $userTable, array(
$resultData = Database::select(
'user_id, lastname, firstname, username',
$userTable,
array(
'where' => array(
'status = ?' => COURSEMANAGER
)
@ -5117,9 +5130,7 @@ class UserManager
FROM $user
GROUP BY official_code";
$result = Database::query($sql);
$values = Database::store_result($result, 'ASSOC');
$result = array();
foreach ($values as $value) {
$result[$value['official_code']] = $value['official_code'];
@ -5504,4 +5515,53 @@ SQL;
return [];
}
/**
* Check if user is teacher of a student based in their courses
* @param $teacherId
* @param $studentId
* @return array
*/
public static function getCommonCoursesBetweenTeacherAndStudent($teacherId, $studentId)
{
$courses = CourseManager::getCoursesFollowedByUser($teacherId, COURSEMANAGER);
if (empty($courses)) {
return false;
}
$coursesFromUser = CourseManager::get_courses_list_by_user_id($studentId);
if (empty($coursesFromUser)) {
return false;
}
$coursesCodeList = array_column($courses, 'code');
$coursesCodeFromUserList = array_column($coursesFromUser, 'code');
$commonCourses = array_intersect($coursesCodeList, $coursesCodeFromUserList);
$commonCourses = array_filter($commonCourses);
if (!empty($commonCourses)) {
return $commonCourses;
}
return [];
}
/**
* @param $teacherId
* @param $studentId
* @return bool
*/
public static function isTeacherOfStudent($teacherId, $studentId)
{
$courses = self::getCommonCoursesBetweenTeacherAndStudent(
$teacherId,
$studentId
);
if (!empty($courses)) {
return true;
}
return false;
}
}

@ -402,7 +402,7 @@ class IndexManager
$items[] = $searchItem;
}
if (api_get_setting('allow_skills_tool') == 'true') {
if (Skill::isAllow(0, false)) {
$items[] = [
'icon' => Display::return_icon('skill-badges.png', get_lang('MySkills')),
'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php',
@ -419,7 +419,7 @@ class IndexManager
}
return self::show_right_block(
get_lang("Skills"),
get_lang('Skills'),
self::returnRightBlockItems($items),
'skill_block',
null,

@ -574,3 +574,7 @@ $_configuration['score_grade_model'] = [
//ALTER TABLE course_category ADD image varchar(255) NULL;
//$_configuration['my_courses_list_as_category'] = false;
// ------
// Skills can only visible for admins, teachers (related to a user via a course),
// and HRM users (if related to a user).
// $_configuration['allow_private_skills'] = false;

@ -405,9 +405,8 @@ if (api_can_login_as($student_id)) {
Display::return_icon('login_as.png', get_lang('LoginAs'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;';
}
if (api_is_platform_admin(false, true) ||
api_is_student_boss()
) {
if (Skill::isAllow($student_id, false)) {
echo Display::url(
Display::return_icon(
'skill-badges.png',

@ -106,8 +106,10 @@ if (api_get_setting('allow_message_tool') === 'true') {
$form->addElement(
'file',
'attach_1',
sprintf(get_lang('MaximunFileSizeX'),
format_file_size(api_get_setting('message_max_upload_filesize')))
sprintf(
get_lang('MaximunFileSizeX'),
format_file_size(api_get_setting('message_max_upload_filesize'))
)
);
$form->addButtonSend(get_lang('SendMessage'));

@ -9,6 +9,8 @@
require_once __DIR__.'/../inc/global.inc.php';
Skill::isAllow();
$isStudent = api_is_student();
$isStudentBoss = api_is_student_boss();
$isDRH = api_is_drh();
@ -19,18 +21,15 @@ if (!$isStudent && !$isStudentBoss && !$isDRH) {
}
$userId = api_get_user_id();
$skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
$skillRelUserTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tableRows = array();
$tpl = new Template(get_lang('Skills'));
$tplPath = null;
$tpl->assign('allowSkillsTool', api_get_setting('allow_skills_tool') === 'true');
$tpl->assign('allowDrhSkillsManagement', api_get_setting('allow_hr_skills_management') === 'true');
$tpl->assign('allow_skill_tool', api_get_setting('allow_skills_tool') === 'true');
$tpl->assign('allow_drh_skills_management', api_get_setting('allow_hr_skills_management') === 'true');
if ($isStudent) {
$sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
@ -40,14 +39,19 @@ if ($isStudent) {
LEFT JOIN $courseTable c
ON sru.course_id = c.id
WHERE sru.user_id = $userId";
$result = Database::query($sql);
while ($resultData = Database::fetch_assoc($result)) {
$tableRow = array(
'skillName' => $resultData['name'],
'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
'courseImage' => Display::return_icon(
'course.png',
null,
null,
ICON_SIZE_MEDIUM,
null,
true
),
'courseName' => $resultData['title']
);
@ -68,7 +72,7 @@ if ($isStudent) {
}
$tplPath = 'skill/student_report.tpl';
} else if ($isStudentBoss) {
} elseif ($isStudentBoss) {
$selectedStudent = isset($_REQUEST['student']) ? intval($_REQUEST['student']) : 0;
$tableRows = array();
$followedStudents = UserManager::getUsersFollowedByStudentBoss($userId);
@ -94,7 +98,14 @@ if ($isStudent) {
'completeName' => $followedStudents[$selectedStudent]['completeName'],
'skillName' => $resultData['name'],
'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
'courseImage' => Display::return_icon(
'course.png',
null,
null,
ICON_SIZE_MEDIUM,
null,
true
),
'courseName' => $resultData['title']
);
@ -118,15 +129,13 @@ if ($isStudent) {
$tplPath = 'skill/student_boss_report.tpl';
$tpl->assign('followedStudents', $followedStudents);
$tpl->assign('selectedStudent', $selectedStudent);
} else if ($isDRH) {
} elseif ($isDRH) {
$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)) {
} elseif (!empty($selectedSkill)) {
$action = 'filterBySkill';
}
@ -174,7 +183,14 @@ if ($isStudent) {
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);
$row['courseImage'] = Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true);
$row['courseImage'] = Display::return_icon(
'course.png',
null,
null,
ICON_SIZE_MEDIUM,
null,
true
);
$imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);

@ -29,7 +29,7 @@ $show_full_profile = true;
//social tab
$this_section = SECTION_SOCIAL;
//Initialize blocks
// Initialize blocks
$social_extra_info_block = null;
$social_course_block = null;
$social_group_info_block = null;
@ -64,7 +64,6 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
$url .= empty($_SERVER['QUERY_STRING']) ? '' : '?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
header('Location: '.$url);
exit;
} elseif (!empty($_POST['social_wall_new_msg']) && !empty($_POST['messageId'])) {
$messageId = intval($_POST['messageId']);
$messageContent = $_POST['social_wall_new_msg'];
@ -81,7 +80,6 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
$url .= empty($_SERVER['QUERY_STRING']) ? '' : '?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
header('Location: '.$url);
exit;
} elseif (isset($_GET['messageId'])) {
$messageId = intval($_GET['messageId']);
$messageInfo = MessageManager::get_message_by_id($messageId);
@ -96,7 +94,8 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
}
}
api_not_allowed(true);
} elseif (isset($_GET['u'])) { //I'm your friend? I can see your profile?
} elseif (isset($_GET['u'])) {
//I'm your friend? I can see your profile?
$user_id = intval($_GET['u']);
if (api_is_anonymous($user_id, true)) {
api_not_allowed(true);
@ -118,7 +117,8 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
USER_RELATION_TYPE_PARENT,
USER_RELATION_TYPE_FRIEND,
USER_RELATION_TYPE_GOODFRIEND
))) {
))
) {
$show_full_profile = true;
}
//checking the relationship between my friend and me
@ -130,7 +130,8 @@ if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp
USER_RELATION_TYPE_PARENT,
USER_RELATION_TYPE_FRIEND,
USER_RELATION_TYPE_GOODFRIEND
))) {
))
) {
$show_full_profile = true;
} else {
// im probably not a good friend
@ -167,7 +168,7 @@ if (file_exists($timeAgoLocaleDir)) {
}
$htmlHeadXtra[] = '<script>
$(document).ready(function (){
$(document).ready(function(){
var container = $("#wallMessages");
container.jscroll({
loadingHtml: "<div class=\"well_border\">' . get_lang('Loading').' </div>",
@ -217,7 +218,10 @@ Session::write('social_user_id', (int) $user_id);
// Setting some course info
$my_user_id = isset($_GET['u']) ? intval($_GET['u']) : api_get_user_id();
$personal_course_list = UserManager::get_personal_session_course_list($my_user_id, 50);
$personal_course_list = UserManager::get_personal_session_course_list(
$my_user_id,
50
);
$course_list_code = array();
$i = 1;
$list = [];
@ -262,7 +266,6 @@ $social_wall_block = $wallSocialAddPost;
// Social Post Wall
$posts = SocialManager::getWallMessagesByUser($my_user_id, $friendId);
$social_post_wall_block = empty($posts) ? '<p>'.get_lang("NoPosts").'</p>' : $posts;
$socialAutoExtendLink = Display::url(
@ -276,7 +279,6 @@ $socialAutoExtendLink = Display::url(
// Added a Jquery Function to return the Preview of OpenGraph URL Content
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
var getUrl = $("[name=\'social_wall_new_msg_main\']");
var matchUrl = /https?:\/\/w{0,3}\w*?\.(\w*?\.)?\w{2,3}\S*|www\.(\w*?\.)?\w*?\.\w{2,3}\S*|(\w*?\.)?\w*?\.\w{2,3}[\/\?]\S*/ ;
@ -371,7 +373,9 @@ if ($show_full_profile) {
$value_options = array();
// get option display text from user_field_options table
foreach ($id_options as $id_option) {
$sql = "SELECT display_text FROM $t_ufo WHERE id = '$id_option'";
$sql = "SELECT display_text
FROM $t_ufo
WHERE id = '$id_option'";
$res_options = Database::query($sql);
$row_options = Database::fetch_row($res_options);
$value_options[] = $row_options[0];
@ -421,9 +425,7 @@ if ($show_full_profile) {
// if there are information to show
if (!empty($extra_information_value)) {
$extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>';
$extra_information .= Display::panelCollapse(
get_lang('ExtraInformation'),
$extra_information_value,
@ -647,7 +649,6 @@ if ($show_full_profile) {
if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
|| !empty($user_info['openarea']) || !empty($user_info['teach'])) {
$more_info .= '<div><h3>'.get_lang('MoreInformation').'</h3></div>';
if (!empty($user_info['competences'])) {
$more_info .= '<br />';

@ -52,9 +52,7 @@ if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
$friend['lastName']
);
$friend_html .= '<div id=div_'.$friend['friend_user_id'].' class="image_friend_network" ><span><center>';
$userPicture = UserManager::getUserPicture($friend['friend_user_id']);
$friend_html .= '<a href="profile.php?u='.$friend['friend_user_id'].'">';
$friend_html .= '<img src="'.$userPicture.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" />';
$friend_html .= '</center></span>';
@ -95,12 +93,12 @@ if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
);
if ($count_users_group == 1) {
$count_users_group = $count_users_group.' '.get_lang(
'Member'
);
'Member'
);
} else {
$count_users_group = $count_users_group.' '.get_lang(
'Members'
);
'Members'
);
}
$picture = $userGroup->get_picture_group(
$result['id'],

@ -7,9 +7,11 @@
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
Skill::isAllow();
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
@ -79,7 +81,6 @@ $extra_params['autowidth'] = 'true';
//height auto
$extra_params['height'] = 'auto';
//$extra_params['excel'] = 'excel';
//$extra_params['rowList'] = array(10, 20 ,30);
$jqgrid = Display::grid_js(

@ -11,10 +11,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_MYPROFILE;
api_block_anonymous_users();
if (api_get_setting('allow_skills_tool') !== 'true') {
api_not_allowed();
}
Skill::isAllow(api_get_user_id());
//Adds the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
@ -24,7 +21,6 @@ $htmlHeadXtra[] = api_get_js('skills.js');
$skill = new Skill();
$type = 'read'; //edit
$tree = $skill->get_skills_tree(api_get_user_id(), null, true);
$skill_visualizer = new SkillVisualizer($tree, $type);
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1';

@ -7,14 +7,10 @@
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_SOCIAL;
if (api_get_setting('allow_skills_tool') !== 'true') {
api_not_allowed();
}
api_block_anonymous_users();
Skill::isAllow(api_get_user_id());
//Adds the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_js('d3/d3.v3.5.4.min.js');
@ -47,21 +43,25 @@ $dialogForm->addLabel(
Display::tag('p', null, ['id' => 'parent', 'class' => 'form-control-static'])
);
$dialogForm->addLabel(
[get_lang('Gradebook'), get_lang('WithCertificate')],
Display::tag('ul', null, ['id' => 'gradebook', 'class' => 'form-control-static list-unstyled'])
[
get_lang('Gradebook'),
get_lang('WithCertificate')
],
Display::tag(
'ul',
null,
['id' => 'gradebook', 'class' => 'form-control-static list-unstyled']
)
);
$dialogForm->addLabel(
get_lang('Description'),
Display::tag('p', null, ['id' => 'description', 'class' => 'form-control-static'])
);
$type = 'read'; //edit
$type = 'read';
$tree = $skill->get_skills_tree($userId, null, true);
$skill_visualizer = new SkillVisualizer($tree, $type);
$tpl->assign('skill_visualizer', $skill_visualizer);
//$html = $skill_visualizer->return_html();
//$tpl->assign('html', $html);
$tpl->assign('dialogForm', $dialogForm->returnForm());
$url = api_get_path(WEB_AJAX_PATH)."skill.ajax.php?a=get_skills_tree_json&load_user=$userId";

@ -1,7 +1,7 @@
{% if allowSkillsTool %}
{% if allow_skill_tool %}
<div class="btn-group">
<a class="btn btn-default" href="{{ _p.web_main }}social/skills_wheel.php">{{ 'SkillsWheel' | get_lang }}</a>
{% if allowDrhSkillsManagement %}
{% if allow_drh_skills_management %}
<a class="btn btn-default" href="{{ _p.web_main }}admin/skills_wheel.php">{{ 'ManageSkills' | get_lang }}</a>
{% endif %}
</div>

@ -1,4 +1,4 @@
{% if allowSkillsTool %}
{% if allow_skill_tool %}
<div class="btn-group">
<a class="btn btn-default" href="{{ _p.web_main }}social/skills_wheel.php">
{{ 'SkillsWheel' | get_lang }}

@ -1,4 +1,4 @@
{% if allowSkillsTool %}
{% if allow_skill_tool %}
<div class="btn-group">
<a class="btn btn-default" href="{{ _p.web_main }}social/skills_wheel.php">{{ 'SkillsWheel' | get_lang }}</a>
</div>

Loading…
Cancel
Save