Minor - LIT: Format code

pull/3065/head
Angel Fernando Quiroz Campos 6 years ago
parent 8154d1e596
commit da8ac134ae
  1. 326
      plugin/ims_lti/Entity/ImsLtiTool.php
  2. 12
      plugin/ims_lti/Entity/Platform.php
  3. 7
      plugin/ims_lti/auth.php
  4. 6
      plugin/ims_lti/configure.php
  5. 37
      plugin/ims_lti/src/ContentItem/LtiContentItemType.php
  6. 11
      plugin/ims_lti/src/ContentItem/LtiResourceLink.php
  7. 8
      plugin/ims_lti/src/Form/FrmAdd.php
  8. 5
      plugin/ims_lti/src/Form/FrmEdit.php

@ -18,6 +18,12 @@ use PHPExiftool\Driver\Tag\MXF\ViewportAspectRatio;
*/ */
class ImsLtiTool class ImsLtiTool
{ {
/**
* @var string|null
*
* @ORM\Column(name="public_key", type="text", nullable=true)
*/
public $publicKey;
/** /**
* @var integer * @var integer
* *
@ -68,14 +74,12 @@ class ImsLtiTool
* @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false}) * @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false})
*/ */
private $activeDeepLinking = false; private $activeDeepLinking = false;
/** /**
* @var null|string * @var null|string
* *
* @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null}) * @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null})
*/ */
private $privacy = null; private $privacy = null;
/** /**
* @var Course|null * @var Course|null
* *
@ -83,7 +87,6 @@ class ImsLtiTool
* @ORM\JoinColumn(name="c_id", referencedColumnName="id") * @ORM\JoinColumn(name="c_id", referencedColumnName="id")
*/ */
private $course = null; private $course = null;
/** /**
* @var GradebookEvaluation|null * @var GradebookEvaluation|null
* *
@ -91,7 +94,6 @@ class ImsLtiTool
* @ORM\JoinColumn(name="gradebook_eval_id", referencedColumnName="id", onDelete="SET NULL") * @ORM\JoinColumn(name="gradebook_eval_id", referencedColumnName="id", onDelete="SET NULL")
*/ */
private $gradebookEval = null; private $gradebookEval = null;
/** /**
* @var ImsLtiTool|null * @var ImsLtiTool|null
* *
@ -99,28 +101,18 @@ class ImsLtiTool
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/ */
private $parent; private $parent;
/** /**
* @var ArrayCollection * @var ArrayCollection
* *
* @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent") * @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent")
*/ */
private $children; private $children;
/** /**
* @var string * @var string
* *
* @ORM\Column(name="client_id", type="string", nullable=true) * @ORM\Column(name="client_id", type="string", nullable=true)
*/ */
private $clientId; private $clientId;
/**
* @var string|null
*
* @ORM\Column(name="public_key", type="text", nullable=true)
*/
public $publicKey;
/** /**
* @var string|null * @var string|null
* *
@ -165,7 +157,7 @@ class ImsLtiTool
$this->customParams = null; $this->customParams = null;
$this->activeDeepLinking = false; $this->activeDeepLinking = false;
$this->course = null; $this->course = null;
$this->gradebookEval =null; $this->gradebookEval = null;
$this->privacy = null; $this->privacy = null;
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
$this->consumerKey = null; $this->consumerKey = null;
@ -192,6 +184,7 @@ class ImsLtiTool
/** /**
* @param string $name * @param string $name
*
* @return ImsLtiTool * @return ImsLtiTool
*/ */
public function setName($name) public function setName($name)
@ -211,6 +204,7 @@ class ImsLtiTool
/** /**
* @param null|string $description * @param null|string $description
*
* @return ImsLtiTool * @return ImsLtiTool
*/ */
public function setDescription($description) public function setDescription($description)
@ -230,6 +224,7 @@ class ImsLtiTool
/** /**
* @param string $launchUrl * @param string $launchUrl
*
* @return ImsLtiTool * @return ImsLtiTool
*/ */
public function setLaunchUrl($launchUrl) public function setLaunchUrl($launchUrl)
@ -239,44 +234,6 @@ class ImsLtiTool
return $this; 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 * @return null|string
*/ */
@ -287,6 +244,7 @@ class ImsLtiTool
/** /**
* @param null|string $customParams * @param null|string $customParams
*
* @return ImsLtiTool * @return ImsLtiTool
*/ */
public function setCustomParams($customParams) public function setCustomParams($customParams)
@ -324,6 +282,9 @@ class ImsLtiTool
return implode("\n", $pairs); return implode("\n", $pairs);
} }
/**
* @return array
*/
public function getCustomParamsAsArray() public function getCustomParamsAsArray()
{ {
$params = []; $params = [];
@ -342,33 +303,6 @@ class ImsLtiTool
return $params; 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. * Map the key from custom param.
* *
@ -410,17 +344,30 @@ class ImsLtiTool
} }
/** /**
* Set activeDeepLinking. * @return array
*
* @param bool $activeDeepLinking
*
* @return ImsLtiTool
*/ */
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; return $this->activeDeepLinking;
} }
/**
* Set activeDeepLinking.
*
* @param bool $activeDeepLinking
*
* @return ImsLtiTool
*/
public function setActiveDeepLinking($activeDeepLinking)
{
$this->activeDeepLinking = $activeDeepLinking;
return $this;
}
/** /**
* Get course. * Get course.
* *
@ -482,45 +443,21 @@ class ImsLtiTool
} }
/** /**
* Get privacy. * @return bool
*
* @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) public function isSharingName()
{ {
$this->privacy = serialize( $unserialize = $this->unserializePrivacy();
[
'share_name' => $shareName,
'share_email' => $shareEmail,
'share_picture' => $sharePicture,
]
);
return $this; return (bool) $unserialize['share_name'];
} }
/** /**
* @return bool * @return mixed
*/ */
public function isSharingName() public function unserializePrivacy()
{ {
$unserialize = $this->unserializePrivacy(); return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy);
return (bool) $unserialize['share_name'];
} }
/** /**
@ -543,14 +480,6 @@ class ImsLtiTool
return (bool) $unserialize['share_picture']; return (bool) $unserialize['share_picture'];
} }
/**
* @return mixed
*/
public function unserializePrivacy()
{
return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy);
}
/** /**
* @return ImsLtiTool|null * @return ImsLtiTool|null
*/ */
@ -575,6 +504,78 @@ class ImsLtiTool
return $this; 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. * Get loginUrl.
* *
@ -647,20 +648,6 @@ class ImsLtiTool
return $this; return $this;
} }
/**
* Set advantageServices.
*
* @param array $advantageServices
*
* @return ImsLtiTool
*/
public function setAdvantageServices($advantageServices)
{
$this->advantageServices = $advantageServices;
return $this;
}
/** /**
* Get advantageServices. * 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->advantageServices = $advantageServices;
$this->lineItems[] = $lineItem;
return $this; return $this;
} }
/** /**
* Set lineItems. * Add LineItem to lineItems.
* *
* @param ArrayCollection $lineItems * @param LineItem $lineItem
* *
* @return $this * @return $this
*/ */
public function setLineItems(ArrayCollection $lineItems) public function addLineItem(LineItem $lineItem)
{ {
$this->lineItems = $lineItems; $lineItem->setTool($this);
$this->lineItems[] = $lineItem;
return $this; return $this;
} }
@ -750,6 +737,20 @@ class ImsLtiTool
return $this->lineItems->matching($criteria); return $this->lineItems->matching($criteria);
} }
/**
* Set lineItems.
*
* @param ArrayCollection $lineItems
*
* @return $this
*/
public function setLineItems(ArrayCollection $lineItems)
{
$this->lineItems = $lineItems;
return $this;
}
/** /**
* Get version. * Get version.
* *
@ -760,15 +761,6 @@ class ImsLtiTool
return $this->version; return $this->version;
} }
public function getVersionName()
{
if (\ImsLti::V_1P1 === $this->version) {
return 'LTI 1.0 / 1.1';
}
return 'LTI 1.3';
}
/** /**
* Set version. * Set version.
* *
@ -783,6 +775,18 @@ class ImsLtiTool
return $this; 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 * @return ArrayCollection
*/ */

@ -15,6 +15,12 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class Platform class Platform
{ {
/**
* @var string
*
* @ORM\Column(name="public_key", type="text")
*/
public $publicKey;
/** /**
* @var int * @var int
* *
@ -29,12 +35,6 @@ class Platform
* @ORM\Column(name="kid", type="string") * @ORM\Column(name="kid", type="string")
*/ */
private $kid; private $kid;
/**
* @var string
*
* @ORM\Column(name="public_key", type="text")
*/
public $publicKey;
/** /**
* @var string * @var string
* *

@ -27,7 +27,12 @@ $webPath = api_get_path(WEB_PATH);
$webPluginPath = api_get_path(WEB_PLUGIN_PATH); $webPluginPath = api_get_path(WEB_PLUGIN_PATH);
try { 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) empty($nonce)
) { ) {
throw LtiAuthException::invalidRequest(); throw LtiAuthException::invalidRequest();

@ -115,13 +115,10 @@ switch ($action) {
); );
} }
$toolIsV1p3 = !empty($tool->publicKey) && !empty($tool->getClientId()) &&
!empty($tool->getLoginUrl()) && !empty($tool->getRedirectUrl());
$em->persist($tool); $em->persist($tool);
$em->flush(); $em->flush();
if ($toolIsV1p3) { if ($tool->getVersion() === ImsLti::V_1P3) {
$advServices = $tool->getAdvantageServices(); $advServices = $tool->getAdvantageServices();
if (LtiAssignmentGradesService::AGS_NONE !== $advServices['ags']) { if (LtiAssignmentGradesService::AGS_NONE !== $advServices['ags']) {
@ -177,7 +174,6 @@ switch ($action) {
if ($form->validate()) { if ($form->validate()) {
$formValues = $form->getSubmitValues(); $formValues = $form->getSubmitValues();
var_dump($formValues);die;
$tool $tool
->setName($formValues['name']) ->setName($formValues['name'])

@ -3,6 +3,7 @@
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
use Doctrine\ORM\OptimisticLockException;
/** /**
* Class LtiContentItemType. * Class LtiContentItemType.
@ -16,28 +17,11 @@ abstract class LtiContentItemType
*/ */
abstract public function __construct(stdClass $itemData); 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 ImsLtiTool $baseTool
* @param Course $course * @param Course $course
* *
* @throws \Doctrine\ORM\OptimisticLockException * @throws OptimisticLockException
* *
* @return ImsLtiTool * @return ImsLtiTool
*/ */
@ -55,4 +39,21 @@ abstract class LtiContentItemType
return $newTool; 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);
} }

@ -1,7 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
/** /**
@ -72,12 +71,12 @@ class LtiResourceLink extends LtiContentItemType
$this->url = empty($itemData->url) ? '' : $itemData->url; $this->url = empty($itemData->url) ? '' : $itemData->url;
$this->title = empty($itemData->title) ? '' : $itemData->title; $this->title = empty($itemData->title) ? '' : $itemData->title;
$this->text = empty($itemData->text) ? '' : $itemData->text; $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; $this->icon = empty($itemData->icon) ? null : $itemData->icon;
if ($this->icon && if ($this->icon
(empty($this->icon->url) || empty($this->icon->width) || empty($this->icon->height)) && (empty($this->icon->url) || empty($this->icon->width) || empty($this->icon->height))
) { ) {
throw new Exception( throw new Exception(
sprintf("Icon properties are missing in data form content item: %s", print_r($itemData, true)) 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; $this->thumbnail = empty($itemData->thumbnail) ? null : $itemData->thumbnail;
if ($this->thumbnail && if ($this->thumbnail
(empty($this->thumbnail->url) || empty($this->thumbnail->width) || empty($this->thumbnail->height)) && (empty($this->thumbnail->url) || empty($this->thumbnail->width) || empty($this->thumbnail->height))
) { ) {
throw new Exception( throw new Exception(
sprintf("Thumbnail URL is missing in data form content item: %s", print_r($itemData, true)) sprintf("Thumbnail URL is missing in data form content item: %s", print_r($itemData, true))

@ -33,8 +33,10 @@ class FrmAdd extends FormValidator
$this->baseTool = $tool; $this->baseTool = $tool;
$this->toolIsV1p3 = $this->baseTool && $this->toolIsV1p3 = $this->baseTool &&
!empty($this->baseTool->publicKey) && !empty($this->baseTool->getClientId()) && !empty($this->baseTool->publicKey) &&
!empty($this->baseTool->getLoginUrl()) && !empty($this->baseTool->getRedirectUrl()); !empty($this->baseTool->getClientId()) &&
!empty($this->baseTool->getLoginUrl()) &&
!empty($this->baseTool->getRedirectUrl());
} }
/** /**
@ -105,7 +107,7 @@ class FrmAdd extends FormValidator
$plugin->get_lang('NamesAndRoleProvisioningService'), $plugin->get_lang('NamesAndRoleProvisioningService'),
[ [
LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), 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('</div>'); $this->addHtml('</div>');

@ -118,7 +118,7 @@ class FrmEdit extends FormValidator
$plugin->get_lang('NamesAndRoleProvisioningService'), $plugin->get_lang('NamesAndRoleProvisioningService'),
[ [
LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), 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'); $this->applyFilter('__ALL__', 'trim');
} }
/**
* @throws Exception
*/
public function setDefaultValues() public function setDefaultValues()
{ {
$advServices = $this->tool->getAdvantageServices(); $advServices = $this->tool->getAdvantageServices();

Loading…
Cancel
Save