diff --git a/plugin/ims_lti/Entity/ImsLtiTool.php b/plugin/ims_lti/Entity/ImsLtiTool.php index c7d58e5eea..8a47b6a7ed 100644 --- a/plugin/ims_lti/Entity/ImsLtiTool.php +++ b/plugin/ims_lti/Entity/ImsLtiTool.php @@ -18,6 +18,12 @@ use PHPExiftool\Driver\Tag\MXF\ViewportAspectRatio; */ class ImsLtiTool { + /** + * @var string|null + * + * @ORM\Column(name="public_key", type="text", nullable=true) + */ + public $publicKey; /** * @var integer * @@ -68,14 +74,12 @@ class ImsLtiTool * @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false}) */ private $activeDeepLinking = false; - /** * @var null|string * * @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null}) */ private $privacy = null; - /** * @var Course|null * @@ -83,7 +87,6 @@ class ImsLtiTool * @ORM\JoinColumn(name="c_id", referencedColumnName="id") */ private $course = null; - /** * @var GradebookEvaluation|null * @@ -91,7 +94,6 @@ class ImsLtiTool * @ORM\JoinColumn(name="gradebook_eval_id", referencedColumnName="id", onDelete="SET NULL") */ private $gradebookEval = null; - /** * @var ImsLtiTool|null * @@ -99,28 +101,18 @@ class ImsLtiTool * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") */ private $parent; - /** * @var ArrayCollection * * @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent") */ private $children; - /** * @var string * * @ORM\Column(name="client_id", type="string", nullable=true) */ private $clientId; - - /** - * @var string|null - * - * @ORM\Column(name="public_key", type="text", nullable=true) - */ - public $publicKey; - /** * @var string|null * @@ -165,7 +157,7 @@ class ImsLtiTool $this->customParams = null; $this->activeDeepLinking = false; $this->course = null; - $this->gradebookEval =null; + $this->gradebookEval = null; $this->privacy = null; $this->children = new ArrayCollection(); $this->consumerKey = null; @@ -192,6 +184,7 @@ class ImsLtiTool /** * @param string $name + * * @return ImsLtiTool */ public function setName($name) @@ -211,6 +204,7 @@ class ImsLtiTool /** * @param null|string $description + * * @return ImsLtiTool */ public function setDescription($description) @@ -230,6 +224,7 @@ class ImsLtiTool /** * @param string $launchUrl + * * @return ImsLtiTool */ public function setLaunchUrl($launchUrl) @@ -239,44 +234,6 @@ class ImsLtiTool return $this; } - /** - * @return string - */ - public function getConsumerKey() - { - return $this->consumerKey; - } - - /** - * @param string $consumerKey - * @return ImsLtiTool - */ - public function setConsumerKey($consumerKey) - { - $this->consumerKey = $consumerKey; - - return $this; - } - - /** - * @return string - */ - public function getSharedSecret() - { - return $this->sharedSecret; - } - - /** - * @param string $sharedSecret - * @return ImsLtiTool - */ - public function setSharedSecret($sharedSecret) - { - $this->sharedSecret = $sharedSecret; - - return $this; - } - /** * @return null|string */ @@ -287,6 +244,7 @@ class ImsLtiTool /** * @param null|string $customParams + * * @return ImsLtiTool */ public function setCustomParams($customParams) @@ -324,6 +282,9 @@ class ImsLtiTool return implode("\n", $pairs); } + /** + * @return array + */ public function getCustomParamsAsArray() { $params = []; @@ -342,33 +303,6 @@ class ImsLtiTool return $params; } - /** - * @return array - */ - public function parseCustomParams() - { - if (empty($this->customParams)) { - return []; - } - - $params = []; - $strings = explode("\n", $this->customParams); - - foreach ($strings as $string) { - if (empty($string)) { - continue; - } - - $pairs = explode('=', $string, 2); - $key = self::filterSpecialChars($pairs[0]); - $value = $pairs[1]; - - $params['custom_'.$key] = $value; - } - - return $params; - } - /** * Map the key from custom param. * @@ -410,17 +344,30 @@ class ImsLtiTool } /** - * Set activeDeepLinking. - * - * @param bool $activeDeepLinking - * - * @return ImsLtiTool + * @return array */ - public function setActiveDeepLinking($activeDeepLinking) + public function parseCustomParams() { - $this->activeDeepLinking = $activeDeepLinking; + if (empty($this->customParams)) { + return []; + } - return $this; + $params = []; + $strings = explode("\n", $this->customParams); + + foreach ($strings as $string) { + if (empty($string)) { + continue; + } + + $pairs = explode('=', $string, 2); + $key = self::filterSpecialChars($pairs[0]); + $value = $pairs[1]; + + $params['custom_'.$key] = $value; + } + + return $params; } /** @@ -433,6 +380,20 @@ class ImsLtiTool return $this->activeDeepLinking; } + /** + * Set activeDeepLinking. + * + * @param bool $activeDeepLinking + * + * @return ImsLtiTool + */ + public function setActiveDeepLinking($activeDeepLinking) + { + $this->activeDeepLinking = $activeDeepLinking; + + return $this; + } + /** * Get course. * @@ -482,45 +443,21 @@ class ImsLtiTool } /** - * Get privacy. - * - * @return null|string - */ - public function getPrivacy() - { - return $this->privacy; - } - - /** - * Set privacy. - * - * @param bool $shareName - * @param bool $shareEmail - * @param bool $sharePicture - * - * @return ImsLtiTool + * @return bool */ - public function setPrivacy($shareName = false, $shareEmail = false, $sharePicture = false) + public function isSharingName() { - $this->privacy = serialize( - [ - 'share_name' => $shareName, - 'share_email' => $shareEmail, - 'share_picture' => $sharePicture, - ] - ); + $unserialize = $this->unserializePrivacy(); - return $this; + return (bool) $unserialize['share_name']; } /** - * @return bool + * @return mixed */ - public function isSharingName() + public function unserializePrivacy() { - $unserialize = $this->unserializePrivacy(); - - return (bool) $unserialize['share_name']; + return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy); } /** @@ -543,14 +480,6 @@ class ImsLtiTool return (bool) $unserialize['share_picture']; } - /** - * @return mixed - */ - public function unserializePrivacy() - { - return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy); - } - /** * @return ImsLtiTool|null */ @@ -575,6 +504,78 @@ class ImsLtiTool return $this; } + /** + * @return string + */ + public function getSharedSecret() + { + return $this->sharedSecret; + } + + /** + * @param string $sharedSecret + * + * @return ImsLtiTool + */ + public function setSharedSecret($sharedSecret) + { + $this->sharedSecret = $sharedSecret; + + return $this; + } + + /** + * @return string + */ + public function getConsumerKey() + { + return $this->consumerKey; + } + + /** + * @param string $consumerKey + * + * @return ImsLtiTool + */ + public function setConsumerKey($consumerKey) + { + $this->consumerKey = $consumerKey; + + return $this; + } + + /** + * Get privacy. + * + * @return null|string + */ + public function getPrivacy() + { + return $this->privacy; + } + + /** + * Set privacy. + * + * @param bool $shareName + * @param bool $shareEmail + * @param bool $sharePicture + * + * @return ImsLtiTool + */ + public function setPrivacy($shareName = false, $shareEmail = false, $sharePicture = false) + { + $this->privacy = serialize( + [ + 'share_name' => $shareName, + 'share_email' => $shareEmail, + 'share_picture' => $sharePicture, + ] + ); + + return $this; + } + /** * Get loginUrl. * @@ -647,20 +648,6 @@ class ImsLtiTool return $this; } - /** - * Set advantageServices. - * - * @param array $advantageServices - * - * @return ImsLtiTool - */ - public function setAdvantageServices($advantageServices) - { - $this->advantageServices = $advantageServices; - - return $this; - } - /** * Get advantageServices. * @@ -682,31 +669,31 @@ class ImsLtiTool } /** - * Add LineItem to lineItems. + * Set advantageServices. * - * @param LineItem $lineItem + * @param array $advantageServices * - * @return $this + * @return ImsLtiTool */ - public function addLineItem(LineItem $lineItem) + public function setAdvantageServices($advantageServices) { - $lineItem->setTool($this); - - $this->lineItems[] = $lineItem; + $this->advantageServices = $advantageServices; return $this; } /** - * Set lineItems. + * Add LineItem to lineItems. * - * @param ArrayCollection $lineItems + * @param LineItem $lineItem * * @return $this */ - public function setLineItems(ArrayCollection $lineItems) + public function addLineItem(LineItem $lineItem) { - $this->lineItems = $lineItems; + $lineItem->setTool($this); + + $this->lineItems[] = $lineItem; return $this; } @@ -750,6 +737,20 @@ class ImsLtiTool return $this->lineItems->matching($criteria); } + /** + * Set lineItems. + * + * @param ArrayCollection $lineItems + * + * @return $this + */ + public function setLineItems(ArrayCollection $lineItems) + { + $this->lineItems = $lineItems; + + return $this; + } + /** * Get version. * @@ -760,15 +761,6 @@ class ImsLtiTool return $this->version; } - public function getVersionName() - { - if (\ImsLti::V_1P1 === $this->version) { - return 'LTI 1.0 / 1.1'; - } - - return 'LTI 1.3'; - } - /** * Set version. * @@ -783,6 +775,18 @@ class ImsLtiTool return $this; } + /** + * @return string + */ + public function getVersionName() + { + if (\ImsLti::V_1P1 === $this->version) { + return 'LTI 1.0 / 1.1'; + } + + return 'LTI 1.3'; + } + /** * @return ArrayCollection */ diff --git a/plugin/ims_lti/Entity/Platform.php b/plugin/ims_lti/Entity/Platform.php index 9be5916a9e..ddacd32e40 100644 --- a/plugin/ims_lti/Entity/Platform.php +++ b/plugin/ims_lti/Entity/Platform.php @@ -15,6 +15,12 @@ use Doctrine\ORM\Mapping as ORM; */ class Platform { + /** + * @var string + * + * @ORM\Column(name="public_key", type="text") + */ + public $publicKey; /** * @var int * @@ -29,12 +35,6 @@ class Platform * @ORM\Column(name="kid", type="string") */ private $kid; - /** - * @var string - * - * @ORM\Column(name="public_key", type="text") - */ - public $publicKey; /** * @var string * diff --git a/plugin/ims_lti/auth.php b/plugin/ims_lti/auth.php index 24f993dc7e..f147f1ac7f 100644 --- a/plugin/ims_lti/auth.php +++ b/plugin/ims_lti/auth.php @@ -27,7 +27,12 @@ $webPath = api_get_path(WEB_PATH); $webPluginPath = api_get_path(WEB_PLUGIN_PATH); try { - if (empty($scope) || empty($responseType) || empty($clientId) || empty($redirectUri) || empty($loginHint) || + if ( + empty($scope) || + empty($responseType) || + empty($clientId) || + empty($redirectUri) || + empty($loginHint) || empty($nonce) ) { throw LtiAuthException::invalidRequest(); diff --git a/plugin/ims_lti/configure.php b/plugin/ims_lti/configure.php index 0764c03ce2..43a6aa4f47 100644 --- a/plugin/ims_lti/configure.php +++ b/plugin/ims_lti/configure.php @@ -115,13 +115,10 @@ switch ($action) { ); } - $toolIsV1p3 = !empty($tool->publicKey) && !empty($tool->getClientId()) && - !empty($tool->getLoginUrl()) && !empty($tool->getRedirectUrl()); - $em->persist($tool); $em->flush(); - if ($toolIsV1p3) { + if ($tool->getVersion() === ImsLti::V_1P3) { $advServices = $tool->getAdvantageServices(); if (LtiAssignmentGradesService::AGS_NONE !== $advServices['ags']) { @@ -177,7 +174,6 @@ switch ($action) { if ($form->validate()) { $formValues = $form->getSubmitValues(); - var_dump($formValues);die; $tool ->setName($formValues['name']) diff --git a/plugin/ims_lti/src/ContentItem/LtiContentItemType.php b/plugin/ims_lti/src/ContentItem/LtiContentItemType.php index ed850f5477..cc4549142a 100644 --- a/plugin/ims_lti/src/ContentItem/LtiContentItemType.php +++ b/plugin/ims_lti/src/ContentItem/LtiContentItemType.php @@ -3,6 +3,7 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; +use Doctrine\ORM\OptimisticLockException; /** * Class LtiContentItemType. @@ -16,28 +17,11 @@ abstract class LtiContentItemType */ abstract public function __construct(stdClass $itemData); - /** - * @param stdClass $itemData - * - * @throws Exception - */ - abstract protected function validateItemData(stdClass $itemData); - - /** - * @param ImsLtiTool $baseTool - * @param Course $course - * - * @throws Exception - * - * @return ImsLtiTool - */ - abstract protected function createTool(ImsLtiTool $baseTool); - /** * @param ImsLtiTool $baseTool * @param Course $course * - * @throws \Doctrine\ORM\OptimisticLockException + * @throws OptimisticLockException * * @return ImsLtiTool */ @@ -55,4 +39,21 @@ abstract class LtiContentItemType return $newTool; } + + /** + * @param ImsLtiTool $baseTool + * @param Course $course + * + * @return ImsLtiTool + * @throws Exception + * + */ + abstract protected function createTool(ImsLtiTool $baseTool); + + /** + * @param stdClass $itemData + * + * @throws Exception + */ + abstract protected function validateItemData(stdClass $itemData); } diff --git a/plugin/ims_lti/src/ContentItem/LtiResourceLink.php b/plugin/ims_lti/src/ContentItem/LtiResourceLink.php index 8466e1fa7a..b0f4a6aec1 100644 --- a/plugin/ims_lti/src/ContentItem/LtiResourceLink.php +++ b/plugin/ims_lti/src/ContentItem/LtiResourceLink.php @@ -1,7 +1,6 @@ url = empty($itemData->url) ? '' : $itemData->url; $this->title = empty($itemData->title) ? '' : $itemData->title; $this->text = empty($itemData->text) ? '' : $itemData->text; - $this->custom = empty($itemData->custom) || !is_array($itemData->custom) ? [] : (array) $itemData->custom; + $this->custom = empty($itemData->custom) || !is_array($itemData->custom) ? [] : (array)$itemData->custom; $this->icon = empty($itemData->icon) ? null : $itemData->icon; - if ($this->icon && - (empty($this->icon->url) || empty($this->icon->width) || empty($this->icon->height)) + if ($this->icon + && (empty($this->icon->url) || empty($this->icon->width) || empty($this->icon->height)) ) { throw new Exception( sprintf("Icon properties are missing in data form content item: %s", print_r($itemData, true)) @@ -86,8 +85,8 @@ class LtiResourceLink extends LtiContentItemType $this->thumbnail = empty($itemData->thumbnail) ? null : $itemData->thumbnail; - if ($this->thumbnail && - (empty($this->thumbnail->url) || empty($this->thumbnail->width) || empty($this->thumbnail->height)) + if ($this->thumbnail + && (empty($this->thumbnail->url) || empty($this->thumbnail->width) || empty($this->thumbnail->height)) ) { throw new Exception( sprintf("Thumbnail URL is missing in data form content item: %s", print_r($itemData, true)) diff --git a/plugin/ims_lti/src/Form/FrmAdd.php b/plugin/ims_lti/src/Form/FrmAdd.php index d4712a8e6c..8a54e465d0 100644 --- a/plugin/ims_lti/src/Form/FrmAdd.php +++ b/plugin/ims_lti/src/Form/FrmAdd.php @@ -33,8 +33,10 @@ class FrmAdd extends FormValidator $this->baseTool = $tool; $this->toolIsV1p3 = $this->baseTool && - !empty($this->baseTool->publicKey) && !empty($this->baseTool->getClientId()) && - !empty($this->baseTool->getLoginUrl()) && !empty($this->baseTool->getRedirectUrl()); + !empty($this->baseTool->publicKey) && + !empty($this->baseTool->getClientId()) && + !empty($this->baseTool->getLoginUrl()) && + !empty($this->baseTool->getRedirectUrl()); } /** @@ -105,7 +107,7 @@ class FrmAdd extends FormValidator $plugin->get_lang('NamesAndRoleProvisioningService'), [ LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), - LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService') + LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'), ] ); $this->addHtml(''); diff --git a/plugin/ims_lti/src/Form/FrmEdit.php b/plugin/ims_lti/src/Form/FrmEdit.php index 4dc08ca29b..28755a5808 100644 --- a/plugin/ims_lti/src/Form/FrmEdit.php +++ b/plugin/ims_lti/src/Form/FrmEdit.php @@ -118,7 +118,7 @@ class FrmEdit extends FormValidator $plugin->get_lang('NamesAndRoleProvisioningService'), [ LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), - LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService') + LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'), ] ); } @@ -136,6 +136,9 @@ class FrmEdit extends FormValidator $this->applyFilter('__ALL__', 'trim'); } + /** + * @throws Exception + */ public function setDefaultValues() { $advServices = $this->tool->getAdvantageServices();