Admin: Add 'allow_session_lp_category' setting BT#17196

pull/3250/head
Julio Montoya 5 years ago
parent fce3055ac9
commit b887b38473
  1. 4
      main/install/configuration.dist.php
  2. 26
      main/lp/learnpath.class.php
  3. 26
      main/lp/lp_list.php
  4. 43
      main/lp/lp_subscribe_users_to_category.php
  5. 87
      main/template/default/learnpath/list.tpl
  6. 30
      src/Chamilo/CourseBundle/Entity/CLpCategory.php

@ -1511,6 +1511,10 @@ $_configuration['auth_password_links'] = [
// Show unsubscribe buttons on page "My courses"
//$_configuration['enable_unsubscribe_button_on_my_course_page'] = false;
// Allow LP category in sessions.
// ALTER TABLE c_lp_category ADD COLUMN session_id INT(11) DEFAULT NULL;
//$_configuration['allow_session_lp_category'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -12019,10 +12019,19 @@ EOD;
$em->persist($item);
$em->flush();
$id = $item->getId();
$sessionId = api_get_session_id();
if (!empty($sessionId) && api_get_configuration_value('allow_session_lp_category')) {
$table = Database::get_course_table(TABLE_LP_CATEGORY);
$sql = "UPDATE $table SET session_id = $sessionId WHERE iid = $id";
Database::query($sql);
}
api_item_property_update(
api_get_course_info(),
TOOL_LEARNPATH_CATEGORY,
$item->getId(),
$id,
'visible',
api_get_user_id()
);
@ -12133,11 +12142,8 @@ EOD;
// Using doctrine extensions
/** @var SortableRepository $repo */
$repo = $em->getRepository('ChamiloCourseBundle:CLpCategory');
$items = $repo
->getBySortableGroupsQuery(['cId' => $courseId])
->getResult();
return $items;
return $repo->getBySortableGroupsQuery(['cId' => $courseId])->getResult();
}
/**
@ -12153,9 +12159,8 @@ EOD;
{
$id = (int) $id;
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
return $item;
return $em->find('ChamiloCourseBundle:CLpCategory', $id);
}
/**
@ -12166,11 +12171,8 @@ EOD;
public static function getCategoryByCourse($courseId)
{
$em = Database::getManager();
$items = $em->getRepository('ChamiloCourseBundle:CLpCategory')->findBy(
['cId' => $courseId]
);
return $items;
return $em->getRepository('ChamiloCourseBundle:CLpCategory')->findBy(['cId' => $courseId]);
}
/**
@ -12185,7 +12187,7 @@ EOD;
public static function deleteCategory($id)
{
$em = Database::getManager();
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
$item = self::getCategory($id);
if ($item) {
$courseId = $item->getCId();
$query = $em->createQuery('SELECT u FROM ChamiloCourseBundle:CLp u WHERE u.cId = :id AND u.categoryId = :catId');

@ -102,7 +102,15 @@ if ($is_allowed_to_edit) {
);
}
if (!$sessionId) {
$allowCategory = true;
if (!empty($sessionId)) {
$allowCategory = false;
if (api_get_configuration_value('allow_session_lp_category')) {
$allowCategory = true;
}
}
if ($allowCategory) {
$actionLeft .= Display::url(
Display::return_icon(
'new_folder.png',
@ -117,7 +125,6 @@ if ($is_allowed_to_edit) {
}
$token = Security::get_token();
$categoriesTempList = learnpath::getCategories($courseId);
$categoryTest = new CLpCategory();
$categoryTest->setId(0);
@ -190,9 +197,19 @@ $enableAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
$gameMode = api_get_setting('gamification_mode');
$data = [];
$tableCategory = Database::get_course_table(TABLE_LP_CATEGORY);
/** @var CLpCategory $item */
foreach ($categories as $item) {
$categoryId = $item->getId();
if (!empty($sessionId) && api_get_configuration_value('allow_session_lp_category')) {
$sql = "SELECT session_id FROM $tableCategory WHERE iid = $categoryId";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
if ($row) {
$item->setSessionId((int) $row['session_id']);
}
}
if ($categoryId !== 0 && $subscriptionSettings['allow_add_users_to_lp_category'] == true) {
// "Without category" has id = 0
$categoryVisibility = api_get_item_visibility(
@ -544,7 +561,7 @@ foreach ($categories as $item) {
/* PUBLISH COMMAND */
if ($sessionId == $details['lp_session']) {
if ($details['lp_published'] == 'i') {
if ($details['lp_published'] === 'i') {
$dsp_publish = Display::url(
Display::return_icon(
'lp_publish_na.png',
@ -912,7 +929,7 @@ foreach ($categories as $item) {
$lpIsShown = true;
// Counter for number of elements treated
$current++;
} // end foreach ($flat_list)
}
}
$data[] = [
@ -973,6 +990,7 @@ if ($ending && $allLpTimeValid && api_get_configuration_value('download_files_af
}
$template = new Template($nameTools);
$template->assign('session_star_icon', Display::return_icon('star.png', get_lang('Session')));
$template->assign('subscription_settings', $subscriptionSettings);
$template->assign('is_allowed_to_edit', $is_allowed_to_edit);
$template->assign('is_invitee', $isInvitee);

@ -17,7 +17,7 @@ if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
$categoryId = isset($_GET['id']) ? intval($_GET['id']) : 0;
$categoryId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (empty($categoryId)) {
api_not_allowed(true);
@ -30,6 +30,7 @@ if ($subscriptionSettings['allow_add_users_to_lp_category'] == false) {
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
$em = Database::getManager();
@ -58,23 +59,19 @@ $form->addLabel('', $message);
// Group list
$groupList = \CourseManager::get_group_list_of_course(
api_get_course_id(),
api_get_session_id(),
$sessionId,
1
);
$groupChoices = array_column($groupList, 'name', 'id');
/** @var Session $session */
$session = null;
if (!empty($sessionId)) {
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
}
$session = api_get_session_entity($sessionId);
/** @var CourseRepository $courseRepo */
$courseRepo = $em->getRepository('ChamiloCoreBundle:Course');
/** @var ItemPropertyRepository $itemRepo */
$itemRepo = $em->getRepository('ChamiloCourseBundle:CItemProperty');
$course = $courseRepo->find($courseId);
$course = api_get_course_entity($courseId);
// Subscribed groups to a LP
$subscribedGroupsInLp = $itemRepo->getGroupsSubscribedToItem(
@ -107,19 +104,27 @@ if (!empty($selectedGroupChoices)) {
$form->setDefaults($defaults);
// Getting subscribe users to the course.
$subscribedUsers = $courseRepo->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();
// Getting all users in a nice format.
$choices = [];
/** @var User $user */
foreach ($subscribedUsers as $user) {
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses();
if (empty($sessionId)) {
$subscribedUsers = $courseRepo->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();
// Getting all users in a nice format.
/** @var User $user */
foreach ($subscribedUsers as $user) {
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses();
}
} else {
$users = CourseManager::get_user_list_from_course_code( $course->getCode(), $sessionId);
foreach ($users as $user) {
$choices[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
}
}
// Getting subscribed users to a category.
$subscribedUsersInCategory = $category->getUsers();
$selectedChoices = [];
foreach ($subscribedUsersInCategory as $item) {
$selectedChoices[] = $item->getUser()->getId();
@ -172,8 +177,10 @@ if ($formUsers->validate()) {
foreach ($users as $userId) {
$categoryUser = new CLpCategoryUser();
$user = UserManager::getRepository()->find($userId);
$categoryUser->setUser($user);
$category->addUser($categoryUser);
if ($user) {
$categoryUser->setUser($user);
$category->addUser($categoryUser);
}
}
$em->merge($category);

@ -24,8 +24,12 @@
<h3 class="page-header">
{{ lp_data.category.getName() | trim }}
{% if lp_data.category.sessionId %}
{{ session_star_icon }}
{% endif %}
{% if lp_data.category.getId() > 0 %}
{% if not _c.session_id %}
{% if lp_data.category.sessionId == _c.session_id %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_lp_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Edit"|get_lang }}">
<img src="{{ "edit.png"|icon }}" alt="{{ "Edit"|get_lang }}">
@ -38,54 +42,61 @@
</a>
{% endif %}
{% if loop.index0 == 1 %}
<a href="#">
<img src="{{ "up_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
{% if not _c.session_id %}
{% if loop.index0 == 1 %}
<a href="#">
<img src="{{ "up_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
</a>
{% else %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_up_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Move"|get_lang }}">
<img src="{{ "up.png"|icon }}" alt="{{ "Move"|get_lang }}">
</a>
{% endif %}
{% if (data|length - 1) == loop.index0 %}
<a href="#">
<img src="{{ "down_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
</a>
{% else %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_down_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Move"|get_lang }}">
<img src="{{ "down.png"|icon }}" alt="{{ "Move"|get_lang }}">
</a>
{% endif %}
{% endif %}
{% endif %}
{% if lp_data.category.sessionId == _c.session_id %}
{% if lp_data.category_visibility == 0 %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':1}|url_encode }}"
title="{{ 'Show'|get_lang }}">
<img src="{{ 'invisible.png'|icon }}" alt="{{ 'Show'|get_lang }}">
</a>
{% else %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_up_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Move"|get_lang }}">
<img src="{{ "up.png"|icon }}" alt="{{ "Move"|get_lang }}">
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':0}|url_encode }}"
title="{{ 'Hide'|get_lang }}">
<img src="{{ 'visible.png'|icon }}" alt="{{ 'Hide'|get_lang }}">
</a>
{% endif %}
{% endif %}
{% if (data|length - 1) == loop.index0 %}
<a href="#">
<img src="{{ "down_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
{% if not _c.session_id %}
{% if lp_data.category_is_published == 0 %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_publish', 'id':lp_data.category.id, 'new_status':1}|url_encode }}"
title="{{ 'LearnpathPublish'|get_lang }}">
<img src="{{ 'lp_publish_na.png'|icon }}"
alt="{{ 'LearnpathPublish'|get_lang }}">
</a>
{% else %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=move_down_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Move"|get_lang }}">
<img src="{{ "down.png"|icon }}" alt="{{ "Move"|get_lang }}">
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_publish', 'id':lp_data.category.id, 'new_status':0}|url_encode }}"
title="{{ 'LearnpathDoNotPublish'|get_lang }}">
<img src="{{ 'lp_publish.png'|icon }}" alt="{{ 'Hide'|get_lang }}">
</a>
{% endif %}
{% endif %}
{% if lp_data.category_visibility == 0 %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':1}|url_encode }}"
title="{{ 'Show'|get_lang }}">
<img src="{{ 'invisible.png'|icon }}" alt="{{ 'Show'|get_lang }}">
</a>
{% else %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_visibility', 'id':lp_data.category.id, 'new_status':0}|url_encode }}"
title="{{ 'Hide'|get_lang }}">
<img src="{{ 'visible.png'|icon }}" alt="{{ 'Hide'|get_lang }}">
</a>
{% endif %}
{% if lp_data.category_is_published == 0 %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_publish', 'id':lp_data.category.id, 'new_status':1}|url_encode }}"
title="{{ 'LearnpathPublish'|get_lang }}">
<img src="{{ 'lp_publish_na.png'|icon }}"
alt="{{ 'LearnpathPublish'|get_lang }}">
</a>
{% else %}
<a href="lp_controller.php?{{ _p.web_cid_query ~ '&' ~ {'action':'toggle_category_publish', 'id':lp_data.category.id, 'new_status':0}|url_encode }}"
title="{{ 'LearnpathDoNotPublish'|get_lang }}">
<img src="{{ 'lp_publish.png'|icon }}" alt="{{ 'Hide'|get_lang }}">
</a>
{% endif %}
{% if not _c.session_id %}
{% if lp_data.category.sessionId == _c.session_id %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=delete_lp_category&id=' ~ lp_data.category.getId() }}"
title="{{ "Delete"|get_lang }}">
<img src="{{ "delete.png"|icon }}" alt="{{ "Delete"|get_lang }}">

@ -51,16 +51,24 @@ class CLpCategory
protected $position;
/**
* @var CLpCategoryUser[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CLpCategoryUser", mappedBy="category", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $users;
/**
* @var int
*/
protected $sessionId;
/**
* CLpCategory constructor.
*/
public function __construct()
{
$this->users = new ArrayCollection();
$this->sessionId = 0;
}
/**
@ -154,7 +162,27 @@ class CLpCategory
}
/**
* @return ArrayCollection
* @return int
*/
public function getSessionId()
{
return $this->sessionId;
}
/**
* @param int $sessionId
*
* @return CLpCategory
*/
public function setSessionId($sessionId)
{
$this->sessionId = $sessionId;
return $this;
}
/**
* @return ArrayCollection|CLpCategoryUser[]
*/
public function getUsers()
{

Loading…
Cancel
Save