Skip to content

Commit 11fa863

Browse files
authored
Merge pull request #1552 from jloguercio/1.11.x
Added Delete session with SequenceResource Linked validation
2 parents 64d2887 + b94dc53 commit 11fa863

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

main/inc/lib/sessionmanager.lib.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,18 @@ public static function delete($id_checked, $from_ws = false)
15491549

15501550
$userId = api_get_user_id();
15511551

1552+
/** @var \Chamilo\CoreBundle\Entity\Repository\SequenceRepository $repo */
1553+
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
1554+
$sequenceResourse = $repo->findRequirementForResource(
1555+
$id_checked,
1556+
\Chamilo\CoreBundle\Entity\SequenceResource::SESSION_TYPE
1557+
);
1558+
1559+
if ($sequenceResourse) {
1560+
Display::addFlash(Display::return_message(get_lang('ThereIsASequenceResourceLinkedToThisSessionYouNeedToDeleteItFirst'), 'error'));
1561+
return false;
1562+
}
1563+
15521564
if (is_array($id_checked)) {
15531565
foreach ($id_checked as $sessionId) {
15541566
self::delete($sessionId);
@@ -1612,8 +1624,6 @@ public static function delete($id_checked, $from_ws = false)
16121624
$extraFieldValue = new ExtraFieldValue('session');
16131625
$extraFieldValue->deleteValuesByItem($id_checked);
16141626

1615-
/** @var \Chamilo\CoreBundle\Entity\Repository\SequenceRepository $repo */
1616-
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
16171627
$repo->deleteResource(
16181628
$id_checked,
16191629
\Chamilo\CoreBundle\Entity\SequenceResource::SESSION_TYPE
@@ -1627,6 +1637,8 @@ public static function delete($id_checked, $from_ws = false)
16271637
api_get_utc_datetime(),
16281638
$userId
16291639
);
1640+
1641+
return true;
16301642
}
16311643

16321644
/**

main/session/session_list.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
$list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
2020

2121
if ($action == 'delete') {
22-
SessionManager::delete($idChecked);
23-
Display::addFlash(Display::return_message(get_lang('Deleted')));
22+
$response = SessionManager::delete($idChecked);
23+
24+
if ($response) {
25+
Display::addFlash(Display::return_message(get_lang('Deleted')));
26+
}
2427
header('Location: session_list.php');
2528
exit();
2629
} elseif ($action == 'copy') {

src/Chamilo/CoreBundle/Entity/Repository/SequenceRepository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ public function getRequirementAndDependencies($resourceId, $type)
7575
*
7676
* @param int $resourceId
7777
* @param int $type
78+
* @return boolean
7879
*/
7980
public function deleteResource($resourceId, $type)
8081
{
8182
$sequence = $this->findRequirementForResource($resourceId, $type);
8283

8384
if ($sequence && $sequence->hasGraph()) {
8485
$em = $this->getEntityManager();
85-
$graph = $sequence->getUnSerializeGraph();
86+
$graph = $sequence->getSequence()->getUnSerializeGraph();
8687

8788
$mainVertex = $graph->getVertex($resourceId);
8889
$vertices = $graph->getVertices();
@@ -92,10 +93,10 @@ public function deleteResource($resourceId, $type)
9293
$subResourceId = $vertex->getId();
9394
$subSequence = $this->findRequirementForResource($subResourceId, $type);
9495
if ($sequence && $subSequence->hasGraph()) {
95-
$graph = $subSequence->getUnSerializeGraph();
96+
$graph = $subSequence->getSequence()->getUnSerializeGraph();
9697
$subMainVertex = $graph->getVertex($resourceId);
9798
$subMainVertex->destroy();
98-
$subSequence->setGraphAndSerialize($graph);
99+
$subSequence->getSequence()->setGraphAndSerialize($graph);
99100
$em->persist($subSequence);
100101
}
101102
}

0 commit comments

Comments
 (0)