From 06d3cc042213c62af4dfbfd8d338bc97d4dbd290 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:28:45 -0500 Subject: [PATCH 1/5] LTI: Add migration to check and table columns --- .../Schema/V200/Version20251002110000.php | 32 ++ .../Schema/V200/Version20251002110001.php | 280 ++++++++++++++++++ src/LtiBundle/Entity/ExternalTool.php | 102 +++---- src/LtiBundle/Entity/LineItem.php | 16 +- src/LtiBundle/Entity/Platform.php | 9 +- src/LtiBundle/Entity/Token.php | 15 +- 6 files changed, 384 insertions(+), 70 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20251002110000.php create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20251002110001.php diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20251002110000.php b/src/CoreBundle/Migrations/Schema/V200/Version20251002110000.php new file mode 100644 index 00000000000..4506e23c59f --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20251002110000.php @@ -0,0 +1,32 @@ +addSql("CREATE TABLE IF NOT EXISTS lti_lineitem (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC"); + + $this->addSql("CREATE TABLE IF NOT EXISTS lti_external_tool (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC"); + + $this->addSql("CREATE TABLE IF NOT EXISTS lti_token (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC"); + + $this->addSql("CREATE TABLE IF NOT EXISTS lti_platform (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC"); + } +} diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20251002110001.php b/src/CoreBundle/Migrations/Schema/V200/Version20251002110001.php new file mode 100644 index 00000000000..3525aa6a192 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20251002110001.php @@ -0,0 +1,280 @@ +getTable('lti_lineitem'); + + if ($lineItem->hasIndex('IDX_5C76B75D8F7B22CC')) { + $this->addSql("DROP INDEX IDX_5C76B75D8F7B22CC ON lti_lineitem"); + } + + if ($lineItem->hasForeignKey('FK_5C76B75D8F7B22CC')) { + $this->addSql("ALTER TABLE lti_lineitem DROP FOREIGN KEY FK_5C76B75D8F7B22CC"); + } + + if ($lineItem->hasColumn('tool_id')) { + $this->addSql('ALTER TABLE lti_lineitem DROP COLUMN tool_id'); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD tool_id INT NOT NULL"); + $this->addSql("ALTER TABLE lti_lineitem ADD CONSTRAINT FK_5C76B75D8F7B22CC FOREIGN KEY (tool_id) REFERENCES lti_external_tool (id) ON DELETE CASCADE"); + $this->addSql("CREATE INDEX IDX_5C76B75D8F7B22CC ON lti_lineitem (tool_id)"); + + if ($lineItem->hasIndex('UNIQ_5C76B75D1323A575')) { + $this->addSql("DROP INDEX UNIQ_5C76B75D1323A575 ON lti_lineitem"); + } + + if ($lineItem->hasForeignKey('FK_5C76B75D1323A575')) { + $this->addSql("ALTER TABLE lti_lineitem DROP FOREIGN KEY FK_5C76B75D1323A575"); + } + + if ($lineItem->hasColumn('evaluation')) { + $this->addSql("ALTER TABLE lti_lineitem DROP COLUMN evaluation"); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD evaluation INT NOT NULL"); + $this->addSql("ALTER TABLE lti_lineitem ADD CONSTRAINT FK_5C76B75D1323A575 FOREIGN KEY (evaluation) REFERENCES gradebook_evaluation (id) ON DELETE CASCADE"); + $this->addSql("CREATE UNIQUE INDEX UNIQ_5C76B75D1323A575 ON lti_lineitem (evaluation)"); + + if ($lineItem->hasColumn('resource_id')) { + $this->addSql("ALTER TABLE DROP COLUMN resource_id"); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD resource_id VARCHAR(255) DEFAULT NULL"); + + if ($lineItem->hasColumn('tag')) { + $this->addSql("ALTER TABLE DROP COLUMN tag"); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD tag VARCHAR(255) DEFAULT NULL"); + + if ($lineItem->hasColumn('start_date')) { + $this->addSql("ALTER TABLE DROP COLUMN start_date"); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD start_date DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)'"); + + if ($lineItem->hasColumn('end_date')) { + $this->addSql("ALTER TABLE DROP COLUMN end_date"); + } + + $this->addSql("ALTER TABLE lti_lineitem ADD end_date DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)'"); + + $externalTool = $schema->getTable('lti_external_tool'); + + if ($externalTool->hasIndex('UNIQ_DB0E04E41BAD783F')) { + $this->addSql("DROP INDEX UNIQ_DB0E04E41BAD783F ON lti_external_tool"); + } + + if ($externalTool->hasForeignKey('FK_DB0E04E41BAD783F')) { + $this->addSql("ALTER TABLE lti_external_tool DROP FOREIGN KEY FK_DB0E04E41BAD783F"); + } + + if ($externalTool->hasColumn('resource_node_id')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN resource_node_id"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD resource_node_id INT DEFAULT NULL"); + $this->addSql('ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E41BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'); + $this->addSql("CREATE UNIQUE INDEX UNIQ_DB0E04E41BAD783F ON lti_external_tool (resource_node_id)"); + + if ($externalTool->hasIndex('IDX_DB0E04E482F80D8B')) { + $this->addSql("DROP INDEX IDX_DB0E04E482F80D8B ON lti_external_tool"); + } + + if ($externalTool->hasForeignKey('FK_DB0E04E482F80D8B')) { + $this->addSql("ALTER TABLE lti_external_tool DROP FOREIGN KEY FK_DB0E04E482F80D8B"); + } + + if ($externalTool->hasColumn('gradebook_eval_id')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN gradebook_eval_id"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD gradebook_eval_id INT DEFAULT NULL"); + $this->addSql("ALTER TABLE lti_external_tool ADD CONSTRAINT FK_DB0E04E482F80D8B FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id) ON DELETE SET NULL"); + $this->addSql("CREATE INDEX IDX_DB0E04E482F80D8B ON lti_external_tool (gradebook_eval_id)"); + + if ($externalTool->hasColumn('title')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN title"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD title VARCHAR(255) NOT NULL"); + + if ($externalTool->hasColumn('description')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN description"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD description LONGTEXT DEFAULT NULL"); + + if ($externalTool->hasColumn('public_key')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN public_key"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD public_key LONGTEXT DEFAULT NULL"); + + if ($externalTool->hasColumn('launch_url')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN launch_url"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD launch_url VARCHAR(255) NOT NULL"); + + if ($externalTool->hasColumn('consumer_key')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN consumer_key"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD consumer_key VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('shared_secret')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN shared_secret"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD shared_secret VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('custom_params')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN custom_params"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD custom_params LONGTEXT DEFAULT NULL"); + + if ($externalTool->hasColumn('active_deep_linking')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN active_deep_linking"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD active_deep_linking TINYINT(1) DEFAULT 0 NOT NULL"); + + if ($externalTool->hasColumn('privacy')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN privacy"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD privacy LONGTEXT DEFAULT NULL"); + + if ($externalTool->hasColumn('client_id')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN client_id"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD client_id VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('login_url')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN login_url"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD login_url VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('redirect_url')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN redirect_url"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD redirect_url VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('jwks_url')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN jwks_url"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD jwks_url VARCHAR(255) DEFAULT NULL"); + + if ($externalTool->hasColumn('advantage_services')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN advantage_services"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD advantage_services JSON DEFAULT NULL COMMENT '(DC2Type:json)'"); + + if ($externalTool->hasColumn('version')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN version"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD version VARCHAR(255) DEFAULT 'lti1p3' NOT NULL"); + + if ($externalTool->hasColumn('launch_presentation')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN launch_presentation"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD launch_presentation JSON NOT NULL COMMENT '(DC2Type:json)'"); + + if ($externalTool->hasColumn('replacement_params')) { + $this->addSql("ALTER TABLE lti_external_tool DROP COLUMN replacement_params"); + } + + $this->addSql("ALTER TABLE lti_external_tool ADD replacement_params JSON NOT NULL COMMENT '(DC2Type:json)'"); + + $token = $schema->getTable('lti_token'); + + if ($token->hasIndex('IDX_EA71C468F7B22CC')) { + $this->addSql("DROP INDEX IDX_EA71C468F7B22CC ON lti_token"); + } + + if ($token->hasForeignKey('FK_EA71C468F7B22CC')) { + $this->addSql("ALTER TABLE lti_token DROP FOREIGN KEY FK_EA71C468F7B22CC"); + } + + if ($token->hasColumn('tool_id')) { + $this->addSql("ALTER TABLE lti_token DROP COLUMN tool_id"); + } + + $this->addSql("ALTER TABLE lti_token ADD tool_id INT DEFAULT NULL"); + $this->addSql("ALTER TABLE lti_token ADD CONSTRAINT FK_EA71C468F7B22CC FOREIGN KEY (tool_id) REFERENCES lti_external_tool (id) ON DELETE CASCADE"); + $this->addSql("CREATE INDEX IDX_EA71C468F7B22CC ON lti_token (tool_id)"); + + if ($token->hasColumn('scope')) { + $this->addSql("ALTER TABLE lti_token DROP COLUMN scope"); + } + + $this->addSql("ALTER TABLE lti_token ADD scope JSON NOT NULL COMMENT '(DC2Type:json)'"); + + if ($token->hasColumn('hash')) { + $this->addSql("ALTER TABLE lti_token DROP COLUMN hash"); + } + + $this->addSql("ALTER TABLE lti_token ADD hash VARCHAR(255) NOT NULL"); + + if ($token->hasColumn('created_at')) { + $this->addSql("ALTER TABLE lti_token DROP COLUMN created_at"); + } + + $this->addSql("ALTER TABLE lti_token ADD created_at INT NOT NULL"); + + if ($token->hasColumn('expires_at')) { + $this->addSql("ALTER TABLE lti_token DROP COLUMN expires_at"); + } + + $this->addSql("ALTER TABLE lti_token ADD expires_at INT NOT NULL"); + + $platform = $schema->getTable('lti_platform'); + + if ($token->hasColumn('public_key')) { + $this->addSql("ALTER TABLE lti_platform DROP COLUMN public_key"); + } + + $this->addSql("ALTER TABLE lti_platform ADD public_key LONGTEXT NOT NULL"); + + if ($token->hasColumn('kid')) { + $this->addSql("ALTER TABLE lti_platform DROP COLUMN kid"); + } + + $this->addSql("ALTER TABLE lti_platform ADD kid VARCHAR(255) NOT NULL"); + + if ($token->hasColumn('private_key')) { + $this->addSql("ALTER TABLE lti_platform DROP COLUMN private_key"); + } + + $this->addSql("ALTER TABLE lti_platform ADD private_key LONGTEXT NOT NULL"); + } +} diff --git a/src/LtiBundle/Entity/ExternalTool.php b/src/LtiBundle/Entity/ExternalTool.php index 4aadea45d4f..b855d79ebfb 100644 --- a/src/LtiBundle/Entity/ExternalTool.php +++ b/src/LtiBundle/Entity/ExternalTool.php @@ -7,14 +7,17 @@ namespace Chamilo\LtiBundle\Entity; use Chamilo\CoreBundle\Entity\AbstractResource; -use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\GradebookEvaluation; use Chamilo\CoreBundle\Entity\ResourceInterface; +use Chamilo\CoreBundle\Entity\ResourceLink; +use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\ResourceToRootInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; +use LtiAssignmentGradesService; +use LtiNamesRoleProvisioningService; use Stringable; use UnserializeApi; @@ -25,9 +28,9 @@ class ExternalTool extends AbstractResource implements ResourceInterface, Resour public const V_1P1 = 'lti1p1'; public const V_1P3 = 'lti1p3'; - #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] #[ORM\GeneratedValue] + #[ORM\Column(name: 'id', type: 'integer')] protected ?int $id = null; #[ORM\Column(name: 'title', type: 'string')] @@ -36,6 +39,9 @@ class ExternalTool extends AbstractResource implements ResourceInterface, Resour #[ORM\Column(name: 'description', type: 'text', nullable: true)] protected ?string $description; + #[ORM\Column(name: 'public_key', type: 'text', nullable: true)] + public ?string $publicKey; + #[ORM\Column(name: 'launch_url', type: 'string')] protected string $launchUrl; @@ -54,37 +60,31 @@ class ExternalTool extends AbstractResource implements ResourceInterface, Resour #[ORM\Column(name: 'privacy', type: 'text', nullable: true, options: ['default' => null])] protected ?string $privacy; - #[ORM\ManyToOne(targetEntity: Course::class)] - #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id')] - protected ?Course $course; - #[ORM\ManyToOne(targetEntity: GradebookEvaluation::class)] #[ORM\JoinColumn(name: 'gradebook_eval_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - protected ?GradebookEvaluation $gradebookEval; - - #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] - #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')] - protected ?ExternalTool $parent; - - #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected Collection $children; + private ?GradebookEvaluation $gradebookEval; #[ORM\Column(name: 'client_id', type: 'string', nullable: true)] - private ?string $clientId = null; + private ?string $clientId; + #[ORM\Column(name: 'login_url', type: 'string', nullable: true)] - private ?string $loginUrl = null; + private ?string $loginUrl; #[ORM\Column(name: 'redirect_url', type: 'string', nullable: true)] - private ?string $redirectUrl = null; + private ?string $redirectUrl; + + #[ORM\Column(name: 'jwks_url', type: 'string', nullable: true)] + private ?string $jwksUrl; #[ORM\Column(name: 'advantage_services', type: 'json', nullable: true)] private ?array $advantageServices; - #[ORM\OneToMany(targetEntity: LineItem::class, mappedBy: 'tool')] + #[ORM\OneToMany(mappedBy: 'tool', targetEntity: LineItem::class)] private Collection $lineItems; - #[ORM\Column(name: 'version', type: 'string', options: ['default' => 'lti1p1'])] + #[ORM\Column(name: 'version', type: 'string', options: ['default' => self::V_1P3])] private string $version; + #[ORM\Column(name: 'launch_presentation', type: 'json')] private array $launchPresentation; @@ -96,17 +96,12 @@ public function __construct() $this->description = null; $this->customParams = null; $this->activeDeepLinking = false; - $this->course = null; $this->gradebookEval = null; $this->privacy = null; $this->consumerKey = null; $this->sharedSecret = null; - $this->parent = null; - $this->children = new ArrayCollection(); - $this->consumerKey = null; - $this->sharedSecret = null; $this->lineItems = new ArrayCollection(); - $this->version = self::V_1P1; + $this->version = self::V_1P3; $this->launchPresentation = [ 'document_target' => 'iframe', ]; @@ -118,7 +113,7 @@ public function __toString(): string return $this->getTitle(); } - public function getId(): int + public function getId(): ?int { return $this->id; } @@ -173,7 +168,9 @@ public function setCustomParams(?string $customParams): static public function isGlobal(): bool { - return null === $this->course; + $resourceNode = $this->resourceNode->getResourceLinks()->first(); + + return !$resourceNode; } public function encodeCustomParams(array $params): ?string @@ -245,18 +242,6 @@ public function setActiveDeepLinking(bool $activeDeepLinking): static return $this; } - public function getCourse(): ?Course - { - return $this->course; - } - - public function setCourse(?Course $course = null): static - { - $this->course = $course; - - return $this; - } - public function getGradebookEval(): ?GradebookEvaluation { return $this->gradebookEval; @@ -328,7 +313,7 @@ public function getToolParent(): ?self public function setToolParent(self $parent): static { - $this->parent = $parent; + $this->resourceNode->setParent($parent->getResourceNode()); $this->sharedSecret = $parent->getSharedSecret(); $this->consumerKey = $parent->getConsumerKey(); $this->privacy = $parent->getPrivacy(); @@ -336,18 +321,6 @@ public function setToolParent(self $parent): static return $this; } - public function getChildren(): Collection - { - return $this->children; - } - - public function setChildren(Collection $children): static - { - $this->children = $children; - - return $this; - } - public function getSharedSecret(): ?string { return $this->sharedSecret; @@ -389,6 +362,18 @@ public function getRedirectUrl(): ?string return $this->redirectUrl; } + public function getJwksUrl(): ?string + { + return $this->jwksUrl; + } + + public function setJwksUrl(?string $jwksUrl): static + { + $this->jwksUrl = $jwksUrl; + + return $this; + } + public function setRedirectUrl(?string $redirectUrl): static { $this->redirectUrl = $redirectUrl; @@ -506,7 +491,7 @@ public function setDocumenTarget(string $target): static return $this; } - public function getDocumentTarget() + public function getDocumentTarget(): string { return $this->launchPresentation['document_target'] ?: 'iframe'; } @@ -532,10 +517,13 @@ public function getReplacementForUserId(): ?string return null; } + // @TODO: move it to repository public function getChildrenInCourses(array $coursesId): Collection { - return $this->children->filter( - fn (self $child) => \in_array($child->getCourse()->getId(), $coursesId, true) + return $this->resourceNode->getChildren()->filter( + fn(ResourceNode $child) => $child->getResourceLinks()->exists( + fn(ResourceLink $link) => ($course = $link->getCourse()) && in_array($course->getId(), $coursesId) + ) ); } @@ -544,9 +532,9 @@ public function getResourceName(): string return $this->getTitle(); } - public function setResourceName(string $title): static + public function setResourceName(string $name): static { - return $this->setTitle($title); + return $this->setTitle($name); } public function getResourceIdentifier(): int diff --git a/src/LtiBundle/Entity/LineItem.php b/src/LtiBundle/Entity/LineItem.php index a654cf45b7f..d1e143d1906 100644 --- a/src/LtiBundle/Entity/LineItem.php +++ b/src/LtiBundle/Entity/LineItem.php @@ -19,22 +19,28 @@ class LineItem #[ORM\Id] #[ORM\GeneratedValue] protected ?int $id = null; + #[ORM\ManyToOne(targetEntity: ExternalTool::class, inversedBy: 'lineItems')] #[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] private ExternalTool $tool; + #[ORM\OneToOne(targetEntity: GradebookEvaluation::class)] #[ORM\JoinColumn(name: 'evaluation', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] private GradebookEvaluation $evaluation; + #[ORM\Column(name: 'resource_id', type: 'string', nullable: true)] - private string $resourceId; + private ?string $resourceId; + #[ORM\Column(name: 'tag', type: 'string', nullable: true)] - private string $tag; + private ?string $tag; + #[ORM\Column(name: 'start_date', type: 'datetime', nullable: true)] - private DateTime $startDate; + private ?DateTime $startDate; + #[ORM\Column(name: 'end_date', type: 'datetime', nullable: true)] - private DateTime $endDate; + private ?DateTime $endDate; - public function getId(): int + public function getId(): ?int { return $this->id; } diff --git a/src/LtiBundle/Entity/Platform.php b/src/LtiBundle/Entity/Platform.php index 510b68752d1..5c5701956ba 100644 --- a/src/LtiBundle/Entity/Platform.php +++ b/src/LtiBundle/Entity/Platform.php @@ -12,18 +12,21 @@ #[ORM\Entity] class Platform { - #[ORM\Column(name: 'public_key', type: 'text')] - public string $publicKey; #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] #[ORM\GeneratedValue] protected ?int $id = null; + + #[ORM\Column(name: 'public_key', type: 'text')] + public string $publicKey; + #[ORM\Column(name: 'kid', type: 'string')] private string $kid; + #[ORM\Column(name: 'private_key', type: 'text')] private string $privateKey; - public function getId(): int + public function getId(): ?int { return $this->id; } diff --git a/src/LtiBundle/Entity/Token.php b/src/LtiBundle/Entity/Token.php index 4c45edd2462..9e8e4a7714c 100644 --- a/src/LtiBundle/Entity/Token.php +++ b/src/LtiBundle/Entity/Token.php @@ -18,29 +18,34 @@ class Token #[ORM\Id] #[ORM\GeneratedValue] protected ?int $id = null; + #[ORM\ManyToOne(targetEntity: ExternalTool::class)] #[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', onDelete: 'CASCADE')] - private ExternalTool $tool; + private ?ExternalTool $tool; + #[ORM\Column(name: 'scope', type: 'json')] private array $scope; + #[ORM\Column(name: 'hash', type: 'string')] private string $hash; + #[ORM\Column(name: 'created_at', type: 'integer')] private int $createdAt; + #[ORM\Column(name: 'expires_at', type: 'integer')] private int $expiresAt; - public function getId(): int + public function getId(): ?int { return $this->id; } - public function getTool(): ExternalTool + public function getTool(): ?ExternalTool { return $this->tool; } - public function setTool(ExternalTool $tool): static + public function setTool(?ExternalTool $tool): static { $this->tool = $tool; @@ -102,7 +107,7 @@ public function getScopeInString(): string public function generateHash(): static { - $this->hash = sha1(uniqid((string) random_int(0, mt_getrandmax()))); + $this->hash = sha1(uniqid((string) mt_rand())); return $this; } From 5244017f6fa5201f3ad6ba926240b14ec785ba71 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:29:06 -0500 Subject: [PATCH 2/5] LTI: Update plugin from 1.11.x --- public/plugin/ImsLti/Entity/ImsLtiTool.php | 626 ++++-------------- public/plugin/ImsLti/Entity/LineItem.php | 191 ++---- public/plugin/ImsLti/Entity/Platform.php | 13 +- public/plugin/ImsLti/Entity/Token.php | 9 +- public/plugin/ImsLti/ImsLtiPlugin.php | 29 +- public/plugin/ImsLti/admin.php | 6 +- public/plugin/ImsLti/auth.php | 8 +- public/plugin/ImsLti/configure.php | 6 +- public/plugin/ImsLti/create.php | 12 +- public/plugin/ImsLti/delete.php | 8 +- public/plugin/ImsLti/edit.php | 12 +- public/plugin/ImsLti/form.php | 4 +- .../plugin/ImsLti/gradebook/OutcomeForm.php | 20 +- public/plugin/ImsLti/gradebook/add_eval.php | 17 +- public/plugin/ImsLti/install.php | 2 + public/plugin/ImsLti/item_return.php | 8 +- public/plugin/ImsLti/item_return2.php | 2 +- public/plugin/ImsLti/jwks.php | 2 +- public/plugin/ImsLti/login.php | 2 +- public/plugin/ImsLti/multiply.php | 20 +- public/plugin/ImsLti/multiply_session.php | 20 +- public/plugin/ImsLti/outcome_service.php | 2 +- public/plugin/ImsLti/platform.php | 6 +- public/plugin/ImsLti/session.php | 14 +- .../src/ContentItem/LtiContentItemType.php | 2 +- .../src/ContentItem/LtiResourceLink.php | 2 +- public/plugin/ImsLti/src/Form/FrmAdd.php | 4 +- public/plugin/ImsLti/src/Form/FrmEdit.php | 4 +- public/plugin/ImsLti/src/ImsLti.php | 6 +- .../ImsLti/src/ImsLtiServiceDeleteRequest.php | 2 +- .../ImsLti/src/ImsLtiServiceReadRequest.php | 2 +- .../src/ImsLtiServiceReplaceRequest.php | 2 +- .../ImsLti/src/Request/LtiTokenRequest.php | 4 +- .../src/Service/LtiAdvantageService.php | 2 +- .../Service/LtiAssignmentGradesService.php | 4 +- .../LtiNamesRoleProvisioningService.php | 2 +- .../Resource/LtiAdvantageServiceResource.php | 4 +- .../Resource/LtiContextMembershipResource.php | 2 +- .../Service/Resource/LtiLineItemResource.php | 2 +- .../Service/Resource/LtiLineItemsResource.php | 5 +- .../Service/Resource/LtiResultsResource.php | 2 +- .../Service/Resource/LtiScoresResource.php | 6 +- public/plugin/ImsLti/start.php | 8 +- public/plugin/ImsLti/token.php | 2 +- public/plugin/ImsLti/tool_settings.php | 6 +- public/plugin/ImsLti/uninstall.php | 2 + public/plugin/ImsLti/view/add.tpl | 10 +- public/plugin/ImsLti/view/admin.tpl | 16 +- 48 files changed, 352 insertions(+), 788 deletions(-) diff --git a/public/plugin/ImsLti/Entity/ImsLtiTool.php b/public/plugin/ImsLti/Entity/ImsLtiTool.php index d51b45ac181..9e9df83b538 100644 --- a/public/plugin/ImsLti/Entity/ImsLtiTool.php +++ b/public/plugin/ImsLti/Entity/ImsLtiTool.php @@ -1,4 +1,5 @@ false])] + private bool $activeDeepLinking; + + #[ORM\Column(name: 'privacy', type: 'text', nullable: true, options: ['default' => null])] + private ?string $privacy; + + #[ORM\ManyToOne(targetEntity: Course::class)] + #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id')] + private ?Course $course; + + #[ORM\ManyToOne(targetEntity: Session::class)] + #[ORM\JoinColumn(name: 'session_id', referencedColumnName: 'id')] + private ?Session $session; + + #[ORM\ManyToOne(targetEntity: GradebookEvaluation::class)] + #[ORM\JoinColumn(name: 'gradebook_eval_id', referencedColumnName: 'id', onDelete: 'SET NULL')] + private ?GradebookEvaluation $gradebookEval; + + #[ORM\ManyToOne(targetEntity: ImsLtiTool::class, inversedBy: 'children')] + #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] + private ?ImsLtiTool $parent; + + #[ORM\OneToMany(mappedBy: 'parent', targetEntity: ImsLtiTool::class)] + private Collection $children; + + #[ORM\Column(name: 'client_id', type: 'string', nullable: true)] + private ?string $clientId; + + #[ORM\Column(name: 'login_url', type: 'string', nullable: true)] + private ?string $loginUrl; + + #[ORM\Column(name: 'redirect_url', type: 'string', nullable: true)] + private ?string $redirectUrl; + + #[ORM\Column(name: 'jwks_url', type: 'string', nullable: true)] + private ?string $jwksUrl; + + #[ORM\Column(name: 'advantage_services', type: 'json', nullable: true)] + private ?array $advantageServices; + + #[ORM\OneToMany(mappedBy: 'tool', targetEntity: LineItem::class)] + private Collection $lineItems; + + #[ORM\Column(name: 'version', type: 'string', options: ['default' => 'lti1p1'])] + private string $version; + + #[ORM\Column(name: 'launch_presentation', type: 'json')] + private array $launchPresentation; + + #[ORM\Column(name: 'replacement_params', type: 'json')] + private array $replacementParams; /** * ImsLtiTool constructor. @@ -197,106 +116,65 @@ public function __construct() $this->replacementParams = []; } - /** - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * @param string $name - * - * @return ImsLtiTool - */ - public function setName($name) + public function setName(string $name): static { $this->name = $name; return $this; } - /** - * @return string|null - */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } - /** - * @param string|null $description - * - * @return ImsLtiTool - */ - public function setDescription($description) + public function setDescription(?string $description): static { $this->description = $description; return $this; } - /** - * @return string - */ - public function getLaunchUrl() + public function getLaunchUrl(): string { return $this->launchUrl; } - /** - * @param string $launchUrl - * - * @return ImsLtiTool - */ - public function setLaunchUrl($launchUrl) + public function setLaunchUrl(string $launchUrl): static { $this->launchUrl = $launchUrl; return $this; } - /** - * @return string|null - */ - public function getCustomParams() + public function getCustomParams(): ?string { return $this->customParams; } - /** - * @param string|null $customParams - * - * @return ImsLtiTool - */ - public function setCustomParams($customParams) + public function setCustomParams(?string $customParams): static { $this->customParams = $customParams; return $this; } - /** - * @return bool - */ - public function isGlobal() + public function isGlobal(): bool { return $this->course === null; } - /** - * @return string|null - */ - public function encodeCustomParams(array $params) + public function encodeCustomParams(array $params): ?string { if (empty($params)) { return null; @@ -311,10 +189,7 @@ public function encodeCustomParams(array $params) return implode("\n", $pairs); } - /** - * @return array - */ - public function getCustomParamsAsArray() + public function getCustomParamsAsArray(): array { $params = []; $lines = explode("\n", $this->customParams); @@ -332,10 +207,7 @@ public function getCustomParamsAsArray() return $params; } - /** - * @return array - */ - public function parseCustomParams() + public function parseCustomParams(): array { if (empty($this->customParams)) { return []; @@ -359,113 +231,61 @@ public function parseCustomParams() return $params; } - /** - * Get activeDeepLinking. - * - * @return bool - */ - public function isActiveDeepLinking() + public function isActiveDeepLinking(): bool { return $this->activeDeepLinking; } - /** - * Set activeDeepLinking. - * - * @param bool $activeDeepLinking - * - * @return ImsLtiTool - */ - public function setActiveDeepLinking($activeDeepLinking) + public function setActiveDeepLinking(bool $activeDeepLinking): static { $this->activeDeepLinking = $activeDeepLinking; return $this; } - /** - * Get course. - * - * @return Course|null - */ - public function getCourse() + public function getCourse(): ?Course { return $this->course; } - /** - * Set course. - * - * @return ImsLtiTool - */ - public function setCourse(Course $course = null) + public function setCourse(?Course $course): static { $this->course = $course; return $this; } - /** - * Get session. - * - * @return Session|null - */ - public function getSession() + public function getSession(): ?Session { return $this->session; } - /** - * Set session. - * - * @param Session|null $course - * - * @return ImsLtiTool - */ - public function setSession(Session $session = null) + public function setSession(?Session $session): static { $this->session = $session; return $this; } - /** - * Get gradebookEval. - * - * @return GradebookEvaluation|null - */ - public function getGradebookEval() + public function getGradebookEval(): ?GradebookEvaluation { return $this->gradebookEval; } - /** - * Set gradebookEval. - * - * @param GradebookEvaluation|null $gradebookEval - * - * @return ImsLtiTool - */ - public function setGradebookEval($gradebookEval) + public function setGradebookEval(?GradebookEvaluation $gradebookEval): static { $this->gradebookEval = $gradebookEval; return $this; } - /** - * @return bool - */ - public function isSharingName() + public function isSharingName(): bool { $unserialize = $this->unserializePrivacy(); return (bool) $unserialize['share_name']; } - /** - * @return mixed - */ public function unserializePrivacy() { return \UnserializeApi::unserialize('not_allowed_classes', $this->privacy); @@ -474,35 +294,26 @@ public function unserializePrivacy() /** * @return bool */ - public function isSharingEmail() + public function isSharingEmail(): bool { $unserialize = $this->unserializePrivacy(); return (bool) $unserialize['share_email']; } - /** - * @return bool - */ - public function isSharingPicture() + public function isSharingPicture(): bool { $unserialize = $this->unserializePrivacy(); return (bool) $unserialize['share_picture']; } - /** - * @return ImsLtiTool|null - */ public function getParent() { return $this->parent; } - /** - * @return ImsLtiTool - */ - public function setParent(ImsLtiTool $parent) + public function setParent(ImsLtiTool $parent): static { $this->parent = $parent; @@ -513,67 +324,40 @@ public function setParent(ImsLtiTool $parent) return $this; } - /** - * @return string - */ - public function getSharedSecret() + public function getSharedSecret(): ?string { return $this->sharedSecret; } - /** - * @param string $sharedSecret - * - * @return ImsLtiTool - */ - public function setSharedSecret($sharedSecret) + public function setSharedSecret(?string $sharedSecret): static { $this->sharedSecret = $sharedSecret; return $this; } - /** - * @return string - */ - public function getConsumerKey() + public function getConsumerKey(): ?string { return $this->consumerKey; } - /** - * @param string $consumerKey - * - * @return ImsLtiTool - */ - public function setConsumerKey($consumerKey) + public function setConsumerKey(?string $consumerKey): static { $this->consumerKey = $consumerKey; return $this; } - /** - * Get privacy. - * - * @return string|null - */ - public function getPrivacy() + public function getPrivacy(): ?string { 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 setPrivacy( + bool $shareName = false, + bool $shareEmail = false, + bool $sharePicture = false + ): static { $this->privacy = serialize( [ 'share_name' => $shareName, @@ -585,108 +369,55 @@ public function setPrivacy($shareName = false, $shareEmail = false, $sharePictur return $this; } - /** - * Get loginUrl. - * - * @return string|null - */ - public function getLoginUrl() + public function getLoginUrl(): ?string { return $this->loginUrl; } - /** - * Set loginUrl. - * - * @param string|null $loginUrl - * - * @return ImsLtiTool - */ - public function setLoginUrl($loginUrl) + public function setLoginUrl(?string $loginUrl): static { $this->loginUrl = $loginUrl; return $this; } - /** - * Get redirectUlr. - * - * @return string|null - */ - public function getRedirectUrl() + public function getRedirectUrl(): ?string { return $this->redirectUrl; } - /** - * Set redirectUrl. - * - * @param string|null $redirectUrl - * - * @return ImsLtiTool - */ - public function setRedirectUrl($redirectUrl) + public function setRedirectUrl(?string $redirectUrl): static { $this->redirectUrl = $redirectUrl; return $this; } - /** - * Get jwksUrl. - * - * @return string|null - */ - public function getJwksUrl() + public function getJwksUrl(): ?string { return $this->jwksUrl; } - /** - * Set jwksUrl. - * - * @param string|null $jwksUrl - * - * @return ImsLtiTool - */ - public function setJwksUrl($jwksUrl) + public function setJwksUrl(?string $jwksUrl): static { $this->jwksUrl = $jwksUrl; return $this; } - /** - * Get clientId. - * - * @return string - */ - public function getClientId() + public function getClientId(): ?string { return $this->clientId; } - /** - * Set clientId. - * - * @param string $clientId - * - * @return ImsLtiTool - */ - public function setClientId($clientId) + public function setClientId(?string $clientId): static { $this->clientId = $clientId; return $this; } - /** - * Get advantageServices. - * - * @return array - */ - public function getAdvantageServices() + public function getAdvantageServices(): ?array { if (empty($this->advantageServices)) { $this->advantageServices = []; @@ -701,26 +432,14 @@ public function getAdvantageServices() ); } - /** - * Set advantageServices. - * - * @param array $advantageServices - * - * @return ImsLtiTool - */ - public function setAdvantageServices($advantageServices) + public function setAdvantageServices($advantageServices): static { $this->advantageServices = $advantageServices; return $this; } - /** - * Add LineItem to lineItems. - * - * @return $this - */ - public function addLineItem(LineItem $lineItem) + public function addLineItem(LineItem $lineItem): static { $lineItem->setTool($this); @@ -729,17 +448,13 @@ public function addLineItem(LineItem $lineItem) return $this; } - /** - * @param int $resourceLinkId - * @param int $resourceId - * @param string $tag - * @param int $limit - * @param int $page - * - * @return ArrayCollection - */ - public function getLineItems($resourceLinkId = 0, $resourceId = 0, $tag = '', $limit = 0, $page = 1) - { + public function getLineItems( + int $resourceLinkId = 0, + int $resourceId = 0, + string $tag = '', + int $limit = 0, + int $page = 1 + ): Collection { $criteria = Criteria::create(); if ($resourceLinkId) { @@ -754,9 +469,6 @@ public function getLineItems($resourceLinkId = 0, $resourceId = 0, $tag = '', $l $criteria->andWhere(Criteria::expr()->eq('tag', $tag)); } - $limit = (int) $limit; - $page = (int) $page; - if ($limit > 0) { $criteria->setMaxResults($limit); @@ -768,46 +480,26 @@ public function getLineItems($resourceLinkId = 0, $resourceId = 0, $tag = '', $l return $this->lineItems->matching($criteria); } - /** - * Set lineItems. - * - * @return $this - */ - public function setLineItems(ArrayCollection $lineItems) + public function setLineItems(ArrayCollection $lineItems): static { $this->lineItems = $lineItems; return $this; } - /** - * Get version. - * - * @return string - */ - public function getVersion() + public function getVersion(): string { return $this->version; } - /** - * Set version. - * - * @param string $version - * - * @return ImsLtiTool - */ - public function setVersion($version) + public function setVersion(string $version): static { $this->version = $version; return $this; } - /** - * @return string - */ - public function getVersionName() + public function getVersionName(): string { if (\ImsLti::V_1P1 === $this->version) { return 'LTI 1.0 / 1.1'; @@ -816,58 +508,36 @@ public function getVersionName() return 'LTI 1.3'; } - /** - * @return ArrayCollection - */ - public function getChildren() + public function getChildren(): Collection { return $this->children; } - /** - * @param string $target - * - * @return $this - */ - public function setDocumenTarget($target) + public function setDocumenTarget(string $target): static { $this->launchPresentation['document_target'] = in_array($target, ['iframe', 'window']) ? $target : 'iframe'; return $this; } - /** - * @return string - */ - public function getDocumentTarget() + public function getDocumentTarget(): string { return $this->launchPresentation['document_target'] ?: 'iframe'; } - /** - * @return array - */ - public function getLaunchPresentation() + public function getLaunchPresentation(): array { return $this->launchPresentation; } - /** - * @param string $replacement - * - * @return ImsLtiTool - */ - public function setReplacementForUserId($replacement) + public function setReplacementForUserId(string $replacement): static { $this->replacementParams['user_id'] = $replacement; return $this; } - /** - * @return string|null - */ - public function getReplacementForUserId() + public function getReplacementForUserId(): ?string { if (!empty($this->replacementParams['user_id'])) { return $this->replacementParams['user_id']; @@ -876,10 +546,7 @@ public function getReplacementForUserId() return null; } - /** - * @return ArrayCollection - */ - public function getChildrenInCourses(array $coursesId) + public function getChildrenInCourses(array $coursesId): Collection { return $this->children->filter( function (ImsLtiTool $child) use ($coursesId) { @@ -889,13 +556,9 @@ function (ImsLtiTool $child) use ($coursesId) { } /** - * Map the key from custom param. - * - * @param string $key - * - * @return string + * Map the key from custom params. */ - private static function filterSpecialChars($key) + private static function filterSpecialChars(string $key): string { $newKey = ''; $key = strtolower($key); @@ -916,12 +579,7 @@ private static function filterSpecialChars($key) return $newKey; } - /** - * @param string $value - * - * @return string - */ - private static function filterSpaces($value) + private static function filterSpaces(string $value): string { $newValue = preg_replace('/\s+/', ' ', $value); diff --git a/public/plugin/ImsLti/Entity/LineItem.php b/public/plugin/ImsLti/Entity/LineItem.php index 011007e0eef..e13a926887c 100644 --- a/public/plugin/ImsLti/Entity/LineItem.php +++ b/public/plugin/ImsLti/Entity/LineItem.php @@ -4,234 +4,133 @@ namespace Chamilo\PluginBundle\ImsLti\Entity; use Chamilo\CoreBundle\Entity\GradebookEvaluation; +use DateTime; +use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; -/** - * Class LineItem. - * - * @ORM\Table(name="plugin_ims_lti_lineitem") - * @ORM\Entity() - */ +#[ORM\Table(name: 'plugin_ims_lti_lineitem')] +#[ORM\Entity] class LineItem { - /** - * @var int - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue - */ - protected $id; - /** - * @var ImsLtiTool - * - * @ORM\ManyToOne(targetEntity="Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool", inversedBy="lineItems") - * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") - */ - private $tool; - /** - * @var GradebookEvaluation - * - * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\GradebookEvaluation") - * @ORM\JoinColumn(name="evaluation", referencedColumnName="id", nullable=false, onDelete="CASCADE") - */ - private $evaluation; - /** - * @var string - * - * @ORM\Column(name="resource_id", type="string", nullable=true) - */ - private $resourceId; - /** - * @var string - * - * @ORM\Column(name="tag", type="string", nullable=true) - */ - private $tag; - /** - * @var \DateTime - * - * @ORM\Column(name="start_date", type="datetime", nullable=true) - */ - private $startDate; - /** - * @var \DateTime - * - * @ORM\Column(name="end_date", type="datetime", nullable=true) - */ - private $endDate; - - /** - * Get id. - * - * @return int - */ - public function getId() + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(name: 'id', type: 'integer')] + protected ?int $id = null; + + #[ORM\ManyToOne(targetEntity: ImsLtiTool::class, inversedBy: 'lineItems')] + #[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] + private ImsLtiTool $tool; + + #[ORM\OneToOne(inversedBy: 'lineItems', targetEntity: GradebookEvaluation::class)] + #[ORM\JoinColumn(name: 'evaluation', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] + private GradebookEvaluation $evaluation; + + #[ORM\Column(name: 'resource_id', type: 'string', nullable: true)] + private ?string $resourceId; + + #[ORM\Column(name: 'tag', type: 'string', nullable: true)] + private ?string $tag; + + #[ORM\Column(name: 'start_date', type: 'datetime', nullable: true)] + private ?DateTime $startDate; + #[ORM\Column(name: 'end_date', type: 'datetime', nullable: true)] + private ?DateTime $endDate; + + public function getId(): ?int { return $this->id; } - /** - * Get tool. - * - * @return ImsLtiTool - */ - public function getTool() + public function getTool(): ImsLtiTool { return $this->tool; } - /** - * Set tool. - * - * @param ImsLtiTool $tool - * - * @return LineItem - */ - public function setTool($tool) + public function setTool(ImsLtiTool $tool): static { $this->tool = $tool; return $this; } - /** - * Get evaluation. - * - * @return GradebookEvaluation - */ - public function getEvaluation() + public function getEvaluation(): GradebookEvaluation { return $this->evaluation; } - /** - * Set evaluation. - * - * @param GradebookEvaluation $evaluation - * - * @return LineItem - */ - public function setEvaluation($evaluation) + public function setEvaluation(GradebookEvaluation $evaluation): static { $this->evaluation = $evaluation; return $this; } - /** - * Get tag. - * - * @return string - */ - public function getTag() + public function getTag(): ?string { return $this->tag; } - /** - * Set tag. - * - * @param string $tag - * - * @return LineItem - */ - public function setTag($tag) + public function setTag(?string $tag): static { $this->tag = $tag; return $this; } - /** - * Get startDate. - * - * @return \DateTime - */ - public function getStartDate() + public function getStartDate(): ?DateTime { return $this->startDate; } - /** - * Set startDate. - * - * @param \DateTime $startDate - * - * @return LineItem - */ - public function setStartDate($startDate) + public function setStartDate(?DateTime$startDate): static { $this->startDate = $startDate; return $this; } - /** - * Get endDate. - * - * @return \DateTime - */ - public function getEndDate() + public function getEndDate(): ?DateTime { return $this->endDate; } - /** - * Set endDate. - * - * @param \DateTime $endDate - * - * @return LineItem - */ - public function setEndDate($endDate) + public function setEndDate(?DateTime $endDate): static { $this->endDate = $endDate; return $this; } - /** - * @return string - */ - public function getResourceId() + public function getResourceId(): ?string { return $this->resourceId; } - /** - * @param string $resourceId - * - * @return LineItem - */ - public function setResourceId($resourceId) + public function setResourceId($resourceId): static { $this->resourceId = $resourceId; return $this; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { $baseTool = $this->tool->getParent() ?: $this->tool; $data = [ 'scoreMaximum' => $this->evaluation->getMax(), - 'label' => $this->evaluation->getName(), + 'label' => $this->evaluation->getTitle(), 'tag' => (string) $this->tag, 'resourceLinkId' => (string) $baseTool->getId(), 'resourceId' => (string) $this->resourceId, ]; if ($this->startDate) { - $data['startDateTime'] = $this->startDate->format(\DateTime::ATOM); + $data['startDateTime'] = $this->startDate->format(DateTimeInterface::ATOM); } if ($this->endDate) { - $data['endDateTime'] = $this->endDate->format(\DateTime::ATOM); + $data['endDateTime'] = $this->endDate->format(DateTimeInterface::ATOM); } return $data; diff --git a/public/plugin/ImsLti/Entity/Platform.php b/public/plugin/ImsLti/Entity/Platform.php index c633f4dea6f..3b59f7a05e4 100644 --- a/public/plugin/ImsLti/Entity/Platform.php +++ b/public/plugin/ImsLti/Entity/Platform.php @@ -1,4 +1,5 @@ kid; } - public function setKid(string $kid): void + public function setKid(string $kid): static { $this->kid = $kid; + + return $this; } public function getPrivateKey(): string diff --git a/public/plugin/ImsLti/Entity/Token.php b/public/plugin/ImsLti/Entity/Token.php index a4070253cc2..9172285059a 100644 --- a/public/plugin/ImsLti/Entity/Token.php +++ b/public/plugin/ImsLti/Entity/Token.php @@ -1,4 +1,5 @@ id; } - public function getTool(): ImsLtiTool + public function getTool(): ?ImsLtiTool { return $this->tool; } - public function setTool(ImsLtiTool $tool): static + public function setTool(?ImsLtiTool $tool): static { $this->tool = $tool; diff --git a/public/plugin/ImsLti/ImsLtiPlugin.php b/public/plugin/ImsLti/ImsLtiPlugin.php index aaf0e0a0496..b71d9be6968 100644 --- a/public/plugin/ImsLti/ImsLtiPlugin.php +++ b/public/plugin/ImsLti/ImsLtiPlugin.php @@ -5,11 +5,11 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CourseBundle\Entity\CTool; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; -use Chamilo\PluginBundle\ImsLti\Entity\LineItem; -use Chamilo\PluginBundle\ImsLti\Entity\Platform; -use Chamilo\PluginBundle\ImsLti\Entity\Token; -use Chamilo\CoreBundle\Entity\User; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\LineItem; +use Chamilo\PluginBundle\Entity\ImsLti\Platform; +use Chamilo\PluginBundle\Entity\ImsLti\Token; +use Chamilo\UserBundle\Entity\User; use Doctrine\ORM\Tools\SchemaTool; use Firebase\JWT\JWK; @@ -60,7 +60,7 @@ public static function create() */ public function get_name() { - return 'ImsLti'; + return 'ims_lti'; } /** @@ -133,7 +133,7 @@ public function uninstall() public function findCourseToolByLink(Course $course, ImsLtiTool $ltiTool) { $em = Database::getManager(); - $toolRepo = $em->getRepository(CTool::class); + $toolRepo = $em->getRepository('ChamiloCourseBundle:CTool'); /** @var CTool $cTool */ $cTool = $toolRepo->findOneBy( @@ -620,7 +620,7 @@ protected function getConfigExtraText() $text = $this->get_lang('ImsLtiDescription'); $text .= sprintf( $this->get_lang('ManageToolButton'), - api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php' + api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php' ); return $text; @@ -630,13 +630,12 @@ protected function getConfigExtraText() * Creates the plugin tables on database. * * @throws \Doctrine\ORM\Tools\ToolsException - * @throws \Doctrine\DBAL\Exception */ private function createPluginTables() { $em = Database::getManager(); - if ($em->getConnection()->createSchemaManager()->tablesExist([self::TABLE_TOOL])) { + if ($em->getConnection()->getSchemaManager()->tablesExist([self::TABLE_TOOL])) { return; }; @@ -653,14 +652,12 @@ private function createPluginTables() /** * Drops the plugin tables on database. - * - * @throws \Doctrine\DBAL\Exception */ private function dropPluginTables() { $em = Database::getManager(); - if (!$em->getConnection()->createSchemaManager()->tablesExist([self::TABLE_TOOL])) { + if (!$em->getConnection()->getSchemaManager()->tablesExist([self::TABLE_TOOL])) { return; }; @@ -677,7 +674,7 @@ private function dropPluginTables() private function removeTools() { - $sql = "DELETE FROM c_tool WHERE link LIKE 'ImsLti/start.php%' AND category = 'plugin'"; + $sql = "DELETE FROM c_tool WHERE link LIKE 'ims_lti/start.php%' AND category = 'plugin'"; Database::query($sql); } @@ -688,7 +685,7 @@ private function setCourseSettings() { $button = Display::toolbarButton( $this->get_lang('ConfigureExternalTool'), - api_get_path(WEB_PLUGIN_PATH).'ImsLti/configure.php?'.api_get_cidreq(), + api_get_path(WEB_PLUGIN_PATH).'ims_lti/configure.php?'.api_get_cidreq(), 'cog', 'primary' ); @@ -707,7 +704,7 @@ private function setCourseSettings() */ private static function generateToolLink(ImsLtiTool $tool) { - return 'ImsLti/start.php?id='.$tool->getId(); + return 'ims_lti/start.php?id='.$tool->getId(); } /** diff --git a/public/plugin/ImsLti/admin.php b/public/plugin/ImsLti/admin.php index 90b15654efb..fe1bc4ac798 100644 --- a/public/plugin/ImsLti/admin.php +++ b/public/plugin/ImsLti/admin.php @@ -39,17 +39,17 @@ } } -$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; $htmlHeadXtra[] = api_get_css( - api_get_path(WEB_PLUGIN_PATH).'ImsLti/assets/style.css' + api_get_path(WEB_PLUGIN_PATH).'ims_lti/assets/style.css' ); $template = new Template($plugin->get_title()); $template->assign('tools', $tools); $template->assign('categories', $categoriesGradeBook); -$content = $template->fetch('ImsLti/view/admin.tpl'); +$content = $template->fetch('ims_lti/view/admin.tpl'); $template->assign('header', $plugin->get_title()); $template->assign('content', $content); diff --git a/public/plugin/ImsLti/auth.php b/public/plugin/ImsLti/auth.php index ba63241e092..46f79ac6971 100644 --- a/public/plugin/ImsLti/auth.php +++ b/public/plugin/ImsLti/auth.php @@ -1,8 +1,8 @@ isSharingName()) { - $jwtContent['name'] = $user->getFullName(); + $jwtContent['name'] = $user->getFullname(); $jwtContent['given_name'] = $user->getFirstname(); $jwtContent['family_name'] = $user->getLastname(); } @@ -185,7 +185,7 @@ 'title' => $tool->getName(), 'text' => $tool->getDescription(), 'data' => "tool:{$tool->getId()}", - 'deep_link_return_url' => $webPluginPath.'ImsLti/item_return2.php', + 'deep_link_return_url' => $webPluginPath.'ims_lti/item_return2.php', ]; } else { $jwtContent['https://purl.imsglobal.org/spec/lti/claim/message_type'] = 'LtiResourceLinkRequest'; diff --git a/public/plugin/ImsLti/configure.php b/public/plugin/ImsLti/configure.php index 376588f7d7f..f77071440a9 100644 --- a/public/plugin/ImsLti/configure.php +++ b/public/plugin/ImsLti/configure.php @@ -2,7 +2,7 @@ /* For license terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Course; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; require_once __DIR__.'/../../main/inc/global.inc.php'; @@ -255,7 +255,7 @@ $template->assign('global_tools', $globalTools); $template->assign('form', $form->returnForm()); -$content = $template->fetch('ImsLti/view/add.tpl'); +$content = $template->fetch('ims_lti/view/add.tpl'); $actions = Display::url( Display::return_icon('add.png', $plugin->get_lang('AddExternalTool'), [], ICON_SIZE_MEDIUM), @@ -264,7 +264,7 @@ if (!empty($categories)) { $actions .= Display::url( - Display::return_icon('gradebook.png', get_lang('Add to gradebook'), [], ICON_SIZE_MEDIUM), + Display::return_icon('gradebook.png', get_lang('MakeQualifiable'), [], ICON_SIZE_MEDIUM), './gradebook/add_eval.php?selectcat='.$categories[0]->get_id().'&'.api_get_cidreq() ); } diff --git a/public/plugin/ImsLti/create.php b/public/plugin/ImsLti/create.php index ddd330c866b..7a277b460ec 100644 --- a/public/plugin/ImsLti/create.php +++ b/public/plugin/ImsLti/create.php @@ -1,6 +1,6 @@ getMessage(), 'error') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } @@ -94,21 +94,21 @@ Display::return_message($plugin->get_lang('ToolAdded'), 'success') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } $form->setDefaultValues(); -$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; -$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $pageTitle = $plugin->get_lang('AddExternalTool'); $template = new Template($pageTitle); $template->assign('form', $form->returnForm()); -$content = $template->fetch('ImsLti/view/add.tpl'); +$content = $template->fetch('ims_lti/view/add.tpl'); $template->assign('header', $pageTitle); $template->assign('content', $content); diff --git a/public/plugin/ImsLti/delete.php b/public/plugin/ImsLti/delete.php index c7a83c9d826..1d32240d72b 100644 --- a/public/plugin/ImsLti/delete.php +++ b/public/plugin/ImsLti/delete.php @@ -1,7 +1,7 @@ getId(); +$links[] = 'ims_lti/start.php?id='.$tool->getId(); if (!$tool->getParent()) { /** @var ImsLtiTool $child */ foreach ($tool->getChildren() as $child) { - $links[] = "ImsLti/start.php?id=".$child->getId(); + $links[] = "ims_lti/start.php?id=".$child->getId(); } } @@ -39,5 +39,5 @@ Display::return_message($plugin->get_lang('ToolDeleted'), 'success') ); -header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); +header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; diff --git a/public/plugin/ImsLti/edit.php b/public/plugin/ImsLti/edit.php index 9af94f14940..7e0f709fef4 100644 --- a/public/plugin/ImsLti/edit.php +++ b/public/plugin/ImsLti/edit.php @@ -1,7 +1,7 @@ get_lang('NoTool'), 'error') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } @@ -126,19 +126,19 @@ Display::return_message($plugin->get_lang('ToolEdited'), 'success') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } else { $form->setDefaultValues(); } -$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; -$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $template = new Template($plugin->get_lang('EditExternalTool')); $template->assign('form', $form->returnForm()); -$content = $template->fetch('ImsLti/view/add.tpl'); +$content = $template->fetch('ims_lti/view/add.tpl'); $template->assign('header', $plugin->get_title()); $template->assign('content', $content); diff --git a/public/plugin/ImsLti/form.php b/public/plugin/ImsLti/form.php index eb519887a95..7f0a9bf065f 100644 --- a/public/plugin/ImsLti/form.php +++ b/public/plugin/ImsLti/form.php @@ -1,7 +1,7 @@ build_basic_form(); - $this->addButtonCreate(get_lang('Add this classroom activity to the assessment'), 'submit'); + $this->addButtonCreate(get_lang('AddAssessment'), 'submit'); } /** @@ -67,7 +67,7 @@ private function build_basic_form($edit = 0) $this->addText( 'name', - get_lang('Assessment'), + get_lang('EvaluationName'), true, [ 'maxlength' => '50', @@ -87,11 +87,11 @@ private function build_basic_form($edit = 0) $select_gradebook = $this->addElement( 'select', 'hid_category_id', - get_lang('Select assessment'), + get_lang('SelectGradebook'), [], ['id' => 'hid_category_id'] ); - $this->addRule('hid_category_id', get_lang('Required field'), 'nonzero'); + $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero'); $default_weight = 0; if (!empty($all_categories)) { foreach ($all_categories as $my_cat) { @@ -135,7 +135,7 @@ private function build_basic_form($edit = 0) if (!$this->evaluation_object->has_results()) { $this->addText( 'max', - get_lang('Maximum score'), + get_lang('QualificationNumeric'), true, [ 'maxlength' => '5', @@ -144,7 +144,7 @@ private function build_basic_form($edit = 0) } else { $this->addText( 'max', - [get_lang('Maximum score'), get_lang('Cannot change the score')], + [get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')], false, [ 'maxlength' => '5', @@ -155,7 +155,7 @@ private function build_basic_form($edit = 0) } else { $this->addText( 'max', - get_lang('Maximum score'), + get_lang('QualificationNumeric'), true, [ 'maxlength' => '5', @@ -167,12 +167,12 @@ private function build_basic_form($edit = 0) } $this->addElement('textarea', 'description', get_lang('Description')); - $this->addRule('hid_category_id', get_lang('Required field'), 'required'); + $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required'); $this->addElement('checkbox', 'visible', null, get_lang('Visible')); - $this->addRule('max', get_lang('Only numbers'), 'numeric'); + $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); $this->addRule( 'max', - get_lang('Negative value'), + get_lang('NegativeValue'), 'compare', '>=', 'server', diff --git a/public/plugin/ImsLti/gradebook/add_eval.php b/public/plugin/ImsLti/gradebook/add_eval.php index 102954b4512..b360ae4fdba 100644 --- a/public/plugin/ImsLti/gradebook/add_eval.php +++ b/public/plugin/ImsLti/gradebook/add_eval.php @@ -1,9 +1,12 @@ find(Course::class, api_get_course_int_id()); +/** @var \Chamilo\CoreBundle\Entity\Course $course */ +$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); $ltiToolRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool'); $categories = Category::load(null, null, $course->getCode(), null, null, $sessionId); @@ -56,7 +59,7 @@ $form->removeElement('addresult'); $slcLtiTools = $form->createElement('select', 'name', get_lang('Tool')); $form->insertElementBefore($slcLtiTools, 'hid_category_id'); -$form->addRule('name', get_lang('Required field'), 'required'); +$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); $ltiTools = $ltiToolRepo->findBy(['course' => $course, 'gradebookEval' => null]); @@ -99,7 +102,7 @@ $eval->add(); /** @var GradebookEvaluation $gradebookEval */ - $gradebookEval = $em->find(GradebookEvaluation::class, $eval->get_id()); + $gradebookEval = $em->find('ChamiloCoreBundle:GradebookEvaluation', $eval->get_id()); $ltiTool->setGradebookEval($gradebookEval); $em->persist($ltiTool); @@ -135,7 +138,7 @@ }); '; -Display::display_header(get_lang('Add classroom activity')); +Display::display_header(get_lang('NewEvaluation')); $form->display(); diff --git a/public/plugin/ImsLti/install.php b/public/plugin/ImsLti/install.php index 8bdf7cb6842..fddf295c7df 100644 --- a/public/plugin/ImsLti/install.php +++ b/public/plugin/ImsLti/install.php @@ -3,6 +3,8 @@ /** * Install the MSI/LTI Plugin. + * + * @package chamilo.plugin.ims_lti */ if (!api_is_platform_admin()) { exit('You must have admin permissions to install plugins'); diff --git a/public/plugin/ImsLti/item_return.php b/public/plugin/ImsLti/item_return.php index 9b4dfac3df2..a62b241aa15 100644 --- a/public/plugin/ImsLti/item_return.php +++ b/public/plugin/ImsLti/item_return.php @@ -2,7 +2,7 @@ /* For license terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Course; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; require_once __DIR__.'/../../main/inc/global.inc.php'; @@ -18,7 +18,7 @@ $plugin = ImsLtiPlugin::create(); $em = Database::getManager(); /** @var Course $course */ -$course = $em->find(Course::class, api_get_course_int_id()); +$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); /** @var ImsLtiTool|null $ltiTool */ $ltiTool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $toolId); @@ -32,7 +32,7 @@ ); $hmacMethod = new OAuthSignatureMethod_HMAC_SHA1(); -$request = OAuthRequest::from_request('POST', api_get_path(WEB_PLUGIN_PATH).'ImsLti/item_return.php'); +$request = OAuthRequest::from_request('POST', api_get_path(WEB_PLUGIN_PATH).'ims_lti/item_return.php'); $request->sign_request($hmacMethod, $consumer, ''); $signature = $request->get_parameter('oauth_signature'); @@ -55,7 +55,7 @@ } } -$currentUrl = api_get_path(WEB_PLUGIN_PATH).'ImsLti/start.php?id='.$ltiTool->getId(); +$currentUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/start.php?id='.$ltiTool->getId(); ?> diff --git a/public/plugin/ImsLti/item_return2.php b/public/plugin/ImsLti/item_return2.php index bca3a92df68..03ac5e6b978 100644 --- a/public/plugin/ImsLti/item_return2.php +++ b/public/plugin/ImsLti/item_return2.php @@ -1,7 +1,7 @@ get('enabled') !== 'true') { - throw new Exception(get_lang('You are not allowed to see this page. Either your connection has expired or you are trying to access a page for which you do not have the sufficient privileges.')); + throw new Exception(get_lang('NotAllowed')); } $request = Request::createFromGlobals(); @@ -54,7 +54,7 @@ ['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course', 'multiple' => true] ); $form->addCheckBox('all_courses', '', $plugin->get_lang('AddInAllCourses')); - $form->addCheckBox('tool_visible', get_lang('SetVisible'), get_lang('The tool is now visible.')); + $form->addCheckBox('tool_visible', get_lang('SetVisible'), get_lang('ToolIsNowVisible')); $form->addButtonExport(get_lang('Save')); if ($form->validate()) { @@ -76,7 +76,7 @@ /** @var ImsLtiTool $childInCourse */ foreach ($tool->getChildrenInCourses($courseIdsToDelete) as $childInCourse) { - $toolLinks[] = "ImsLti/start.php?id={$childInCourse->getId()}"; + $toolLinks[] = "ims_lti/start.php?id={$childInCourse->getId()}"; $em->remove($childInCourse); } @@ -116,10 +116,10 @@ } Display::addFlash( - Display::return_message(get_lang('Item updated')) + Display::return_message(get_lang('ItemUpdated')) ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } @@ -133,8 +133,8 @@ $content = $form->returnForm(); - $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; - $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $template = new Template($plugin->get_lang('AddInCourses')); $template->assign('header', $plugin->get_lang('AddInCourses')); @@ -145,5 +145,5 @@ Display::return_message($exception->getMessage(), 'error') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); } diff --git a/public/plugin/ImsLti/multiply_session.php b/public/plugin/ImsLti/multiply_session.php index e72a937c2e0..30cbc5ffa2e 100644 --- a/public/plugin/ImsLti/multiply_session.php +++ b/public/plugin/ImsLti/multiply_session.php @@ -1,7 +1,7 @@ get('enabled') !== 'true') { - throw new Exception(get_lang('You are not allowed to see this page. Either your connection has expired or you are trying to access a page for which you do not have the sufficient privileges.')); + throw new Exception(get_lang('NotAllowed')); } $request = Request::createFromGlobals(); @@ -55,7 +55,7 @@ $selectedCoursesIds = array_keys($slctCourses); $form = new FormValidator('frm_multiply', 'post', api_get_self().'?id='.$tool->getId().'&session_id='.$sessionId); - $form->addLabel(get_lang('Session name'), $session); + $form->addLabel(get_lang('SessionName'), $session); $form->addLabel($plugin->get_lang('Tool'), $tool->getName()); $form->addSelectAjax( 'courses', @@ -88,7 +88,7 @@ /** @var ImsLtiTool $childInCourse */ foreach ($tool->getChildrenInCourses($courseIdsToDelete) as $childInCourse) { - $toolLinks[] = "ImsLti/start.php?id={$childInCourse->getId()}"; + $toolLinks[] = "ims_lti/start.php?id={$childInCourse->getId()}"; $em->remove($childInCourse); } @@ -130,10 +130,10 @@ } Display::addFlash( - Display::return_message(get_lang('Item updated')) + Display::return_message(get_lang('ItemUpdated')) ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); exit; } @@ -147,8 +147,8 @@ $content = $form->returnForm(); - $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; - $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $template = new Template($plugin->get_lang('AddInCourses')); $template->assign('header', $plugin->get_lang('AddInCourses')); @@ -159,5 +159,5 @@ Display::return_message($exception->getMessage(), 'error') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); } diff --git a/public/plugin/ImsLti/outcome_service.php b/public/plugin/ImsLti/outcome_service.php index 8db406ac500..0f5b0bb8440 100644 --- a/public/plugin/ImsLti/outcome_service.php +++ b/public/plugin/ImsLti/outcome_service.php @@ -1,7 +1,7 @@ updateCellAttributes(1, 1, ['style' => 'font-family: monospace; font-size: 10px;']); $table->updateCellAttributes(1, 2, ['style' => 'font-family: monospace; font-size: 10px;']); -$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; -$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; +$interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $template = new Template($plugin->get_lang('PlatformKeys')); $template->assign('header', $plugin->get_lang('PlatformKeys')); diff --git a/public/plugin/ImsLti/session.php b/public/plugin/ImsLti/session.php index 0975834fc14..c4c659a57a7 100644 --- a/public/plugin/ImsLti/session.php +++ b/public/plugin/ImsLti/session.php @@ -1,7 +1,7 @@ query->getInt('id'); @@ -20,7 +20,7 @@ try { if ($plugin->get('enabled') !== 'true') { - throw new Exception(get_lang('You are not allowed here.')); + throw new Exception(get_lang('NotAllowed')); } /** @var ImsLtiTool $tool */ @@ -66,7 +66,7 @@ exit; } - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/multiply_session.php?id='.$formValues['tool_id'].'&session_id='.$formValues['sessions']); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/multiply_session.php?id='.$formValues['tool_id'].'&session_id='.$formValues['sessions']); exit; } @@ -75,8 +75,8 @@ $content = $form->returnForm(); - $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('Administration')]; - $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php', 'name' => $plugin->get_title()]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; + $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; $template = new Template($plugin->get_lang('AddInSessions')); $template->assign('header', $plugin->get_lang('AddInSessions')); @@ -87,5 +87,5 @@ Display::return_message($exception->getMessage(), 'error') ); - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ImsLti/admin.php'); + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); } diff --git a/public/plugin/ImsLti/src/ContentItem/LtiContentItemType.php b/public/plugin/ImsLti/src/ContentItem/LtiContentItemType.php index 057e1eb9e13..1cea6138255 100644 --- a/public/plugin/ImsLti/src/ContentItem/LtiContentItemType.php +++ b/public/plugin/ImsLti/src/ContentItem/LtiContentItemType.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Course; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; /** * Class LtiContentItemType. diff --git a/public/plugin/ImsLti/src/ContentItem/LtiResourceLink.php b/public/plugin/ImsLti/src/ContentItem/LtiResourceLink.php index fb448e9aab4..9745107ab24 100644 --- a/public/plugin/ImsLti/src/ContentItem/LtiResourceLink.php +++ b/public/plugin/ImsLti/src/ContentItem/LtiResourceLink.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Course; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; /** * Class LtiContentItem. diff --git a/public/plugin/ImsLti/src/Form/FrmAdd.php b/public/plugin/ImsLti/src/Form/FrmAdd.php index 1dae58dfbf2..bfc13974463 100644 --- a/public/plugin/ImsLti/src/Form/FrmAdd.php +++ b/public/plugin/ImsLti/src/Form/FrmAdd.php @@ -4,7 +4,7 @@ namespace Chamilo\PluginBundle\ImsLti\Form; use Category; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; use Display; use FormValidator; use ImsLti; @@ -104,7 +104,7 @@ public function build() ); $this->addSelect( 'document_target', - get_lang("Link's target"), + get_lang('LinkTarget'), ['iframe' => 'iframe', 'window' => 'window'] ); diff --git a/public/plugin/ImsLti/src/Form/FrmEdit.php b/public/plugin/ImsLti/src/Form/FrmEdit.php index 90572c9881a..541efa71de1 100644 --- a/public/plugin/ImsLti/src/Form/FrmEdit.php +++ b/public/plugin/ImsLti/src/Form/FrmEdit.php @@ -4,7 +4,7 @@ namespace Chamilo\PluginBundle\Form; use Category; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; use Display; use Exception; use FormValidator; @@ -105,7 +105,7 @@ public function build($globalMode = true) ); $this->addSelect( 'document_target', - get_lang("Link's target"), + get_lang('LinkTarget'), ['iframe' => 'iframe', 'window' => 'window'] ); diff --git a/public/plugin/ImsLti/src/ImsLti.php b/public/plugin/ImsLti/src/ImsLti.php index 5dae928c52b..93d9395b401 100644 --- a/public/plugin/ImsLti/src/ImsLti.php +++ b/public/plugin/ImsLti/src/ImsLti.php @@ -3,8 +3,8 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; -use Chamilo\PluginBundle\ImsLti\Entity\ImsLtiTool; -use Chamilo\CoreBundle\Entity\User; +use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; +use Chamilo\UserBundle\Entity\User; /** * Class ImsLti. @@ -43,7 +43,7 @@ public static function getSubstitutableVariables( '$Person.sourcedId' => $isLti1p3 ? self::getPersonSourcedId($domain, $user) : "$domain:".ImsLtiPlugin::getLaunchUserIdClaim($tool, $user), - '$Person.name.full' => $user->getFullName(), + '$Person.name.full' => $user->getFullname(), '$Person.name.family' => $user->getLastname(), '$Person.name.given' => $user->getFirstname(), '$Person.address.street1' => $user->getAddress(), diff --git a/public/plugin/ImsLti/src/ImsLtiServiceDeleteRequest.php b/public/plugin/ImsLti/src/ImsLtiServiceDeleteRequest.php index ea84961deda..0cd180f8844 100644 --- a/public/plugin/ImsLti/src/ImsLtiServiceDeleteRequest.php +++ b/public/plugin/ImsLti/src/ImsLtiServiceDeleteRequest.php @@ -38,7 +38,7 @@ protected function processBody() $em = Database::getManager(); /** @var GradebookEvaluation $evaluation */ - $evaluation = $em->find(GradebookEvaluation::class, $sourcedParts['e']); + $evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts['e']); /** @var User $user */ $user = $em->find('ChamiloUserBundle:User', $sourcedParts['u']); diff --git a/public/plugin/ImsLti/src/ImsLtiServiceReadRequest.php b/public/plugin/ImsLti/src/ImsLtiServiceReadRequest.php index 8cd00b03094..83aff51e24f 100644 --- a/public/plugin/ImsLti/src/ImsLtiServiceReadRequest.php +++ b/public/plugin/ImsLti/src/ImsLtiServiceReadRequest.php @@ -38,7 +38,7 @@ protected function processBody() $em = Database::getManager(); /** @var GradebookEvaluation $evaluation */ - $evaluation = $em->find(GradebookEvaluation::class, $sourcedParts['e']); + $evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts['e']); /** @var User $user */ $user = $em->find('ChamiloUserBundle:User', $sourcedParts['u']); diff --git a/public/plugin/ImsLti/src/ImsLtiServiceReplaceRequest.php b/public/plugin/ImsLti/src/ImsLtiServiceReplaceRequest.php index 88ac913ec54..b9a09041696 100644 --- a/public/plugin/ImsLti/src/ImsLtiServiceReplaceRequest.php +++ b/public/plugin/ImsLti/src/ImsLtiServiceReplaceRequest.php @@ -57,7 +57,7 @@ protected function processBody() $em = Database::getManager(); /** @var GradebookEvaluation $evaluation */ - $evaluation = $em->find(GradebookEvaluation::class, $sourcedParts['e']); + $evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts['e']); /** @var User $user */ $user = $em->find('ChamiloUserBundle:User', $sourcedParts['u']); diff --git a/public/plugin/ImsLti/src/Request/LtiTokenRequest.php b/public/plugin/ImsLti/src/Request/LtiTokenRequest.php index 116d0c974ca..ece5d023965 100644 --- a/public/plugin/ImsLti/src/Request/LtiTokenRequest.php +++ b/public/plugin/ImsLti/src/Request/LtiTokenRequest.php @@ -1,8 +1,8 @@ api_get_path(WEB_PLUGIN_PATH) - ."ImsLti/nrps2.php/{$this->course->getId()}/memberships?" + ."ims_lti/nrps2.php/{$this->course->getId()}/memberships?" .http_build_query( [ 't' => $this->tool->getId(), diff --git a/public/plugin/ImsLti/src/Service/Resource/LtiLineItemResource.php b/public/plugin/ImsLti/src/Service/Resource/LtiLineItemResource.php index 6e21e89b0c1..47120842d26 100644 --- a/public/plugin/ImsLti/src/Service/Resource/LtiLineItemResource.php +++ b/public/plugin/ImsLti/src/Service/Resource/LtiLineItemResource.php @@ -1,7 +1,7 @@ set_visible(1); $eval->add(); - $evaluation = $em->find(GradebookEvaluation::class, $eval->get_id()); + $evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $eval->get_id()); $lineItem = new LineItem(); $lineItem diff --git a/public/plugin/ImsLti/src/Service/Resource/LtiResultsResource.php b/public/plugin/ImsLti/src/Service/Resource/LtiResultsResource.php index ab541631e63..76be91cbb8e 100644 --- a/public/plugin/ImsLti/src/Service/Resource/LtiResultsResource.php +++ b/public/plugin/ImsLti/src/Service/Resource/LtiResultsResource.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\GradebookResult; -use Chamilo\PluginBundle\ImsLti\Entity\LineItem; +use Chamilo\PluginBundle\Entity\ImsLti\LineItem; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; use Doctrine\ORM\TransactionRequiredException; diff --git a/public/plugin/ImsLti/src/Service/Resource/LtiScoresResource.php b/public/plugin/ImsLti/src/Service/Resource/LtiScoresResource.php index d910fd4e365..99631ae9d19 100644 --- a/public/plugin/ImsLti/src/Service/Resource/LtiScoresResource.php +++ b/public/plugin/ImsLti/src/Service/Resource/LtiScoresResource.php @@ -3,8 +3,8 @@ use Chamilo\CoreBundle\Entity\GradebookResult; use Chamilo\CoreBundle\Entity\GradebookResultLog; -use Chamilo\PluginBundle\ImsLti\Entity\LineItem; -use Chamilo\CoreBundle\Entity\User; +use Chamilo\PluginBundle\Entity\ImsLti\LineItem; +use Chamilo\UserBundle\Entity\User; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; use Doctrine\ORM\TransactionRequiredException; @@ -144,7 +144,7 @@ private function processPost() $evaluation = $this->lineItem->getEvaluation(); $result = Database::getManager() - ->getRepository(GradebookResult::class) + ->getRepository('ChamiloCoreBundle:GradebookResult') ->findOneBy( [ 'userId' => $data['userId'], diff --git a/public/plugin/ImsLti/start.php b/public/plugin/ImsLti/start.php index e7d4081676d..dd0efdae72b 100644 --- a/public/plugin/ImsLti/start.php +++ b/public/plugin/ImsLti/start.php @@ -1,7 +1,7 @@ getLoginUrl()) && !empty($tool->getRedirectUrl()); if ($is1p3) { - $launchUrl = api_get_path(WEB_PLUGIN_PATH).'ImsLti/login.php?id='.$tool->getId(); + $launchUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/login.php?id='.$tool->getId(); } else { - $launchUrl = api_get_path(WEB_PLUGIN_PATH).'ImsLti/form.php?'.http_build_query(['id' => $tool->getId()]); + $launchUrl = api_get_path(WEB_PLUGIN_PATH).'ims_lti/form.php?'.http_build_query(['id' => $tool->getId()]); } if ($tool->getDocumentTarget() == 'window') { @@ -43,7 +43,7 @@ $template->assign('launch_url', $launchUrl); -$content = $template->fetch('ImsLti/view/start.tpl'); +$content = $template->fetch('ims_lti/view/start.tpl'); $template->assign('header', $pageTitle); $template->assign('content', $content); diff --git a/public/plugin/ImsLti/token.php b/public/plugin/ImsLti/token.php index 204effff2d3..51e5815ad94 100644 --- a/public/plugin/ImsLti/token.php +++ b/public/plugin/ImsLti/token.php @@ -1,7 +1,7 @@ get('enabled') !== 'true') { - throw new Exception(get_lang('Not allowed')); + throw new Exception(get_lang('Forbidden')); } /** @var ImsLtiTool $tool */ diff --git a/public/plugin/ImsLti/uninstall.php b/public/plugin/ImsLti/uninstall.php index 1dfbe91519a..1fb7c91e449 100644 --- a/public/plugin/ImsLti/uninstall.php +++ b/public/plugin/ImsLti/uninstall.php @@ -3,6 +3,8 @@ /** * Uninstall the MSI/LTI Plugin. + * + * @package chamilo.plugin.ims_lti */ if (!api_is_platform_admin()) { exit('You must have admin permissions to uninstall plugins'); diff --git a/public/plugin/ImsLti/view/add.tpl b/public/plugin/ImsLti/view/add.tpl index 5ccbe0feea8..3be9103f824 100644 --- a/public/plugin/ImsLti/view/add.tpl +++ b/public/plugin/ImsLti/view/add.tpl @@ -11,19 +11,19 @@