Skip to content

Commit

Permalink
LTI: improve creation for content item types - refs BT#16379
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Mar 25, 2020
1 parent 390a376 commit 8590e9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 40 deletions.
30 changes: 4 additions & 26 deletions plugin/ims_lti/src/ContentItem/LtiContentItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,19 @@ abstract class LtiContentItemType
* LtiContentItemType constructor.
*
* @param stdClass $itemData
*/
abstract public function __construct(stdClass $itemData);

/**
* @param ImsLtiTool $baseTool
* @param Course $course
*
* @throws OptimisticLockException
*
* @return ImsLtiTool
* @throws Exception
*/
public function save(ImsLtiTool $baseTool, Course $course)
public function __construct(stdClass $itemData)
{
$newTool = $this->createTool($baseTool);
$newTool->setActiveDeepLinking(false);

$em = Database::getManager();

$em->persist($newTool);
$em->flush();

ImsLtiPlugin::create()->addCourseTool($course, $newTool);

return $newTool;
$this->validateItemData($itemData);
}

/**
* @param ImsLtiTool $baseTool
* @param Course $course
*
* @return ImsLtiTool
* @throws Exception
*
*/
abstract protected function createTool(ImsLtiTool $baseTool);
abstract function save(ImsLtiTool $baseTool, Course $course);

/**
* @param stdClass $itemData
Expand Down
40 changes: 26 additions & 14 deletions plugin/ims_lti/src/ContentItem/LtiResourceLink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */

use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;

/**
Expand Down Expand Up @@ -49,18 +50,6 @@ class LtiResourceLink extends LtiContentItemType
*/
private $submission;

/**
* LtiContentItem constructor.
*
* @param stdClass $itemData
*
* @throws Exception
*/
public function __construct(stdClass $itemData)
{
$this->validateItemData($itemData);
}

/**
* @param stdClass $itemData
*
Expand Down Expand Up @@ -127,9 +116,11 @@ protected function validateItemData(stdClass $itemData)
}

/**
* @inheritDoc
* @param ImsLtiTool $baseTool
*
* @return ImsLtiTool
*/
protected function createTool(ImsLtiTool $baseTool)
private function createTool(ImsLtiTool $baseTool)
{
$newTool = clone $baseTool;
$newTool->setParent($baseTool);
Expand All @@ -154,4 +145,25 @@ protected function createTool(ImsLtiTool $baseTool)

return $newTool;
}

/**
* @param ImsLtiTool $baseTool
* @param Course $course
*
* @throws \Doctrine\ORM\OptimisticLockException
*
* @return ImsLtiTool
*/
public function save(ImsLtiTool $baseTool, Course $course)
{
$newTool = $this->createTool($baseTool);
$newTool->setActiveDeepLinking(false);

$em = Database::getManager();

$em->persist($newTool);
$em->flush();

ImsLtiPlugin::create()->addCourseTool($course, $newTool);
}
}

0 comments on commit 8590e9f

Please sign in to comment.