Add "allow_skill_rel_items" setting see BT#13334

Allows connect skills with course tools.
pull/2458/head
jmontoyaa 8 years ago
parent 0a1b19d699
commit 93a64d5f4a
  1. 3
      main/attendance/attendance_add.php
  2. 18
      main/attendance/attendance_controller.php
  3. 8
      main/attendance/attendance_edit.php
  4. 15
      main/exercise/exercise.class.php
  5. 10
      main/forum/editthread.php
  6. 59
      main/forum/forumfunction.inc.php
  7. 27
      main/gradebook/gradebook_display_summary.php
  8. 34
      main/gradebook/lib/be/abstractlink.class.php
  9. 7
      main/gradebook/lib/fe/evalform.class.php
  10. 4
      main/gradebook/lib/fe/gradebooktable.class.php
  11. 27
      main/gradebook/skill_rel_user.php
  12. 76
      main/inc/ajax/skill.ajax.php
  13. 27
      main/inc/lib/api.lib.php
  14. 17
      main/inc/lib/link.lib.php
  15. 370
      main/inc/lib/skill.lib.php
  16. 4
      main/install/configuration.dist.php
  17. 5
      main/link/link.php
  18. 4
      main/lp/learnpath.class.php
  19. 2
      main/lp/lp_add.php
  20. 1
      main/lp/lp_content.php
  21. 24
      main/lp/lp_controller.php
  22. 12
      main/lp/lp_edit.php
  23. 30
      main/survey/create_new_survey.php
  24. 2
      main/survey/survey.lib.php
  25. 38
      main/template/default/gradebook/skill_rel_user.tpl
  26. 2
      main/work/edit_work.php
  27. 2
      main/work/view.php
  28. 8
      main/work/work.lib.php
  29. 2
      main/work/work.php
  30. 57
      src/Chamilo/CoreBundle/Entity/Skill.php
  31. 29
      src/Chamilo/CoreBundle/Entity/SkillRelUser.php
  32. 363
      src/Chamilo/SkillBundle/Entity/SkillRelItem.php
  33. 169
      src/Chamilo/SkillBundle/Entity/SkillRelItemRelUser.php

@ -65,6 +65,9 @@ if ((api_get_session_id() != 0 && Gradebook::is_active()) || api_get_session_id(
);
$form->applyFilter('attendance_weight', 'html_filter');
$form->addElement('html', '</div>');
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_ATTENDANCE, 0);
$form->addElement('html', '</div>');
}
$form->addButtonCreate(get_lang('Save'));

@ -45,7 +45,6 @@ class AttendanceController
{
$attendance = new Attendance();
$data = [];
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
if (!empty($_POST['title'])) {
$check = Security::check_token();
@ -62,10 +61,15 @@ class AttendanceController
$link_to_gradebook = true;
}
$attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : 0;
$last_id = $attendance->attendance_add($link_to_gradebook);
$attendanceId = $attendance->attendance_add($link_to_gradebook);
if ($attendanceId) {
$form = new FormValidator('attendance_add');
Skill::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendanceId);
}
Security::clear_token();
}
header('Location: index.php?action=calendar_add&attendance_id='.$last_id.'&'.api_get_cidreq());
header('Location: index.php?action=calendar_add&attendance_id='.$attendanceId.'&'.api_get_cidreq());
exit;
} else {
$data['error'] = true;
@ -119,8 +123,13 @@ class AttendanceController
$link_to_gradebook = true;
}
$attendance->attendance_edit($attendance_id, $link_to_gradebook);
$form = new FormValidator('attendance_edit');
Skill::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendance_id);
Display::addFlash(Display::return_message(get_lang('Updated')));
Security::clear_token();
header('location:index.php?action=attendance_list&'.api_get_cidreq());
header('Location:index.php?action=attendance_list&'.api_get_cidreq());
exit;
}
} else {
@ -167,6 +176,7 @@ class AttendanceController
$attendance = new Attendance();
if (!empty($attendance_id)) {
$affected_rows = $attendance->attendance_delete($attendance_id);
Skill::deleteSkillsFromItem($attendance_id, ITEM_TYPE_ATTENDANCE);
}
if ($affected_rows) {

@ -44,8 +44,8 @@ $form->addHtmlEditor(
]
);
// Adavanced Parameters
// Advanced Parameters
$skillList = [];
if (Gradebook::is_active()) {
if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
$form->addButtonAdvancedSettings('id_qualify');
@ -81,6 +81,9 @@ if (Gradebook::is_active()) {
);
$form->applyFilter('attendance_weight', 'html_filter');
$form->addElement('html', '</div>');
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_ATTENDANCE, $attendance_id);
$form->addElement('html', '</div>');
}
$form->addButtonUpdate(get_lang('Save'));
@ -90,6 +93,7 @@ $default['title'] = Security::remove_XSS($title);
$default['description'] = Security::remove_XSS($description, STUDENT);
$default['attendance_qualify_title'] = $attendance_qualify_title;
$default['attendance_weight'] = $attendance_weight;
$default['skills'] = array_keys($skillList);
$link_info = GradebookUtils::isResourceInCourseGradebook(
api_get_course_id(),

@ -1850,8 +1850,8 @@ class Exercise
*/
public function delete()
{
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $TBL_EXERCISES SET active='-1'
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $table SET active='-1'
WHERE c_id = ".$this->course_id." AND id = ".intval($this->id);
Database::query($sql);
@ -1870,6 +1870,8 @@ class Exercise
api_get_user_id()
);
Skill::deleteSkillsFromItem($this->iId, ITEM_TYPE_EXERCISE);
if (api_get_setting('search_enabled') == 'true' &&
extension_loaded('xapian')
) {
@ -2498,7 +2500,7 @@ class Exercise
}
}
//$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_EXERCISE, $this->iId);
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_EXERCISE, $this->iId);
$form->addElement('html', '</div>'); //End advanced setting
$form->addElement('html', '</div>');
@ -2564,7 +2566,7 @@ class Exercise
} else {
$defaults['enabletimercontroltotalminutes'] = 0;
}
//$defaults['skills'] = array_keys($skillList);
$defaults['skills'] = array_keys($skillList);
$defaults['notifications'] = $this->getNotifications();
} else {
$defaults['exerciseType'] = 2;
@ -2709,9 +2711,9 @@ class Exercise
}
$iId = $this->save($type);
/*if (!empty($iId)) {
if (!empty($iId)) {
Skill::saveSkills($form, ITEM_TYPE_EXERCISE, $iId);
}*/
}
}
public function search_engine_save()
@ -6077,7 +6079,6 @@ class Exercise
);
$html = '<div class="question-result">';
if (api_get_configuration_value('save_titles_as_html')) {
$html .= $this->get_formated_title();
$html .= Display::page_header(get_lang('Result'));

@ -179,7 +179,7 @@ $form->addElement('text', 'thread_title', get_lang('Title'));
$form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
if ((api_is_course_admin() || api_is_session_general_coach() || api_is_course_tutor()) && ($threadId)) {
if ((api_is_course_admin() || api_is_session_general_coach() || api_is_course_tutor()) && $threadId) {
// Thread qualify
if (Gradebook::is_active()) {
//Loading gradebook select
@ -224,6 +224,8 @@ if ($forumSettings['allow_sticky'] && api_is_allowed_to_edit(null, true)) {
$form->addElement('html', '</div>');
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_FORUM_THREAD, $threadId);
if (!empty($threadData)) {
$defaults['thread_qualify_gradebook'] = ($threadData['threadQualifyMax'] > 0 && empty($_POST)) ? 1 : 0;
$defaults['thread_title'] = prepare4display($threadData['threadTitle']);
@ -240,16 +242,20 @@ if (!empty($threadData)) {
$defaults['thread_peer_qualify'] = 0;
}
$defaults['skills'] = array_keys($skillList);
$form->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
if ($form->validate()) {
$redirectUrl = api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$forumId.'&'.api_get_cidreq();
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
Security::clear_token();
updateThread($values);
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId);
header('Location: '.$redirectUrl);
exit;
}

@ -101,7 +101,7 @@ function handle_forum_and_forumcategories($lp_id = null)
$get_id = isset($_GET['id']) ? intval($_GET['id']) : '';
$forum_categories_list = get_forum_categories();
//Verify if forum category exists
// Verify if forum category exists
if (empty($forum_categories_list)) {
$get_content = 'forumcategory';
}
@ -117,10 +117,9 @@ function handle_forum_and_forumcategories($lp_id = null)
if ((($action_forum_cat == 'add' || $action_forum_cat == 'edit') && $get_content == 'forum') ||
$post_submit_forum
) {
$inputvalues = [];
if ($action_forum_cat == 'edit' && $get_id || $post_submit_forum) {
$inputvalues = get_forums($get_id);
} else {
$inputvalues = [];
}
$content = show_add_forum_form($inputvalues, $lp_id);
}
@ -246,10 +245,9 @@ function show_add_forum_form($inputvalues = [], $lp_id)
$form = new FormValidator('forumcategory', 'post', 'index.php?'.api_get_cidreq());
// The header for the form
$form_title = get_lang('AddForum');
if (!empty($inputvalues)) {
$form_title = get_lang('EditForum');
} else {
$form_title = get_lang('AddForum');
}
$form->addElement('header', $form_title);
@ -387,6 +385,10 @@ function show_add_forum_form($inputvalues = [], $lp_id)
'filetype',
['jpg', 'jpeg', 'png', 'gif']
);
//$forumId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
//$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_FORUM, $forumId);
$form->addElement('html', '</div>');
// The OK button
@ -433,14 +435,24 @@ function show_add_forum_form($inputvalues = [], $lp_id)
$defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null;
$defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
}
// $defaults['skills'] = array_keys($skillList);
$form->setDefaults($defaults);
// Validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->getSubmitValues();
$return_message = store_forum($values);
Display::addFlash(Display::return_message($return_message, 'confirmation'));
$forumId = store_forum($values, '', true);
if ($forumId) {
// Skill::saveSkills($form, ITEM_TYPE_FORUM, $forumId);
if (isset($values['forum_id'])) {
Display::addFlash(Display::return_message(get_lang('ForumEdited'), 'confirmation'));
} else {
Display::addFlash(Display::return_message(get_lang('ForumAdded'), 'confirmation'));
}
}
}
Security::clear_token();
} else {
@ -647,11 +659,9 @@ function store_forum($values, $courseInfo = [], $returnId = false)
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$course_id = $courseInfo['real_id'];
$session_id = api_get_session_id();
$group_id = api_get_group_id();
if (isset($values['group_id']) && !empty($values['group_id'])) {
$group_id = $values['group_id'];
} else {
$group_id = api_get_group_id();
}
$groupInfo = [];
if (!empty($group_id)) {
@ -677,11 +687,10 @@ function store_forum($values, $courseInfo = [], $returnId = false)
// Forum images
$image_moved = false;
$has_attachment = false;
$image_moved = true;
if (!empty($_FILES['picture']['name'])) {
$upload_ok = process_uploaded_file($_FILES['picture']);
$has_attachment = true;
} else {
$image_moved = true;
}
// Remove existing picture if it was requested.
@ -765,6 +774,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
);
$return_message = get_lang('ForumEdited');
$forumId = $values['forum_id'];
} else {
if ($image_moved) {
$new_file_name = isset($new_file_name) ? $new_file_name : '';
@ -793,31 +803,32 @@ function store_forum($values, $courseInfo = [], $returnId = false)
'forum_id' => 0
];
$last_id = Database::insert($table_forums, $params);
if ($last_id > 0) {
$sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $last_id";
$forumId = Database::insert($table_forums, $params);
if ($forumId > 0) {
$sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $forumId";
Database::query($sql);
api_item_property_update(
$courseInfo,
TOOL_FORUM,
$last_id,
$forumId,
'ForumAdded',
api_get_user_id(),
$groupInfo
);
api_set_default_visibility(
$last_id,
$forumId,
TOOL_FORUM,
$group_id,
$courseInfo
);
}
$return_message = get_lang('ForumAdded');
if ($returnId) {
return $last_id;
}
}
if ($returnId) {
return $forumId;
}
return $return_message;
@ -911,6 +922,7 @@ function deleteForumCategoryThread($content, $id)
if ($content == 'thread') {
$tool_constant = TOOL_FORUM_THREAD;
$return_message = get_lang('ThreadDeleted');
Skill::deleteSkillsFromItem($id, ITEM_TYPE_FORUM_THREAD);
}
api_item_property_update(
@ -2624,8 +2636,8 @@ function store_thread(
$visible = 1;
}
$clean_post_title = $values['post_title'];
// We first store an entry in the forum_thread table because the thread_id is used in the forum_post table.
// We first store an entry in the forum_thread table because the thread_id is used in the forum_post table.
$lastThread = new CForumThread();
$lastThread
->setCId($course_id)
@ -2975,6 +2987,10 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
$form->addElement('html', '</div>');
}
if ($action == 'newthread') {
Skill::addSkillsToForm($form, ITEM_TYPE_FORUM_THREAD, 0);
}
if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $action == 'newthread') {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
@ -3082,6 +3098,7 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
switch ($action) {
case 'newthread':
$myThread = store_thread($current_forum, $values);
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $myThread);
break;
case 'quote':
case 'replythread':

@ -129,21 +129,42 @@ if (count($userList) > 0) {
}
echo '</div>';
$allowSkillRelItem = api_get_configuration_value('allow_skill_rel_items');
if (count($userList) == 0) {
echo Display::return_message(get_lang('NoResultsAvailable'), 'warning');
} else {
echo '<br /><br /><table class="data_table">';
echo '<tr><th>';
echo get_lang('Student');
echo '</th>';
echo '<th>';
echo get_lang('Action');
echo '</th></tr>';
foreach ($userList as $index => $value) {
echo '<tr>
<td width="100%" >'.
get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].') </td>';
<td width="70%">'
.api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].') </td>';
echo '<td>';
$link = '';
if ($allowSkillRelItem) {
$url = api_get_path(WEB_CODE_PATH).'gradebook/skill_rel_user.php?'.api_get_cidreq().'&user_id='.$value['user_id'].'&selectcat='.$cat_id;
$link = Display::url(
get_lang('Skills'),
$url,
['class' => 'btn btn-default']
).'&nbsp;';
}
$url = api_get_self().'?'.api_get_cidreq().'&action=download&user_id='.$value['user_id'].'&selectcat='.$cat_id;
$link = Display::url(
$link .= Display::url(
get_lang('ExportToPDF'),
$url,
['target' => '_blank', 'class' => 'btn btn-default']
);
echo $link;
echo '</td></tr>';
}

@ -695,4 +695,38 @@ abstract class AbstractLink implements GradebookItem
return [];
}
/**
* @return string
*/
public function getSkillsFromItem()
{
$toolType = '';
switch ($this->type) {
case LINK_ATTENDANCE:
$toolType = ITEM_TYPE_ATTENDANCE;
break;
case LINK_EXERCISE:
$toolType = ITEM_TYPE_EXERCISE;
break;
case LINK_FORUM_THREAD:
$toolType = ITEM_TYPE_FORUM_THREAD;
break;
case LINK_LEARNPATH:
$toolType = ITEM_TYPE_LEARNPATH;
break;
case LINK_HOTPOTATOES:
$toolType = ITEM_TYPE_HOTPOTATOES;
break;
case LINK_STUDENTPUBLICATION:
$toolType = ITEM_TYPE_STUDENT_PUBLICATION;
break;
case LINK_SURVEY:
$toolType = ITEM_TYPE_SURVEY;
break;
}
$skillToString = Skill::getSkillRelItemsToString($toolType, $this->get_ref_id());
return $skillToString;
}
}

@ -130,9 +130,7 @@ class EvalForm extends FormValidator
{
//extra field for check on maxvalue
$this->addElement('header', get_lang('EditResult'));
$renderer = &$this->defaultRenderer();
// set new form template
$form_template = '<form{attributes}>
<table class="data_table" border="0" cellpadding="5" cellspacing="5">{content}
@ -179,7 +177,6 @@ class EvalForm extends FormValidator
foreach ($results_and_users as $result_and_user) {
$user = $result_and_user['user'];
$result = $result_and_user['result'];
$renderer = &$this->defaultRenderer();
$this->addFloat(
'score['.$result->get_id().']',
@ -254,7 +251,7 @@ class EvalForm extends FormValidator
</form>'
);
$tblusers = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code());
$users = GradebookUtils::get_users_in_course($this->evaluation_object->get_course_code());
$nr_users = 0;
//extra field for check on maxvalue
$this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max());
@ -284,7 +281,7 @@ class EvalForm extends FormValidator
}
$firstUser = true;
foreach ($tblusers as $user) {
foreach ($users as $user) {
$element_name = 'score['.$user[0].']';
$scoreColumnProperties = ['maxlength' => 5];
if ($firstUser) {

@ -1073,18 +1073,18 @@ class GradebookTable extends SortableTable
$url = $item->get_link();
$text = $item->get_name();
if (isset($url) && $show_message === false) {
$text = '&nbsp;<a href="'.$item->get_link().'">'
.$item->get_name()
.'</a>';
} else {
$text = $item->get_name();
}
$extra = Display::label($item->get_type_name(), 'info');
if ($type == 'simple') {
$extra = '';
}
$extra .= $item->getSkillsFromItem();
$text .= "&nbsp;".$extra.$show_message;
$cc = $this->currentcat->get_course_code();

@ -1,9 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
use Chamilo\SkillBundle\Entity\SkillRelItem;
exit;
require_once __DIR__.'/../inc/global.inc.php';
if (api_get_configuration_value('allow_skill_rel_items') == false) {
api_not_allowed(true);
@ -15,6 +15,7 @@ $courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0;
$categoryId = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
$userInfo = api_get_user_info($userId);
if (empty($userInfo)) {
@ -35,14 +36,21 @@ if (!empty($userSkills)) {
}
}
/** @var \Chamilo\SkillBundle\Entity\SkillRelItem $skill */
$em = Database::getManager();
/** @var SkillRelItem $skill */
foreach ($skills as $skill) {
$skillId = $skill->getSkill()->getId();
$uniqueSkills[$skillId] = $skill->getSkill();
$itemInfo = Skill::getItemInfo($skill->getItemId(), $skill->getItemType());
$itemInfo['status'] = in_array($skillId, $userSkillsList);
$itemInfo['status'] = false;
$criteria = [
'user' => $userId,
'skillRelItem' => $skill
];
$skillRelItemRelUser = $em->getRepository('ChamiloSkillBundle:SkillRelItemRelUser')->findOneBy($criteria);
$itemInfo['status'] = $skillRelItemRelUser ? true : false;
$itemsPerSkill[$skillId][]['info'] = $itemInfo;
}
@ -57,6 +65,15 @@ foreach ($itemsPerSkill as $skillId => $skillList) {
$uniqueSkillsConclusion[$skillId] = $allSkillsCompleted;
}
$interbreadcrumb[] = [
'url' => Category::getUrl(),
'name' => get_lang('Gradebook')
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'gradebook/gradebook_display_summary.php?'.api_get_cidreq().'&selectcat='.$categoryId,
'name' => get_lang('GradebookListOfStudentsReports')
];
$template = new Template(get_lang('SkillUserList'));
$template->assign('conclusion_list', $uniqueSkillsConclusion);
$template->assign('skills', $uniqueSkills);

@ -53,13 +53,11 @@ switch ($action) {
//Only course gradebook with certificate
if (!empty($gradebooks)) {
foreach ($gradebooks as $gradebook) {
if ($gradebook['parent_id'] == 0 && !empty($gradebook['certif_min_score']) && !empty($gradebook['document_id'])) {
if ($gradebook['parent_id'] == 0 &&
!empty($gradebook['certif_min_score']) &&
!empty($gradebook['document_id'])
) {
$gradebook_list[] = $gradebook;
//$gradebook['name'] = $gradebook['name'];
//$gradebook_list[] = $gradebook;
} else {
// $gradebook['name'] = $gradebook_list[$gradebook['parent_id']]['name'].' > '.$gradebook['name'];
//$gradebook_list[] = $gradebook;
}
}
}
@ -134,7 +132,6 @@ switch ($action) {
$template = Display::$global_template->get_template('skill/skill_info.tpl');
$html = Display::$global_template->fetch($template);
}
echo $html;
break;
case 'get_skills_tree_json':
@ -174,7 +171,6 @@ switch ($action) {
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$load_user_data = isset($_REQUEST['load_user_data']) ? $_REQUEST['load_user_data'] : null;
$skills = $skill->getChildren($id, $load_user_data);
$return = [];
foreach ($skills as $skill) {
if (isset($skill['data']) && !empty($skill['data'])) {
@ -268,10 +264,8 @@ switch ($action) {
Display::$global_template->assign('total_search_skills', $count_skills);
$skill_list = [];
if (!empty($total_skills_to_search)) {
$total_skills_to_search = $skill->getSkillsInfo($total_skills_to_search);
foreach ($total_skills_to_search as $skill_info) {
$skill_list[$skill_info['id']] = $skill_info;
}
@ -368,6 +362,68 @@ switch ($action) {
'items' => $returnSkills
]);
break;
case 'update_skill_rel_user':
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
if (empty($allowSkillInTools)) {
exit;
}
if (!api_is_allowed_to_edit()) {
exit;
}
$creatorId = api_get_user_id();
$typeId = isset($_REQUEST['type_id']) ? (int) $_REQUEST['type_id'] : 0;
$itemId = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : 0;
$skillId = isset($_REQUEST['skill_id']) ? (int) $_REQUEST['skill_id'] : 0;
$userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0;
$courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
if (!empty($typeId) && !empty($itemId) && !empty($skillId) && !empty($userId) && !empty($courseId)) {
$em = Database::getManager();
$user = api_get_user_entity($userId);
$skill = $em->getRepository('ChamiloCoreBundle:Skill')->find($skillId);
if (empty($user) || empty($skill)) {
exit;
}
$course = api_get_course_entity($courseId);
if (empty($course)) {
exit;
}
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
/** @var \Chamilo\SkillBundle\Entity\SkillRelItem $skillRelItem */
$skillRelItem = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findOneBy(
['itemId' => $itemId, 'itemType' => $typeId, 'skill' => $skillId]
);
if ($skillRelItem) {
$criteria = [
'user' => $userId,
'skillRelItem' => $skillRelItem
];
$skillRelItemRelUser = $em->getRepository('ChamiloSkillBundle:SkillRelItemRelUser')->findOneBy($criteria);
if ($skillRelItemRelUser) {
$em->remove($skillRelItemRelUser);
$em->flush();
$skillRelItemRelUser = null;
} else {
$skillRelItemRelUser = new Chamilo\SkillBundle\Entity\SkillRelItemRelUser();
$skillRelItemRelUser
->setUser($user)
->setSkillRelItem($skillRelItem)
->setCreatedBy($creatorId)
->setUpdatedBy($creatorId)
;
$em->persist($skillRelItemRelUser);
$em->flush();
}
}
echo Skill::getUserSkillStatusLabel($skillRelItem, $skillRelItemRelUser, false);
}
break;
default:
echo '';
}

@ -498,6 +498,18 @@ define('EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED', 8);
define('EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED', 9);
define('EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM', 10);
// Used to save the skill_rel_item table
define('ITEM_TYPE_EXERCISE', 1);
define('ITEM_TYPE_HOTPOTATOES', 2);
define('ITEM_TYPE_LINK', 3);
define('ITEM_TYPE_LEARNPATH', 4);
define('ITEM_TYPE_GRADEBOOK', 5);
define('ITEM_TYPE_STUDENT_PUBLICATION', 6);
//define('ITEM_TYPE_FORUM', 7);
define('ITEM_TYPE_ATTENDANCE', 8);
define('ITEM_TYPE_SURVEY', 9);
define('ITEM_TYPE_FORUM_THREAD', 10);
// one big string with all question types, for the validator in pear/HTML/QuickForm/Rule/QuestionType
define(
'QUESTION_TYPES',
@ -1936,6 +1948,18 @@ function api_get_course_info($course_code = null, $strict = false)
return $_course;
}
/**
* @param int $courseId
* @return \Chamilo\CoreBundle\Entity\Course
*/
function api_get_course_entity($courseId)
{
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
return Database::getManager()->getRepository('ChamiloCoreBundle:Course')->find($courseId);
}
/**
* Returns the current course info array.
@ -6613,6 +6637,8 @@ function api_get_asset($file)
/**
* Returns the <script> HTML tag
* @param string $file
* @param string $media
* @return string
*/
function api_get_css_asset($file, $media = 'screen')
@ -6623,6 +6649,7 @@ function api_get_css_asset($file, $media = 'screen')
/**
* Returns the <link> HTML tag
* @param string $file
* @param string $media
*/
function api_get_css($file, $media = 'screen')
{

@ -167,15 +167,13 @@ class Link extends Model
$description = Security::remove_XSS($_POST['description']);
$selectcategory = Security::remove_XSS($_POST['category_id']);
if (!isset($_POST['on_homepage'])) {
$onhomepage = 0;
} else {
$onhomepage = 0;
if (isset($_POST['on_homepage'])) {
$onhomepage = Security::remove_XSS($_POST['on_homepage']);
}
if (empty($_POST['target'])) {
$target = '_self'; // Default target.
} else {
$target = '_self'; // Default target.
if (!empty($_POST['target'])) {
$target = Security::remove_XSS($_POST['target']);
}
@ -201,7 +199,6 @@ class Link extends Model
return false;
} else {
// Looking for the largest order number for this category.
$link = new Link();
$params = [
'c_id' => $course_id,
@ -317,6 +314,7 @@ class Link extends Model
}
}
Display::addFlash(Display::return_message(get_lang('LinkAdded')));
return $link_id;
}
} elseif ($type == 'category') {
$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
@ -366,6 +364,7 @@ class Link extends Model
}
Display::addFlash(Display::return_message(get_lang('CategoryAdded')));
return $linkId;
}
}
@ -393,7 +392,6 @@ class Link extends Model
}
$result = false;
switch ($type) {
case 'link':
// -> Items are no longer physically deleted,
@ -411,6 +409,7 @@ class Link extends Model
api_get_user_id()
);
self::delete_link_from_search_engine(api_get_course_id(), $id);
Skill::deleteSkillsFromItem($id, ITEM_TYPE_LINK);
Display::addFlash(Display::return_message(get_lang('LinkDeleted')));
$result = true;
break;
@ -1798,8 +1797,10 @@ class Link extends Model
}
}
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LINK, $linkId);
$form->addHidden('lp_id', $lpId);
$form->addButtonSave(get_lang('SaveLink'), 'submitLink');
$defaults['skills'] = array_keys($skillList);
$form->setDefaults($defaults);
return $form;

@ -6,6 +6,7 @@ use Chamilo\UserBundle\Entity\Repository\UserRepository;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Graph;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\SkillBundle\Entity\SkillRelItem;
/**
* Class SkillProfile
@ -639,7 +640,6 @@ class Skill extends Model
}
$path = api_get_path(WEB_UPLOAD_PATH).'badges/';
if (!empty($result['icon'])) {
$iconSmall = sprintf(
"%s-small.png",
@ -1327,10 +1327,9 @@ class Skill extends Model
$isHierarchicalTable = api_get_configuration_value('table_of_hierarchical_skill_presentation');
$allowLevels = api_get_configuration_value('skill_levels_names');
$tableResult = '<div id="skillList">';
if ($isHierarchicalTable) {
$tableResult = '<div class="table-responsive">';
} else {
$tableResult = '<div id="skillList">';
}
if ($addTitle) {
@ -2323,4 +2322,369 @@ class Skill extends Model
return $actions;
}
/**
* @param \Chamilo\SkillBundle\Entity\SkillRelItem $skillRelItem
* @param \Chamilo\SkillBundle\Entity\SkillRelItemRelUser $skillRelItemRelUser
* @param bool $addHeader
* @return string
*/
public static function getUserSkillStatusLabel($skillRelItem, $skillRelItemRelUser, $addHeader = true)
{
if (empty($skillRelItem)) {
return '';
}
$type = 'success';
if (empty($skillRelItemRelUser)) {
$type = 'danger';
}
$label = '';
$skill = $skillRelItem->getSkill();
if ($addHeader) {
$label .= '<span id="'.$skill->getId().'" class="user_skill" style="cursor:pointer">';
}
$label .= Display::label($skill->getName(), $type);
if ($addHeader) {
$label .= '</span>&nbsp;';
}
return $label;
}
/**
* Assign a user with a SkilRelItem object
*
* @param FormValidator $form
* @param int $typeId see ITEM_TYPE_* constants
* @param int $itemId
* @param int $userId
*/
public static function addSkillsToUserForm(FormValidator $form, $typeId, $itemId, $userId)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
if ($allowSkillInTools && !empty($typeId) && !empty($itemId) && !empty($userId)) {
$em = Database::getManager();
$items = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['itemId' => $itemId, 'itemType' => $typeId]
);
$skillRelUser = new SkillRelUser();
$skillUserList = $skillRelUser->getUserSkills($userId);
if (!empty($skillUserList)) {
$skillUserList = array_column($skillUserList, 'skill_id');
}
$skills = '';
/** @var SkillRelItem $skillRelItem */
foreach ($items as $skillRelItem) {
$criteria = [
'user' => $userId,
'skillRelItem' => $skillRelItem
];
$skillRelItemRelUser = $em->getRepository('ChamiloSkillBundle:SkillRelItemRelUser')->findOneBy($criteria);
$skills .= self::getUserSkillStatusLabel($skillRelItem, $skillRelItemRelUser);
}
if (!empty($skills)) {
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=update_skill_rel_user&'.api_get_cidreq();
$params = [
'item_id' => $itemId,
'type_id' => $typeId,
'user_id' => $userId,
'course_id' => api_get_course_int_id(),
'session_id' => api_get_session_id()
];
$params = json_encode($params);
$html = '
<script>
$(function() {
$(".user_skill").on("click", function() {
var skillId = this.id;
var params = '.$params.';
$.ajax({
type: "GET",
async: false,
data: params,
url: "'.$url.'&skill_id="+skillId,
success: function(result) {
$("#" +skillId+ ".user_skill").html(result);
}
});
});
});
</script>
';
$form->addHtml($html);
$form->addLabel(get_lang('Skills'), $skills);
}
}
}
/**
* Add skills select ajax for an item (exercise, lp)
* @param FormValidator $form
* @param int $typeId see ITEM_TYPE_* constants
* @param int $itemId
* @throws Exception
* @return array
*/
public static function addSkillsToForm(FormValidator $form, $typeId, $itemId = 0)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
if (!$allowSkillInTools) {
return [];
}
$skillList = [];
if (!empty($itemId)) {
$em = Database::getManager();
$items = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['itemId' => $itemId, 'itemType' => $typeId]
);
/** @var SkillRelItem $skillRelItem */
foreach ($items as $skillRelItem) {
$skillList[$skillRelItem->getSkill()->getId()] = $skillRelItem->getSkill()->getName();
}
}
$form->addSelectAjax(
'skills',
get_lang('Skills'),
$skillList,
[
'url' => api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=search_skills',
'multiple' => 'multiple',
]
);
return $skillList;
}
/**
* @param int $courseId
* @param int $sessionId
* @return array
*/
public static function getSkillRelItemsPerCourse($courseId, $sessionId = null)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
$skills = [];
if (empty($sessionId)) {
$sessionId = null;
}
if ($allowSkillInTools) {
$em = Database::getManager();
$skills = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['courseId' => $courseId, 'sessionId' => $sessionId]
);
}
return $skills;
}
/**
* @param int $itemId
* @param int $itemType
* @return array
*/
public static function getItemInfo($itemId, $itemType)
{
$itemInfo = [];
$itemId = (int) $itemId;
$itemType = (int) $itemType;
$em = Database::getManager();
switch ($itemType) {
case ITEM_TYPE_EXERCISE:
/** @var \Chamilo\CourseBundle\Entity\CQuiz $item */
$item = $em->getRepository('ChamiloCourseBundle:CQuiz')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getTitle();
}
break;
case ITEM_TYPE_HOTPOTATOES:
break;
case ITEM_TYPE_LINK:
/** @var \Chamilo\CourseBundle\Entity\CLink $item */
$item = $em->getRepository('ChamiloCourseBundle:CLink')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getTitle();
}
break;
case ITEM_TYPE_LEARNPATH:
/** @var \Chamilo\CourseBundle\Entity\CLp $item */
$item = $em->getRepository('ChamiloCourseBundle:CLp')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getName();
}
break;
case ITEM_TYPE_GRADEBOOK:
break;
case ITEM_TYPE_STUDENT_PUBLICATION:
/** @var \Chamilo\CourseBundle\Entity\CStudentPublication $item */
$item = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getTitle();
}
break;
//ITEM_TYPE_FORUM', 7);
case ITEM_TYPE_ATTENDANCE:
/** @var \Chamilo\CourseBundle\Entity\CAttendance $item */
$item = $em->getRepository('ChamiloCourseBundle:CAttendance')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getName();
}
break;
case ITEM_TYPE_SURVEY:
/** @var \Chamilo\CourseBundle\Entity\CSurvey $item */
$item = $em->getRepository('ChamiloCourseBundle:CSurvey')->find($itemId);
if ($item) {
$itemInfo['name'] = strip_tags($item->getTitle());
}
break;
case ITEM_TYPE_FORUM_THREAD:
/** @var \Chamilo\CourseBundle\Entity\CForumThread $item */
$item = $em->getRepository('ChamiloCourseBundle:CForumThread')->find($itemId);
if ($item) {
$itemInfo['name'] = $item->getThreadTitle();
}
break;
}
return $itemInfo;
}
/**
* @param int $typeId
* @param int $itemId
* @return array
*/
public static function getSkillRelItems($typeId, $itemId)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
$skills = [];
if ($allowSkillInTools) {
$em = Database::getManager();
$skills = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['itemId' => $itemId, 'itemType' => $typeId]
);
}
return $skills;
}
/**
* @param int $typeId
* @param int $itemId
*
* @return string
*/
public static function getSkillRelItemsToString($typeId, $itemId)
{
$skills = self::getSkillRelItems($typeId, $itemId);
$skillToString = '';
if (!empty($skills)) {
/** @var SkillRelItem $skillRelItem */
$skillList = [];
foreach ($skills as $skillRelItem) {
$skillList[] = Display::label($skillRelItem->getSkill()->getName(), 'success');
}
$skillToString = '&nbsp;'.implode(' ', $skillList);
}
return $skillToString;
}
/**
* @param int $itemId
* @param int $typeId
*/
public static function deleteSkillsFromItem($itemId, $typeId)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
if ($allowSkillInTools) {
$itemId = (int) $itemId;
$typeId = (int) $typeId;
$em = Database::getManager();
// Delete old ones
$items = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['itemId' => $itemId, 'itemType' => $typeId]
);
/** @var SkillRelItem $skillRelItem */
foreach ($items as $skillRelItem) {
$em->remove($skillRelItem);
}
$em->flush();
}
}
/**
* Relate skill with an item (exercise, gradebook, lp, etc)
* @param FormValidator $form
* @param int $typeId
* @param int $itemId
* @throws \Doctrine\ORM\OptimisticLockException
*/
public static function saveSkills($form, $typeId, $itemId)
{
$allowSkillInTools = api_get_configuration_value('allow_skill_rel_items');
if ($allowSkillInTools) {
$userId = api_get_user_id();
$courseId = api_get_course_int_id();
if (empty($courseId)) {
$courseId = null;
}
$sessionId = api_get_session_id();
if (empty($sessionId)) {
$sessionId = null;
}
$em = Database::getManager();
$skills = (array) $form->getSubmitValue('skills');
// Delete old ones
$items = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findBy(
['itemId' => $itemId, 'itemType' => $typeId]
);
if (!empty($items)) {
/** @var SkillRelItem $skillRelItem */
foreach ($items as $skillRelItem) {
if (!in_array($skillRelItem->getSkill()->getId(), $skills)) {
$em->remove($skillRelItem);
}
}
$em->flush();
}
// Add new one
if (!empty($skills)) {
foreach ($skills as $skillId) {
/** @var \Chamilo\CoreBundle\Entity\Skill $skill */
$skill = $em->getRepository('ChamiloCoreBundle:Skill')->find($skillId);
if ($skill) {
if (!$skill->hasItem($typeId, $itemId)) {
$skillRelItem = new SkillRelItem();
$skillRelItem
->setItemType($typeId)
->setItemId($itemId)
->setCourseId($courseId)
->setSessionId($sessionId)
->setCreatedBy($userId)
->setUpdatedBy($userId)
;
$skill->addItem($skillRelItem);
$em->persist($skill);
$em->flush();
}
}
}
}
}
}
}

@ -733,6 +733,10 @@ $_configuration['gradebook_badge_sidebar'] = [
//$_configuration['allow_teachers_to_access_blocked_lp_by_prerequisite'] = false;
// Allow connect skills with course tools
// Uncomment doctrine tags for Entities:
//SkillRelItemRelUser|SkillRelItem|SkillRelUser.validation_status|Skill.items
// DB changes:
//$_configuration['allow_skill_rel_items'] = false;
// Generate random login when importing users

@ -107,7 +107,9 @@ switch ($action) {
$form = Link::getLinkForm(null, 'addlink', $token);
if ($form->validate() && Security::check_token('get')) {
// Here we add a link
Link::addlinkcategory("link");
$linkId = Link::addlinkcategory('link');
Skill::saveSkills($form, ITEM_TYPE_LINK, $linkId);
Security::clear_token();
header('Location: '.$linkListUrl);
exit;
@ -119,6 +121,7 @@ switch ($action) {
$form = Link::getLinkForm($id, 'editlink');
if ($form->validate()) {
Link::editLink($id, $form->getSubmitValues());
Skill::saveSkills($form, ITEM_TYPE_LINK, $id);
header('Location: '.$linkListUrl);
exit;
}

@ -3439,7 +3439,6 @@ class learnpath
public function get_link($type = 'http', $item_id = null, $provided_toc = false)
{
$course_id = $this->get_course_int_id();
if ($this->debug > 0) {
error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')', 0);
}
@ -3456,7 +3455,7 @@ class learnpath
}
//still empty, this means there was no item_id given and we are not in an object context or
//the object property is empty, return empty link
$item_id = $this->first();
$this->first();
return '';
}
@ -12322,6 +12321,7 @@ EOD;
$main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
$link = '';
$extraParams = api_get_cidreq(true, true, 'learnpath').'&session_id='.$session_id;
switch ($type) {
case 'dir':
return $main_dir_path.'lp/blank.php';

@ -151,6 +151,8 @@ $form->addElement('html', '<div id="end_date_div" style="display:none;">');
$form->addDatePicker('expired_on', get_lang('ExpirationDate'));
$form->addElement('html', '</div>');
Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);
$form->addElement('html', '</div>');
$defaults['activate_start_date_check'] = 1;

@ -40,6 +40,7 @@ foreach ($list as $toc) {
$dir = true;
}
}
if ($dir) {
$src = 'blank.php';
} else {

@ -283,21 +283,21 @@ if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
if (is_numeric($lp_id)) {
$sel = "SELECT lp_type FROM $lp_table WHERE c_id = $course_id AND id = $lp_id";
$sel = "SELECT iid, lp_type FROM $lp_table WHERE c_id = $course_id AND id = $lp_id";
if ($debug > 0) {
error_log('New LP - querying '.$sel, 0);
}
$res = Database::query($sel);
if (Database::num_rows($res)) {
$row = Database::fetch_array($res);
$lpIid = $row['iid'];
$type = $row['lp_type'];
if ($debug > 0) {
error_log('New LP - found row - type '.$type.' - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
}
switch ($type) {
case 1:
$oLP = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
$oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
if ($oLP !== false) {
$lp_found = true;
} else {
@ -305,7 +305,7 @@ if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $
}
break;
case 2:
$oLP = new scorm(api_get_course_id(), $lp_id, api_get_user_id());
$oLP = new scorm(api_get_course_id(), $lpIid, api_get_user_id());
if ($oLP !== false) {
$lp_found = true;
} else {
@ -313,7 +313,7 @@ if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $
}
break;
case 3:
$oLP = new aicc(api_get_course_id(), $lp_id, api_get_user_id());
$oLP = new aicc(api_get_course_id(), $lpIid, api_get_user_id());
if ($oLP !== false) {
$lp_found = true;
} else {
@ -321,7 +321,7 @@ if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $
}
break;
default:
$oLP = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
$oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
if ($oLP !== false) {
$lp_found = true;
} else {
@ -605,6 +605,11 @@ switch ($action) {
);
if (is_numeric($new_lp_id)) {
// Create temp form validator to save skills
$form = new FormValidator('lp_add');
$form->addSelect('skills', 'skills');
Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $new_lp_id);
// TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
$_SESSION['oLP'] = new learnpath(
api_get_course_id(),
@ -863,6 +868,9 @@ switch ($action) {
} else {
Session::write('refresh', 1);
$_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
Skill::deleteSkillsFromItem($_GET['lp_id'], ITEM_TYPE_LEARNPATH);
Display::addFlash(Display::return_message(get_lang('Deleted')));
Session::erase('oLP');
require 'lp_list.php';
@ -1028,6 +1036,10 @@ switch ($action) {
$_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
}
$form = new FormValidator('form1');
$form->addSelect('skills', 'skills');
Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());
if (api_get_setting('search_enabled') === 'true') {
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
$specific_fields = get_specific_field_list();

@ -10,11 +10,12 @@ require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
api_protect_course_script();
$show_description_field = false; //for now
$nameTools = get_lang('Doc');
$this_section = SECTION_COURSES;
Event::event_access_tool(TOOL_LEARNPATH);
$lpId = $_SESSION['oLP']->get_id();
if (api_is_in_gradebook()) {
$interbreadcrumb[] = [
'url' => Category::getUrl(),
@ -26,7 +27,7 @@ $interbreadcrumb[] = [
'name' => get_lang('LearningPaths')
];
$interbreadcrumb[] = [
'url' => api_get_self()."?action=build&lp_id=".$_SESSION['oLP']->get_id().'&'.api_get_cidreq(),
'url' => api_get_self()."?action=build&lp_id=".$lpId.'&'.api_get_cidreq(),
'name' => $_SESSION['oLP']->get_name()
];
@ -214,15 +215,17 @@ $form->addElement(
$enableLpExtraFields = false;
if ($enableLpExtraFields) {
$extraField = new ExtraField('lp');
$extra = $extraField->addElements($form, $_SESSION['oLP']->get_id());
$extra = $extraField->addElements($form, $lpId);
}
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, $lpId);
// Submit button
$form->addButtonSave(get_lang('SaveLPSettings'));
// Hidden fields
$form->addElement('hidden', 'action', 'update_lp');
$form->addElement('hidden', 'lp_id', $_SESSION['oLP']->get_id());
$form->addElement('hidden', 'lp_id', $lpId);
if ($enableLpExtraFields) {
$htmlHeadXtra[] = '<script>
@ -235,6 +238,7 @@ if ($enableLpExtraFields) {
$defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00' ? api_get_local_time($publicated_on) : null;
$defaults['expired_on'] = (!empty($expired_on)) ? api_get_local_time($expired_on) : date('Y-m-d 12:00:00', time() + 84600);
$defaults['subscribe_users'] = $_SESSION['oLP']->getSubscribeUsers();
$defaults['skills'] = array_keys($skillList);
$form->setDefaults($defaults);
Display::display_header(get_lang('CourseSettings'), 'Path');

@ -36,7 +36,7 @@ if (!api_is_allowed_to_edit()) {
}
// Getting the survey information
$survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$survey_id = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null;
$survey_data = SurveyManager::get_survey($survey_id);
// Additional information
@ -160,8 +160,20 @@ if (api_get_configuration_value('hide_survey_reporting_button')) {
$form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults);
}
//$defaults['visible_results'] = 0;
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]);
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]);
$form->addElement(
'html_editor',
'survey_introduction',
get_lang('SurveyIntroduction'),
null,
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]
);
$form->addElement(
'html_editor',
'survey_thanks',
get_lang('SurveyThanks'),
null,
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]
);
$extraField = new ExtraField('survey');
$extraField->addElements($form, $survey_id);
@ -261,20 +273,17 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && !empty($survey_id)) {
}
}
}
$form->addElement('html', '</div>');
}
}
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_SURVEY, $survey_id);
$form->addElement('html', '</div><br />');
if (isset($_GET['survey_id']) && $_GET['action'] == 'edit') {
$class = 'save';
$text = get_lang('ModifySurvey');
$form->addButtonUpdate(get_lang('ModifySurvey'), 'submit_survey');
} else {
$class = 'add';
$text = get_lang('CreateSurvey');
$form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey');
}
@ -293,6 +302,8 @@ $form->addRule(
'lte'
);
$defaults['skills'] = array_keys($skillList);
// Setting the default values
$form->setDefaults($defaults);
@ -302,13 +313,14 @@ if ($form->validate()) {
$values = $form->getSubmitValues();
// Storing the survey
$return = SurveyManager::store_survey($values);
Skill::saveSkills($form, ITEM_TYPE_SURVEY, $return['id']);
$values['item_id'] = $return['id'];
$extraFieldValue = new ExtraFieldValue('survey');
$extraFieldValue->saveFieldValues($values);
// Redirecting to the survey page (whilst showing the return message)
header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&'.api_get_cidreq());
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&'.api_get_cidreq());
exit;
} else {
// Displaying the header

@ -653,6 +653,8 @@ class SurveyManager
api_get_user_id()
);
Skill::deleteSkillsFromItem($survey_id, ITEM_TYPE_SURVEY);
return true;
}

@ -0,0 +1,38 @@
<h3>{{ user.complete_name_with_username }}</h3>
<br />
<table class="table table-striped">
<tr>
<th>{{ 'Skill' | get_lang }}</th>
<th>{{ 'Occurrences' | get_lang }}</th>
<th>{{ 'Conclusion' | get_lang }}</th>
</tr>
{% for skill in skills %}
<tr>
<td>{{ skill.name }}</td>
<td>
{% for item in items[skill.id] %}
{% set status = 'danger' %}
{% if item.info.status %}
{% set status = 'success' %}
{% endif %}
<span class="label label-{{ status }}">
{{ item.info.name }}
</span> &nbsp;
{% endfor %}
</td>
<td>
{% if conclusion_list[skill.id] %}
<span class="label label-success">
{{ 'Achieved' }}
</span>
{% else %}
<span class="label label-danger">
{{ 'NotYetAchieved' }}
</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>

@ -119,7 +119,7 @@ if ($form->validate()) {
updateWork($workData['iid'], $params, $courseInfo, $sessionId);
updatePublicationAssignment($workId, $params, $courseInfo, $groupId);
updateDirName($workData, $params['new_dir']);
Skill::saveSkills($form, ITEM_TYPE_STUDENT_PUBLICATION, $workData['iid']);
Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
header('Location: '.$currentUrl);
exit;

@ -162,12 +162,10 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
$commentForm = getWorkCommentForm($work, $my_folder_data);
$tpl = new Template();
$tpl->assign('work', $work);
$tpl->assign('comments', $comments);
$actions = '';
if (isset($work['contains_file']) && !empty($work['contains_file'])) {
if (isset($work['download_url']) && !empty($work['download_url'])) {
$actions = Display::url(

@ -885,6 +885,8 @@ function deleteDirWork($id)
WHERE c_id = $course_id AND publication_id = $id";
Database::query($sql);
Skill::deleteSkillsFromItem($id, ITEM_TYPE_STUDENT_PUBLICATION);
Event::addEvent(
LOG_WORK_DIR_DELETE,
LOG_WORK_DATA,
@ -3595,6 +3597,7 @@ function getWorkCommentForm($work, $workParent)
}
}
Skill::addSkillsToUserForm($form, ITEM_TYPE_STUDENT_PUBLICATION, $workParent['id'], $work['user_id']);
$form->addHtmlEditor('comment', get_lang('Comment'), false);
$form->addFile('attachment', get_lang('Attachment'));
$form->addElement('hidden', 'id', $work['id']);
@ -4800,7 +4803,12 @@ function getFormWork($form, $defaults = [], $workId = 0)
</script>';
$form->addHtml('</div>');
$skillList = Skill::addSkillsToForm($form, ITEM_TYPE_STUDENT_PUBLICATION, $workId);
if (!empty($defaults)) {
$defaults['skills'] = array_keys($skillList);
$form->setDefaults($defaults);
}

@ -197,6 +197,8 @@ switch ($action) {
);
if ($result) {
Skill::saveSkills($form, ITEM_TYPE_STUDENT_PUBLICATION, $result);
$message = Display::return_message(get_lang('DirectoryCreated'), 'success');
} else {
$currentUrl = $addUrl;

@ -5,7 +5,9 @@ namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\SkillBundle\Entity\Profile;
use Chamilo\SkillBundle\Entity\SkillRelItem;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
/**
@ -95,6 +97,12 @@ class Skill
*/
protected $issuedSkills;
/**
* // uncomment if api_get_configuration_value('allow_skill_rel_items')
* ORM\OneToMany(targetEntity="Chamilo\SkillBundle\Entity\SkillRelItem", mappedBy="skill", cascade={"persist"})
*/
protected $items;
/**
* @return string
*/
@ -358,4 +366,53 @@ class Skill
{
return $this->issuedSkills;
}
/**
* @return ArrayCollection
*/
public function getItems()
{
return $this->items;
}
/**
* @param ArrayCollection $items
* @return Skill
*/
public function setItems($items)
{
$this->items = $items;
return $this;
}
/**
* @param int $itemId
* @return bool
*/
public function hasItem($typeId, $itemId)
{
if ($this->getItems()->count()) {
$found = false;
/** @var SkillRelItem $item */
foreach ($this->getItems() as $item) {
if ($item->getItemId() == $itemId && $item->getItemType() == $typeId) {
$found = true;
break;
}
}
return $found;
}
return false;
}
/**
* @param SkillRelItem $skillRelItem
*/
public function addItem(SkillRelItem $skillRelItem)
{
$skillRelItem->setSkill($this);
$this->items[] = $skillRelItem;
}
}

@ -38,6 +38,7 @@ class SkillRelUser
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="issuedSkills", cascade={"persist"})
* @ORM\JoinColumn(name="skill_id", referencedColumnName="id", nullable=false)
@ -99,6 +100,16 @@ class SkillRelUser
*/
protected $comments;
/**
* Whether this has been confirmed by a teacher or not
* Only set to 0 when the skill_rel_item says requires_validation = 1
* @var integer
*
* // uncomment if api_get_configuration_value('allow_skill_rel_items')
* ORM\Column(name="validation_status", type="integer")
*/
protected $validationStatus;
/**
* SkillRelUser constructor.
*/
@ -409,4 +420,22 @@ class SkillRelUser
return number_format($average, 2);
}
/**
* @return int
*/
public function getValidationStatus()
{
return $this->validationStatus;
}
/**
* @param int $validationStatus
* @return SkillRelUser
*/
public function setValidationStatus($validationStatus)
{
$this->validationStatus = $validationStatus;
return $this;
}
}

@ -0,0 +1,363 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\SkillBundle\Entity;
use Chamilo\CoreBundle\Entity\Skill;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* SkillRelItem
*
* @ORM\Table(name="skill_rel_item")
* ORM\Entity // uncomment if api_get_configuration_value('allow_skill_rel_items')
*/
class SkillRelItem
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="items")
* @ORM\JoinColumn(name="skill_id", referencedColumnName="id")
**/
protected $skill;
/**
* See ITEM_TYPE_* constants in api.lib.php
* @var integer
*
* @ORM\Column(name="item_type", type="integer", nullable=false)
*/
protected $itemType;
/**
* iid value
* @var integer
*
* @ORM\Column(name="item_id", type="integer", nullable=false)
*/
protected $itemId;
/**
* A text expressing what has to be achieved
* (view, finish, get more than X score, finishing all children skills, etc),
* @var string
*
* @ORM\Column(name="obtain_conditions", type="string", length=255, nullable=true)
*/
protected $obtainConditions;
/**
* if it requires validation by a teacher
* @var bool
*
* @ORM\Column(name="requires_validation", type="boolean")
*/
protected $requiresValidation;
/**
* Set to false if this is a children skill used only to obtain a higher-level skill,
* so a skill with is_real = false never appears in a student portfolio/backpack
* @var bool
*
* @ORM\Column(name="is_real", type="boolean")
*/
protected $isReal;
/**
* @var integer
*
* @ORM\Column(name="c_id", type="integer", nullable=true)
*/
protected $courseId;
/**
* @var integer
*
* @ORM\Column(name="session_id", type="integer", nullable=true)
*/
protected $sessionId;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $updatedAt;
/**
* @var integer
*
* @ORM\Column(name="created_by", type="integer", nullable=false)
*/
protected $createdBy;
/**
* @var integer
*
* @ORM\Column(name="updated_by", type="integer", nullable=false)
*/
protected $updatedBy;
/**
* SkillRelItem constructor.
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->updatedAt = new \DateTime('now');
$this->isReal = false;
$this->requiresValidation = false;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
* @return SkillRelItem
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return Skill
*/
public function getSkill()
{
return $this->skill;
}
/**
* @param mixed $skill
* @return SkillRelItem
*/
public function setSkill($skill)
{
$this->skill = $skill;
return $this;
}
/**
* @return int
*/
public function getItemId()
{
return $this->itemId;
}
/**
* @param int $itemId
* @return SkillRelItem
*/
public function setItemId($itemId)
{
$this->itemId = $itemId;
return $this;
}
/**
* @return string
*/
public function getObtainConditions()
{
return $this->obtainConditions;
}
/**
* @param string $obtainConditions
* @return SkillRelItem
*/
public function setObtainConditions($obtainConditions)
{
$this->obtainConditions = $obtainConditions;
return $this;
}
/**
* @return bool
*/
public function isRequiresValidation()
{
return $this->requiresValidation;
}
/**
* @param bool $requiresValidation
* @return SkillRelItem
*/
public function setRequiresValidation($requiresValidation)
{
$this->requiresValidation = $requiresValidation;
return $this;
}
/**
* @return bool
*/
public function isReal()
{
return $this->isReal;
}
/**
* @param bool $isReal
* @return SkillRelItem
*/
public function setIsReal($isReal)
{
$this->isReal = $isReal;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
* @return SkillRelItem
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
* @return SkillRelItem
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return int
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* @param int $createdBy
* @return SkillRelItem
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return int
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* @param int $updatedBy
* @return SkillRelItem
*/
public function setUpdatedBy($updatedBy)
{
$this->updatedBy = $updatedBy;
return $this;
}
/**
* @return int
*/
public function getItemType()
{
return $this->itemType;
}
/**
* @param int $itemType
* @return SkillRelItem
*/
public function setItemType($itemType)
{
$this->itemType = $itemType;
return $this;
}
/**
* @return int
*/
public function getCourseId()
{
return $this->courseId;
}
/**
* @param int $courseId
* @return SkillRelItem
*/
public function setCourseId($courseId)
{
$this->courseId = $courseId;
return $this;
}
/**
* @return int
*/
public function getSessionId()
{
return $this->sessionId;
}
/**
* @param int $sessionId
* @return SkillRelItem
*/
public function setSessionId($sessionId)
{
$this->sessionId = $sessionId;
return $this;
}
}

@ -0,0 +1,169 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\SkillBundle\Entity;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* SkillRelItemRelUser
*
* @ORM\Table(name="skill_rel_item_rel_user")
* ORM\Entity // uncomment if api_get_configuration_value('allow_skill_rel_items')
*/
class SkillRelItemRelUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @var SkillRelItem
* @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\SkillRelItem", cascade={"persist"})
* @ORM\JoinColumn(name="skill_rel_item_id", referencedColumnName="id", nullable=false)
*/
protected $skillRelItem;
/**
* @var User
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
protected $user;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $updatedAt;
/**
* @var integer
*
* @ORM\Column(name="created_by", type="integer", nullable=false)
*/
protected $createdBy;
/**
* @var integer
*
* @ORM\Column(name="updated_by", type="integer", nullable=false)
*/
protected $updatedBy;
/**
* SkillRelItemRelUser constructor.
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->updatedAt = new \DateTime('now');
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
* @return SkillRelItemRelUser
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return SkillRelItem
*/
public function getSkillRelItem()
{
return $this->skillRelItem;
}
/**
* @param SkillRelItem $skillRelItem
* @return SkillRelItemRelUser
*/
public function setSkillRelItem($skillRelItem)
{
$this->skillRelItem = $skillRelItem;
return $this;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User $user
* @return SkillRelItemRelUser
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* @return int
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* @param int $createdBy
* @return SkillRelItemRelUser
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return int
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* @param int $updatedBy
* @return SkillRelItemRelUser
*/
public function setUpdatedBy($updatedBy)
{
$this->updatedBy = $updatedBy;
return $this;
}
}
Loading…
Cancel
Save