Internal: Refactor shortcut code in order to use the shortcut repository

pull/3466/head
Julio Montoya 5 years ago
parent a8dd9d039f
commit f734211c72
  1. 13
      public/main/exercise/exercise.php
  2. 20
      public/main/lp/learnpath.class.php
  3. 2
      src/CourseBundle/Repository/CShortcutRepository.php

@ -95,24 +95,15 @@ if ($is_allowedToEdit && !empty($action)) {
switch ($action) {
case 'add_shortcut':
$repo = Container::getShortcutRepository();
$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->getEntityManager()->flush();
$repo->addShortCut($exerciseEntity, $courseEntity, $courseEntity, api_get_session_entity());
Display::addFlash(Display::return_message(get_lang('Updated')));
break;
case 'remove_shortcut':
$repo = Container::getShortcutRepository();
$shortcut = $repo->getShortcutFromResource($exerciseEntity);
if (null !== $shortcut) {
$repo->getEntityManager()->remove($shortcut);
$repo->getEntityManager()->flush();
}
$repo->removeShortCut($exerciseEntity);
Display::addFlash(Display::return_message(get_lang('Deleted')));

@ -4460,7 +4460,6 @@ class learnpath
}
/**
* Publishes a learnpath.
* Show or hide the learnpath category on the course homepage.
*
* @param int $id
@ -4471,7 +4470,6 @@ class learnpath
public static function toggleCategoryPublish($id, $setVisibility = 1)
{
$setVisibility = (int) $setVisibility;
$sessionId = api_get_session_id();
$addShortcut = false;
if (1 === $setVisibility) {
$addShortcut = true;
@ -4480,21 +4478,17 @@ class learnpath
$repo = Container::getLpCategoryRepository();
/** @var CLpCategory $lp */
$category = $repo->find($id);
if (null === $category) {
return false;
}
$repoShortcut = Container::getShortcutRepository();
if ($addShortcut) {
$shortcut = new CShortcut();
$shortcut->setName($category->getName());
$shortcut->setShortCutNode($category->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();
$repoShortcut->addShortCut($category, $courseEntity, $courseEntity, api_get_session_entity());
} else {
$shortcut = $repoShortcut->getShortcutFromResource($category);
if (null !== $shortcut) {
$repoShortcut->getEntityManager()->remove($shortcut);
$repoShortcut->getEntityManager()->flush();
}
$repoShortcut->removeShortCut($category);
}
return true;

@ -20,7 +20,7 @@ use Symfony\Component\Form\FormInterface;
*/
final class CShortcutRepository extends ResourceRepository
{
private function getShortcutFromResource(AbstractResource $resource): ?CShortcut
public function getShortcutFromResource(AbstractResource $resource): ?CShortcut
{
$repo = $this->getRepository();
$criteria = ['shortCutNode' => $resource->getResourceNode()];

Loading…
Cancel
Save