Add shortcut to LP

pull/3064/head
Julio 5 years ago
parent cd17519403
commit d160d0d8d7
  1. 17
      public/main/exercise/exercise.php
  2. 80
      public/main/lp/learnpath.class.php
  3. 83
      public/main/lp/learnpathList.class.php

@ -4,6 +4,7 @@
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CExerciseCategory;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CShortcut;
/**
* Exercise list: This script shows the list of exercises for administrators and students.
@ -90,23 +91,23 @@ if ($is_allowedToEdit && !empty($action)) {
switch ($action) {
case 'add_shortcut':
$repo = Container::getShortcutRepository();
$shortCut = new \Chamilo\CourseBundle\Entity\CShortcut();
$shortCut->setName($objExerciseTmp->get_formated_title());
$shortCut->setShortCutNode($exerciseEntity->getResourceNode());
$shortcut = new CShortcut();
$shortcut->setName($objExerciseTmp->get_formated_title());
$shortcut->setShortCutNode($exerciseEntity->getResourceNode());
$courseEntity = api_get_course_entity(api_get_course_int_id());
$repo->addResourceNode($shortCut, api_get_user_entity(api_get_user_id()), $courseEntity);
$repo->addResourceNode($shortcut, api_get_user_entity(api_get_user_id()), $courseEntity);
$repo->getEntityManager()->flush();
Display::addFlash(Display::return_message(get_lang('Updated')));
break;
case 'remove_shortcut':
$repo = Container::getShortcutRepository();
$shortCut = $repo->getShortcutFromResource($exerciseEntity);
$shortcut = $repo->getShortcutFromResource($exerciseEntity);
$courseEntity = api_get_course_entity(api_get_course_int_id());
if (null !== $shortCut) {
$repo->addResourceNode($shortCut, api_get_user_entity(api_get_user_id()), $courseEntity);
$repo->getEntityManager()->remove($shortCut);
if (null !== $shortcut) {
$repo->addResourceNode($shortcut, api_get_user_entity(api_get_user_id()), $courseEntity);
$repo->getEntityManager()->remove($shortcut);
$repo->getEntityManager()->flush();
}

@ -7,11 +7,13 @@ use Chamilo\CoreBundle\Repository\CourseRepository;
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CLpItem;
use Chamilo\CourseBundle\Entity\CLpItemView;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CShortcut;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
@ -1023,7 +1025,7 @@ class learnpath
WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
Database::query($sql);
self::toggle_publish($this->lp_id, 'i');
//self::toggle_publish($this->lp_id, 'i');
if ($this->type == 2 || $this->type == 3) {
// This is a scorm learning path, delete the files as well.
@ -4271,9 +4273,32 @@ class learnpath
*
* @return bool
*/
public static function toggle_publish($lp_id, $set_visibility = 'v')
public static function toggle_publish($id, $setVisibility = 'v')
{
return false;
$addShortcut = false;
if ($setVisibility == 'v') {
$addShortcut = true;
}
$repo = Container::getLpRepository();
/** @var CLp $lp */
$lp = $repo->find($id);
$repoShortcut = Container::getShortcutRepository();
if ($addShortcut) {
$shortcut = new CShortcut();
$shortcut->setName($lp->getName());
$shortcut->setShortCutNode($lp->getResourceNode());
$courseEntity = api_get_course_entity(api_get_course_int_id());
$repoShortcut->addResourceNode($shortcut, api_get_user_entity(api_get_user_id()), $courseEntity);
$repoShortcut->getEntityManager()->flush();
} else {
$shortcut = $repoShortcut->getShortcutFromResource($lp);
$repoShortcut->getEntityManager()->remove($shortcut);
$repoShortcut->getEntityManager()->flush();
}
return true;
/*
$course_id = api_get_course_int_id();
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = (int) $lp_id;
@ -4353,7 +4378,7 @@ class learnpath
}
} else {
return false;
}
}*/
}
/**
@ -9986,7 +10011,6 @@ class learnpath
$session_id = api_get_session_id();
$userInfo = api_get_user_info();
$tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
$tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
$condition_session = api_get_session_condition($session_id, true, true);
$setting = api_get_setting('lp.show_invisible_exercise_in_lp_toc') === 'true';
@ -10122,14 +10146,19 @@ class learnpath
*/
public function get_links()
{
$sessionId = api_get_session_id();
$repo = Container::getLinkRepository();
$course = api_get_course_entity();
$session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourse($course, $session);
/** @var CLink[] $links */
$links = $qb->getQuery()->getResult();
$selfUrl = api_get_self();
$courseIdReq = api_get_cidreq();
$course = api_get_course_info();
$userInfo = api_get_user_info();
$course_id = $course['real_id'];
$tbl_link = Database::get_course_table(TABLE_LINK);
$linkCategoryTable = Database::get_course_table(TABLE_LINK_CATEGORY);
$moveEverywhereIcon = Display::return_icon(
'move_everywhere.png',
get_lang('Move'),
@ -10137,8 +10166,7 @@ class learnpath
ICON_SIZE_TINY
);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition(
/*$condition_session = api_get_session_condition(
$session_id,
true,
true,
@ -10156,16 +10184,20 @@ class learnpath
ON (link.category_id = link_category.id AND link.c_id = link_category.c_id)
WHERE link.c_id = $course_id $condition_session
ORDER BY link_category.category_title ASC, link.title ASC";
$result = Database::query($sql);
$result = Database::query($sql);*/
$categorizedLinks = [];
$categories = [];
while ($link = Database::fetch_array($result)) {
if (!$link['category_id']) {
$link['category_title'] = get_lang('Uncategorized');
foreach ($links as $link) {
$categoryId = $link->getCategory() !== null ? $link->getCategory()->getIid() : 0;
if (empty($categoryId)) {
$categories[0] = get_lang('Uncategorized');
} else {
$category = $link->getCategory();
$categories[$categoryId] = $category->getCategoryTitle();
}
$categories[$link['category_id']] = $link['category_title'];
$categorizedLinks[$link['category_id']][$link['link_id']] = $link;
$categorizedLinks[$categoryId][$link->getIid()] = $link;
}
$linksHtmlCode =
@ -10191,17 +10223,18 @@ class learnpath
foreach ($categorizedLinks as $categoryId => $links) {
$linkNodes = null;
foreach ($links as $key => $linkInfo) {
$title = $linkInfo['link_title'];
$linkSessionId = $linkInfo['link_session_id'];
/** @var CLink $link */
foreach ($links as $key => $link) {
$title = $link->getTitle();
$linkSessionId = $link->getSessionId();
$link = Display::url(
$linkUrl = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
api_get_path(WEB_CODE_PATH).'link/link_goto.php?'.api_get_cidreq().'&link_id='.$key,
['target' => '_blank']
);
if (api_get_item_visibility($course, TOOL_LINK, $key, $session_id) != 2) {
if ($link->isVisible($course, $session)) {
$sessionStar = api_get_session_image($linkSessionId, $userInfo['status']);
$linkNodes .=
'<li class="lp_resource_element" data_id="'.$key.'" data_type="'.TOOL_LINK.'" title="'.$title.'" >
@ -10211,7 +10244,7 @@ class learnpath
'.Display::return_icon('links.png', '', [], ICON_SIZE_TINY).'
<a class="moved" href="'.$selfUrl.'?'.$courseIdReq.'&action=add_item&type='.
TOOL_LINK.'&file='.$key.'&lp_id='.$this->lp_id.'">'.
Security::remove_XSS($title).$sessionStar.$link.
Security::remove_XSS($title).$sessionStar.$linkUrl.
'</a>
</li>';
}
@ -12436,7 +12469,6 @@ EOD;
$course = api_get_course_entity();
$session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourse($course, $session);
return $qb->getQuery()->getResult();

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
@ -107,11 +108,13 @@ class LearnpathList
$isAllowToEdit = api_is_allowed_to_edit();
$courseEntity = api_get_course_entity($course_id);
$sessionEntity = api_get_session_entity($session_id);
/** @var CLp $row */
foreach ($learningPaths as $row) {
//$name = Database::escape_string($row->getName());
//$link = 'lp/lp_controller.php?action=view&lp_id='.$row->getId().'&id_session='.$session_id;
//$oldLink = 'newscorm/lp_controller.php?action=view&lp_id='.$row->getId().'&id_session='.$session_id;
$shortcutRepository = Container::getShortcutRepository();
/** @var CLp $lp */
foreach ($learningPaths as $lp) {
//$name = Database::escape_string($lp->getName());
//$link = 'lp/lp_controller.php?action=view&lp_id='.$lp->getId().'&id_session='.$session_id;
//$oldLink = 'newscorm/lp_controller.php?action=view&lp_id='.$lp->getId().'&id_session='.$session_id;
/*$sql2 = "SELECT visibility FROM $tbl_tool
WHERE
@ -125,25 +128,29 @@ class LearnpathList
";
$res2 = Database::query($sql2);*/
$pub = 'i';
$shortcut = $shortcutRepository->getShortcutFromResource($lp);
if ($shortcut) {
$pub = 'v';
}
/*if (Database::num_rows($res2) > 0) {
$row2 = Database::fetch_array($res2);
$pub = $row2['visibility'];
$lp2 = Database::fetch_array($res2);
$pub = $lp2['visibility'];
}*/
// Check if visible.
/*$visibility = api_get_item_visibility(
$courseInfo,
'learnpath',
$row->getId(),
$lp->getId(),
$session_id
);*/
$visibility = $row->isVisible($courseEntity, $sessionEntity);
$visibility = $lp->isVisible($courseEntity, $sessionEntity);
// If option is not true then don't show invisible LP to user
if ($ignoreLpVisibility === false) {
if ($showBlockedPrerequisite !== true && !$isAllowToEdit) {
$lpVisibility = learnpath::is_lp_visible_for_student(
$row,
$lp,
$user_id,
$courseInfo
);
@ -153,38 +160,38 @@ class LearnpathList
}
}
$this->list[$row->getIid()] = [
'lp_type' => $row->getLpType(),
'lp_session' => $row->getSessionId(),
'lp_name' => stripslashes($row->getName()),
'lp_desc' => stripslashes($row->getDescription()),
'lp_path' => $row->getPath(),
'lp_view_mode' => $row->getDefaultViewMod(),
'lp_force_commit' => $row->getForceCommit(),
'lp_maker' => stripslashes($row->getContentMaker()),
'lp_proximity' => $row->getContentLocal(),
$this->list[$lp->getIid()] = [
'lp_type' => $lp->getLpType(),
'lp_session' => $lp->getSessionId(),
'lp_name' => stripslashes($lp->getName()),
'lp_desc' => stripslashes($lp->getDescription()),
'lp_path' => $lp->getPath(),
'lp_view_mode' => $lp->getDefaultViewMod(),
'lp_force_commit' => $lp->getForceCommit(),
'lp_maker' => stripslashes($lp->getContentMaker()),
'lp_proximity' => $lp->getContentLocal(),
'lp_encoding' => api_get_system_encoding(),
'lp_visibility' => $visibility,
'lp_published' => $pub,
'lp_prevent_reinit' => $row->getPreventReinit(),
'seriousgame_mode' => $row->getSeriousgameMode(),
'lp_scorm_debug' => $row->getDebug(),
'lp_display_order' => $row->getDisplayOrder(),
'lp_preview_image' => stripslashes($row->getPreviewImage()),
'autolaunch' => $row->getAutolaunch(),
'session_id' => $row->getSessionId(),
'created_on' => $row->getCreatedOn() ? $row->getCreatedOn()->format('Y-m-d H:i:s') : null,
'modified_on' => $row->getModifiedOn() ? $row->getModifiedOn()->format('Y-m-d H:i:s') : null,
'publicated_on' => $row->getPublicatedOn() ? $row->getPublicatedOn()->format('Y-m-d H:i:s') : null,
'expired_on' => $row->getExpiredOn() ? $row->getExpiredOn()->format('Y-m-d H:i:s') : null,
//'category_id' => $row['category_id'],
'subscribe_users' => $row->getSubscribeUsers(),
'lp_old_id' => $row->getId(),
'iid' => $row->getIid(),
'prerequisite' => $row->getPrerequisite(),
'entity' => $row,
'lp_prevent_reinit' => $lp->getPreventReinit(),
'seriousgame_mode' => $lp->getSeriousgameMode(),
'lp_scorm_debug' => $lp->getDebug(),
'lp_display_order' => $lp->getDisplayOrder(),
'lp_preview_image' => stripslashes($lp->getPreviewImage()),
'autolaunch' => $lp->getAutolaunch(),
'session_id' => $lp->getSessionId(),
'created_on' => $lp->getCreatedOn() ? $lp->getCreatedOn()->format('Y-m-d H:i:s') : null,
'modified_on' => $lp->getModifiedOn() ? $lp->getModifiedOn()->format('Y-m-d H:i:s') : null,
'publicated_on' => $lp->getPublicatedOn() ? $lp->getPublicatedOn()->format('Y-m-d H:i:s') : null,
'expired_on' => $lp->getExpiredOn() ? $lp->getExpiredOn()->format('Y-m-d H:i:s') : null,
//'category_id' => $lp['category_id'],
'subscribe_users' => $lp->getSubscribeUsers(),
'lp_old_id' => $lp->getId(),
'iid' => $lp->getIid(),
'prerequisite' => $lp->getPrerequisite(),
'entity' => $lp,
];
$names[$row->getName()] = $row->getIid();
$names[$lp->getName()] = $lp->getIid();
}
asort($names);
$this->alpha_list = $names;

Loading…
Cancel
Save