Allow publish learnpath categories as course tool - refs BT#12756

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent f41666006f
commit 37de579dff
  1. 38
      main/inc/lib/course_home.lib.php
  2. 176
      main/lp/learnpath.class.php
  3. 12
      main/lp/lp_controller.php
  4. 28
      main/lp/lp_list.php
  5. 238
      main/template/default/learnpath/list.tpl
  6. 3
      src/Chamilo/CourseBundle/Entity/CTool.php

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\CourseBundle\Entity\CLpCategory;
/**
* Class CourseHome
@ -461,6 +462,8 @@ class CourseHome
// Condition for the session
$session_id = $sessionId ?: api_get_session_id();
$course_id = $courseId ?: api_get_course_int_id();
$userId = api_get_user_id();
$user = api_get_user_entity($userId);
$condition_session = api_get_session_condition(
$session_id,
true,
@ -572,12 +575,12 @@ class CourseHome
$lp = new learnpath(
api_get_course_id(),
$lp_id,
api_get_user_id()
$userId
);
$path = $lp->get_preview_image_path(ICON_SIZE_BIG);
$add = learnpath::is_lp_visible_for_student(
$lp_id,
api_get_user_id(),
$userId,
api_get_course_id(),
api_get_session_id()
);
@ -586,6 +589,16 @@ class CourseHome
}
}
if ($temp_row['image'] === 'lp_category.gif') {
$lpCategory = self::getPublishedLpCategoryFromLink(
$temp_row['link']
);
$add = learnpath::categoryIsVisibleForStudent(
$lpCategory,
$user
);
}
if ($add) {
$all_tools_list[] = $temp_row;
}
@ -675,7 +688,7 @@ class CourseHome
WHERE blog_id =".$blog_id;
} else {
$sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
WHERE blog_id =".$blog_id." AND user_id = ".api_get_user_id();
WHERE blog_id =".$blog_id." AND user_id = ".$userId;
}
$result_blogs = Database::query($sql_blogs);
@ -1173,6 +1186,25 @@ class CourseHome
return $lp_id;
}
/**
* Get published learning path category from link inside course home
* @param string $link
* @return CLpCategory
*/
public static function getPublishedLpCategoryFromLink($link)
{
$query = parse_url($link, PHP_URL_QUERY);
parse_str($query, $params);
$id = isset($params['id']) ? (int) $params['id'] : 0;
$em = Database::getManager();
/** @var CLpCategory $category */
$category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
return $category;
}
/**
* @param bool $include_admin_tools
* @return array

@ -9,6 +9,8 @@ use Gedmo\Sortable\Entity\Repository\SortableRepository;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\UserBundle\Entity\User;
/**
* Class learnpath
@ -4145,6 +4147,8 @@ class learnpath
foreach ($learPaths as $lp) {
learnpath::toggle_visibility($lp['iid'], 0);
}
learnpath::toggleCategoryPublish($id, 0);
}
return api_item_property_update(
@ -4247,6 +4251,178 @@ class learnpath
}
}
/**
* Generate the link for a learnpath category as course tool
* @param int $categoryId
* @return string
*/
private static function getCategoryLinkForTool($categoryId)
{
$link = 'lp/lp_controller.php?'.api_get_cidreq().'&'
.http_build_query(
[
'action' => 'view_category',
'id' => $categoryId
]
);
return $link;
}
/**
* Publishes a learnpath.
* Show or hide the learnpath category on the course homepage
* @param int $id
* @param int $setVisibility
* @return bool
*/
public static function toggleCategoryPublish($id, $setVisibility = 1)
{
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$sessionCondition = api_get_session_condition($sessionId, true, false, 't.sessionId');
$em = Database::getManager();
/** @var CLpCategory $category */
$category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
if (!$category) {
return false;
}
$link = self::getCategoryLinkForTool($id);
/** @var CTool $tool */
$tool = $em
->createQuery("
SELECT t FROM ChamiloCourseBundle:CTool t
WHERE
t.cId = :course AND
t.link = :link1 AND
t.image = 'lp_category.gif' AND
t.link LIKE :link2
$sessionCondition
")
->setParameters([
'course' => (int) $courseId,
'link1' => $link,
'link2' => "$link%"
])
->getOneOrNullResult();
if ($setVisibility == 0 && $tool) {
$em->remove($tool);
$em->flush();
return true;
}
if ($setVisibility == 1 && !$tool) {
$tool = new CTool();
$tool
->setCategory('authoring')
->setCId($courseId)
->setName($category->getName())
->setLink($link)
->setImage('lp_category.gif')
->setVisibility(1)
->setAdmin(0)
->setAddress('pastillegris.gif')
->setAddedTool(0)
->setSessionId($sessionId)
->setTarget('_self');
$em->persist($tool);
$em->flush();
$tool->setId($tool->getIid());
$em->persist($tool);
$em->flush();
return true;
}
if ($setVisibility == 1 && $tool) {
$tool
->setName($category->getName())
->setVisibility(1);
$em->persist($tool);
$em->flush();
return true;
}
return false;
}
/**
* Check if the learnpath category is visible for a user
* @param CLpCategory $category
* @param User $user
* @return bool
*/
public static function categoryIsVisibleForStudent(
CLpCategory $category,
User $user
)
{
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
if ($isAllowedToEdit) {
return true;
}
$users = $category->getUsers();
if (empty($users) || !$users->count()) {
return true;
}
if ($category->hasUserAdded($user)) {
return true;
}
return false;
}
/**
* Check if a learnpath category is published as course tool
* @param CLpCategory $category
* @param int $courseId
* @return bool
*/
public static function categoryIsPusblished(
CLpCategory $category,
$courseId
)
{
$link = self::getCategoryLinkForTool($category->getId());
$em = Database::getManager();
$tools = $em
->createQuery("
SELECT t FROM ChamiloCourseBundle:CTool t
WHERE t.cId = :course AND
t.name = :name AND
t.image = 'lp_category.gif' AND
t.link LIKE :link
")
->setParameters([
'course' => $courseId,
'name' => $category->getName(),
'link' => "$link%"
])
->getResult();
/** @var CTool $tool */
$tool = current($tools);
return $tool ? $tool->getVisibility() : false;
}
/**
* Restart the whole learnpath. Return the URL of the first element.
* Make sure the results are saved with anoter method. This method should probably be

@ -334,9 +334,11 @@ if (isset($_SESSION['oLP'])) {
}
if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
if (isset($_REQUEST['action']) && !in_array($_REQUEST['action'], ['list', 'view'])) {
if (isset($_REQUEST['action']) && !in_array($_REQUEST['action'], ['list', 'view', 'view_category'])) {
if (!empty($_REQUEST['lp_id'])) {
$_REQUEST['action'] = 'view';
} elseif($_REQUEST['action'] == 'view_category') {
$_REQUEST['action'] = 'view_category';
} else {
$_REQUEST['action'] = 'list';
}
@ -873,6 +875,14 @@ switch ($action) {
require 'lp_list.php';
}
break;
case 'toggle_category_publish':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
learnpath::toggleCategoryPublish($_REQUEST['id'], $_REQUEST['new_status']);
require 'lp_list.php';
break;
case 'toggle_publish':
// Change lp published status (visibility on homepage).
if (!$is_allowed_to_edit) {

@ -141,6 +141,20 @@ $userId = api_get_user_id();
$userInfo = api_get_user_info();
$lpIsShown = false;
$filteredCategoryId = $action === 'view_category' && !empty($_GET['id']);
if ($filteredCategoryId) {
/** @var CLpCategory $category */
foreach ($categories as $category) {
if ($category->getId() != $filteredCategoryId) {
continue;
}
$interbreadcrumb[] = ['name' => $nameTools, 'url' => api_get_self()];
$nameTools = $category->getName();
}
}
$test_mode = api_get_setting('server_type');
$user = UserManager::getRepository()->find($userId);
@ -149,13 +163,8 @@ $data = [];
foreach ($categories as $item) {
$categoryId = $item->getId();
if (!$is_allowed_to_edit) {
$users = $item->getUsers();
if (!empty($users) && $users->count() > 0) {
if (!$item->hasUserAdded($user)) {
continue;
}
}
if (!learnpath::categoryIsVisibleForStudent($item, $user)) {
continue;
}
$list = new LearnpathList(
@ -848,6 +857,10 @@ foreach ($categories as $item) {
$item->getId(),
$current_session
),
'category_is_published' => learnpath::categoryIsPusblished(
$item,
$courseInfo['real_id']
),
'lp_list' => $listData
];
}
@ -861,6 +874,7 @@ $template->assign('message', $message);
$template->assign('introduction_section', $introductionSection);
$template->assign('data', $data);
$template->assign('lp_is_shown', $lpIsShown);
$template->assign('filtered_category', $filteredCategoryId);
$templateName = $template->get_template('learnpath/list.tpl');
$content = $template->fetch($templateName);
$template->assign('content', $content);

@ -11,140 +11,160 @@
{{ introduction_section }}
{% for lp_data in data %}
{% if categories|length > 1 and lp_data.category.id %}
{% if is_allowed_to_edit %}
<h3 class="page-header">
{{ lp_data.category.getName() }}
{% set show_category = true %}
{% if lp_data.category.getId() > 0 %}
{% if not _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 }}">
</a>
{% if filtered_category and filtered_category != lp_data.category.id %}
{% set show_category = false %}
{% endif %}
<a href="{{ 'lp_controller.php?' ~ _p.web_cid_query ~ '&action=add_users_to_category&id=' ~ lp_data.category.getId() }}" title="{{ "AddUser"|get_lang }}">
<img src="{{ "user.png"|icon }}" alt="{{ "AddUser"|get_lang }}">
</a>
{% if show_category %}
{% if categories|length > 1 and lp_data.category.id %}
{% if is_allowed_to_edit %}
<h3 class="page-header">
{{ lp_data.category.getName() }}
{% if loop.index0 == 1 %}
<a href="#">
<img src="{{ "up_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
{% if lp_data.category.getId() > 0 %}
{% if not _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 }}">
</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=add_users_to_category&id=' ~ lp_data.category.getId() }}" title="{{ "AddUser"|get_lang }}">
<img src="{{ "user.png"|icon }}" alt="{{ "AddUser"|get_lang }}">
</a>
{% 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 %}
{% if (data|length - 1) == loop.index0 %}
<a href="#">
<img src="{{ "down_na.png"|icon }}" alt="{{ "Move"|get_lang }}">
{% 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_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_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 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 %}
<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 }}">
</a>
{% if not _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 }}">
</a>
{% endif %}
{% endif %}
{% endif %}
</h3>
{% elseif lp_data.lp_list is not empty %}
<h3 class="page-header">{{ lp_data.category.getName() }}</h3>
</h3>
{% elseif lp_data.lp_list is not empty %}
<h3 class="page-header">{{ lp_data.category.getName() }}</h3>
{% endif %}
{% endif %}
{% endif %}
{% if lp_data.lp_list %}
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ "Title"|get_lang }}</th>
{% if is_allowed_to_edit %}
<th>{{ "PublicationDate"|get_lang }}</th>
<th>{{ "ExpirationDate"|get_lang }}</th>
<th>{{ "Progress"|get_lang }}</th>
<th>{{ "AuthoringOptions"|get_lang }}</th>
{% else %}
{% if not is_invitee %}
<th>{{ "Progress"|get_lang }}</th>
{% endif %}
<th>{{ "Actions"|get_lang }}</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for row in lp_data.lp_list %}
{% if lp_data.lp_list %}
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<td>
{{ row.learnpath_icon }}
<a href="{{ row.url_start }}">
{{ row.title }}
{{ row.session_image }}
{{ row.extra }}
</a>
</td>
<th>{{ "Title"|get_lang }}</th>
{% if is_allowed_to_edit %}
<td>
{% if row.start_time %}
<span class="small">{{ row.start_time }}</span>
{% endif %}
</td>
<td>
<span class="small">{{ row.end_time }}</span>
</td>
<td>
{{ row.dsp_progress }}
</td>
<th>{{ "PublicationDate"|get_lang }}</th>
<th>{{ "ExpirationDate"|get_lang }}</th>
<th>{{ "Progress"|get_lang }}</th>
<th>{{ "AuthoringOptions"|get_lang }}</th>
{% else %}
{% if not is_invitee %}
<th>{{ "Progress"|get_lang }}</th>
{% endif %}
<th>{{ "Actions"|get_lang }}</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for row in lp_data.lp_list %}
<tr>
<td>
{{ row.learnpath_icon }}
<a href="{{ row.url_start }}">
{{ row.title }}
{{ row.session_image }}
{{ row.extra }}
</a>
</td>
{% if is_allowed_to_edit %}
<td>
{% if row.start_time %}
<span class="small">{{ row.start_time }}</span>
{% endif %}
</td>
<td>
<span class="small">{{ row.end_time }}</span>
</td>
<td>
{{ row.dsp_progress }}
</td>
{% else %}
{% if not is_invitee %}
<td>
{{ row.dsp_progress }}
</td>
{% endif %}
{% endif %}
{% endif %}
<td>
{{ row.action_build }}
{{ row.action_edit }}
{{ row.action_visible }}
{{ row.action_tracking }}
{{ row.action_publish }}
{{ row.action_subscribe_users }}
{{ row.action_serious_game }}
{{ row.action_reinit }}
{{ row.action_default_view }}
{{ row.action_debug }}
{{ row.action_export }}
{{ row.action_copy }}
{{ row.action_auto_launch }}
{{ row.action_pdf }}
{{ row.action_delete }}
{{ row.action_order }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<td>
{{ row.action_build }}
{{ row.action_edit }}
{{ row.action_visible }}
{{ row.action_tracking }}
{{ row.action_publish }}
{{ row.action_subscribe_users }}
{{ row.action_serious_game }}
{{ row.action_reinit }}
{{ row.action_default_view }}
{{ row.action_debug }}
{{ row.action_export }}
{{ row.action_copy }}
{{ row.action_auto_launch }}
{{ row.action_pdf }}
{{ row.action_delete }}
{{ row.action_order }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endif %}
{% endfor %}

@ -96,7 +96,8 @@ class CTool
*
* @ORM\Column(name="target", type="string", length=20, nullable=false)
*/
private $target;
private
$target;
/**
* @var string

Loading…
Cancel
Save