Minor - LIT: Format code

pull/3065/head
Angel Fernando Quiroz Campos 6 years ago
parent 8154d1e596
commit da8ac134ae
  1. 324
      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. 9
      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
{
/**
* @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
*
@ -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
*/

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

@ -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();

@ -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'])

@ -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);
}

@ -1,7 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
/**
@ -76,8 +75,8 @@ class LtiResourceLink extends LtiContentItemType
$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))

@ -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('</div>');

@ -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();

Loading…
Cancel
Save