LTI: improve creation for content item types - refs BT#16379

pull/3141/head
Angel Fernando Quiroz Campos 6 years ago
parent 390a376812
commit 8590e9f4ca
  1. 30
      plugin/ims_lti/src/ContentItem/LtiContentItemType.php
  2. 40
      plugin/ims_lti/src/ContentItem/LtiResourceLink.php

@ -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

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
/**
@ -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
*
@ -127,9 +116,11 @@ class LtiResourceLink extends LtiContentItemType
}
/**
* @inheritDoc
* @param ImsLtiTool $baseTool
*
* @return ImsLtiTool
*/
protected function createTool(ImsLtiTool $baseTool)
private function createTool(ImsLtiTool $baseTool)
{
$newTool = clone $baseTool;
$newTool->setParent($baseTool);
@ -154,4 +145,25 @@ class LtiResourceLink extends LtiContentItemType
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);
}
}

Loading…
Cancel
Save