Internal: Fix add shortcut to LP

pull/3466/head
Julio Montoya 4 years ago
parent 1ab4d4afd1
commit 7e3b7b250d
  1. 38
      public/main/lp/learnpath.class.php
  2. 2
      src/CourseBundle/Repository/CShortcutRepository.php

@ -755,6 +755,9 @@ class learnpath
} }
$id = null; $id = null;
$sessionEntity = api_get_session_entity();
$courseEntity = api_get_course_entity($courseInfo['real_id']);
switch ($origin) { switch ($origin) {
case 'zip': case 'zip':
// Check zip name string. If empty, we are currently creating a new Chamilo learnpath. // Check zip name string. If empty, we are currently creating a new Chamilo learnpath.
@ -782,23 +785,15 @@ class learnpath
->setCategoryId($categoryId) ->setCategoryId($categoryId)
->setPublicatedOn($publicated_on) ->setPublicatedOn($publicated_on)
->setExpiredOn($expired_on) ->setExpiredOn($expired_on)
->setParent($courseEntity)
->addCourseLink($courseEntity, $sessionEntity)
; ;
$repo = Container::getLpRepository(); $repo = Container::getLpRepository();
$em = $repo->getEntityManager(); $em = $repo->getEntityManager();
$em->persist($lp); $em->persist($lp);
$courseEntity = api_get_course_entity($courseInfo['real_id']);
$repo->addResourceToCourse(
$lp,
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity(api_get_user_id()),
$courseEntity,
api_get_session_entity(),
api_get_group_entity()
);
$em->flush(); $em->flush();
if ($lp->getIid()) { if ($lp->getIid()) {
$id = $lp->getIid(); $id = $lp->getIid();
$sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id"; $sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id";
@ -4369,19 +4364,24 @@ class learnpath
/** @var CLp $lp */ /** @var CLp $lp */
$lp = $repo->find($id); $lp = $repo->find($id);
$repoShortcut = Container::getShortcutRepository(); $repoShortcut = Container::getShortcutRepository();
$em = $repoShortcut->getEntityManager();
$courseEntity = api_get_course_entity();
if ($addShortcut) { if ($addShortcut) {
$shortcut = new CShortcut(); $shortcut = new CShortcut();
$shortcut->setName($lp->getName()); $shortcut
$shortcut->setShortCutNode($lp->getResourceNode()); ->setName($lp->getName())
->setShortCutNode($lp->getResourceNode())
$courseEntity = api_get_course_entity(api_get_course_int_id()); ->setParent($courseEntity)
$repoShortcut->addResourceNode($shortcut, api_get_user_entity(api_get_user_id()), $courseEntity); ->addCourseLink($courseEntity, api_get_session_entity())
$repoShortcut->getEntityManager()->flush(); ;
$em->persist($shortcut);
$em->flush();
} else { } else {
$shortcut = $repoShortcut->getShortcutFromResource($lp); $shortcut = $repoShortcut->getShortcutFromResource($lp);
if (null !== $shortcut) { if (null !== $shortcut) {
$repoShortcut->getEntityManager()->remove($shortcut); $em->remove($shortcut);
$repoShortcut->getEntityManager()->flush(); $em->flush();
} }
} }

@ -40,7 +40,7 @@ final class CShortcutRepository extends ResourceRepository
'resource.resourceNode', 'resource.resourceNode',
'node' 'node'
) )
->innerJoin('node.resourceFile', 'file') ->leftJoin('node.resourceFile', 'file')
//->innerJoin('node.resourceLinks', 'links') //->innerJoin('node.resourceLinks', 'links')
//->where('node.resourceType = :type') //->where('node.resourceType = :type')
//->setParameter('type',$type) //->setParameter('type',$type)

Loading…
Cancel
Save