Browse Source

Merge remote-tracking branch 'origin/1.11.x' into 1.11.x

Yannick Warnier 6 years ago
parent
commit
6d230e6f23

+ 42 - 19
plugin/ims_lti/Entity/ImsLtiTool.php

@@ -5,6 +5,7 @@ namespace Chamilo\PluginBundle\Entity\ImsLti;
 
 use Chamilo\CoreBundle\Entity\Course;
 use Chamilo\CoreBundle\Entity\GradebookEvaluation;
+use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 
 /**
@@ -59,12 +60,6 @@ class ImsLtiTool
      * @ORM\Column(name="custom_params", type="text", nullable=true)
      */
     private $customParams = null;
-    /**
-     * @var bool
-     *
-     * @ORM\Column(name="is_global", type="boolean")
-     */
-    private $isGlobal = false;
     /**
      * @var bool
      *
@@ -95,6 +90,21 @@ class ImsLtiTool
      */
     private $gradebookEval = null;
 
+    /**
+     * @var ImsLtiTool|null
+     *
+     * @ORM\ManyToOne(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", inversedBy="children")
+     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
+     */
+    private $parent;
+
+    /**
+     * @var ArrayCollection
+     *
+     * @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent")
+     */
+    private $children;
+
     /**
      * ImsLtiTool constructor.
      */
@@ -102,11 +112,11 @@ class ImsLtiTool
     {
         $this->description = null;
         $this->customParams = null;
-        $this->isGlobal = false;
         $this->activeDeepLinking = false;
         $this->course = null;
         $this->gradebookEval =null;
         $this->privacy = null;
+        $this->children = new ArrayCollection();
     }
 
     /**
@@ -236,18 +246,7 @@ class ImsLtiTool
      */
     public function isGlobal()
     {
-        return $this->isGlobal;
-    }
-
-    /**
-     * @param bool $isGlobal
-     * @return ImsLtiTool
-     */
-    public function setIsGlobal($isGlobal)
-    {
-        $this->isGlobal = $isGlobal;
-
-        return $this;
+        return $this->course === null;
     }
 
     /**
@@ -405,4 +404,28 @@ class ImsLtiTool
     {
         return unserialize($this->privacy);
     }
+
+    /**
+     * @return ImsLtiTool|null
+     */
+    public function getParent()
+    {
+        return $this->parent;
+    }
+
+    /**
+     * @param ImsLtiTool $parent
+     *
+     * @return ImsLtiTool
+     */
+    public function setParent(ImsLtiTool $parent)
+    {
+        $this->parent = $parent;
+
+        $this->sharedSecret = $parent->getSharedSecret();
+        $this->consumerKey = $parent->getConsumerKey();
+        $this->privacy = $parent->getPrivacy();
+
+        return $this;
+    }
 }

+ 45 - 51
plugin/ims_lti/ImsLtiPlugin.php

@@ -105,55 +105,47 @@ class ImsLtiPlugin extends Plugin
      * Creates the plugin tables on database
      *
      * @return boolean
+     * @throws DBALException
      */
     private function createPluginTables()
     {
         $entityManager = Database::getManager();
         $connection = $entityManager->getConnection();
-        $pluginSchema = new Schema();
-        $platform = $connection->getDatabasePlatform();
-        if (!$connection->getSchemaManager()->tablesExist(self::TABLE_TOOL)) {
-            $toolTable = $pluginSchema->createTable(self::TABLE_TOOL);
-            $toolTable->addColumn(
-                'id',
-                \Doctrine\DBAL\Types\Type::INTEGER,
-                ['autoincrement' => true, 'unsigned' => true]
-            );
-            $toolTable->addColumn('name', Type::STRING);
-            $toolTable->addColumn('description', Type::TEXT)->setNotnull(false);
-            $toolTable->addColumn('launch_url', Type::TEXT);
-            $toolTable->addColumn('consumer_key', Type::STRING);
-            $toolTable->addColumn('shared_secret', Type::STRING);
-            $toolTable->addColumn('custom_params', Type::TEXT)->setNotnull(false);
-            $toolTable->addColumn('is_global', Type::BOOLEAN);
-            $toolTable->addColumn('active_deep_linking', Type::BOOLEAN)->setDefault(false);
-            $toolTable->addColumn('c_id', Type::INTEGER)->setNotnull(false);
-            $toolTable->addColumn('gradebook_eval_id', Type::INTEGER)->setNotnull(false);
-            $toolTable->addForeignKeyConstraint(
-                'course',
-                ['c_id'],
-                ['id'],
-                [],
-                'FK_C5E47F7C91D79BD3'
-            );
-            $toolTable->addForeignKeyConstraint(
-                'gradebook_evaluation',
-                ['gradebook_eval_id'],
-                ['id'],
-                ['onDelete' => 'SET NULL'],
-                'FK_C5E47F7C82F80D8B'
-            );
-            $toolTable->setPrimaryKey(['id']);
-            $toolTable->addIndex(['c_id'], 'IDX_C5E47F7C91D79BD3');
-            $toolTable->addIndex(['gradebook_eval_id'], 'IDX_C5E47F7C82F80D8B');
 
-            $queries = $pluginSchema->toSql($platform);
-
-            foreach ($queries as $query) {
-                Database::query($query);
-            }
+        if ($connection->getSchemaManager()->tablesExist(self::TABLE_TOOL)) {
+            return true;
         }
 
+        $queries = [
+            'CREATE TABLE '.self::TABLE_TOOL.' (
+                id INT AUTO_INCREMENT NOT NULL,
+                c_id INT DEFAULT NULL,
+                gradebook_eval_id INT DEFAULT NULL,
+                parent_id INT DEFAULT NULL,
+                name VARCHAR(255) NOT NULL,
+                description LONGTEXT DEFAULT NULL,
+                launch_url VARCHAR(255) NOT NULL,
+                consumer_key VARCHAR(255) NOT NULL,
+                shared_secret VARCHAR(255) NOT NULL,
+                custom_params LONGTEXT DEFAULT NULL,
+                active_deep_linking TINYINT(1) DEFAULT \'0\' NOT NULL,
+                privacy LONGTEXT DEFAULT NULL,
+                INDEX IDX_C5E47F7C91D79BD3 (c_id),
+                INDEX IDX_C5E47F7C82F80D8B (gradebook_eval_id),
+                INDEX IDX_C5E47F7C727ACA70 (parent_id),
+                PRIMARY KEY(id)
+            ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
+            'ALTER TABLE '.self::TABLE_TOOL.' ADD CONSTRAINT FK_C5E47F7C91D79BD3
+                FOREIGN KEY (c_id) REFERENCES course (id)',
+            'ALTER TABLE '.self::TABLE_TOOL.' ADD CONSTRAINT FK_C5E47F7C82F80D8B
+                FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id) ON DELETE SET NULL',
+            'ALTER TABLE '.self::TABLE_TOOL.' ADD CONSTRAINT FK_C5E47F7C727ACA70
+                FOREIGN KEY (parent_id) REFERENCES '.self::TABLE_TOOL.' (id);',
+        ];
+
+        foreach ($queries as $query) {
+            Database::query($query);
+        }
 
         return true;
     }
@@ -377,18 +369,21 @@ class ImsLtiPlugin extends Plugin
         $url = empty($contentItem['url']) ? $baseLtiTool->getLaunchUrl() : $contentItem['url'];
 
         /** @var ImsLtiTool $newLtiTool */
-        $newLtiTool = $ltiToolRepo->findOneBy(['launchUrl' => $url, 'isGlobal' => false, 'course' => $course]);
+        $newLtiTool = $ltiToolRepo->findOneBy(['launchUrl' => $url, 'parent' => $baseLtiTool, 'course' => $course]);
 
-        if (empty($newLtiTool)) {
+        if (null === $newLtiTool) {
             $newLtiTool = new ImsLtiTool();
             $newLtiTool
                 ->setLaunchUrl($url)
-                ->setConsumerKey(
-                    $baseLtiTool->getConsumerKey()
+                ->setParent(
+                    $baseLtiTool
+                )
+                ->setPrivacy(
+                    $baseLtiTool->isSharingName(),
+                    $baseLtiTool->isSharingEmail(),
+                    $baseLtiTool->isSharingEmail()
                 )
-                ->setSharedSecret(
-                    $baseLtiTool->getSharedSecret()
-                );
+                ->setCourse($course);
         }
 
         $newLtiTool
@@ -397,8 +392,7 @@ class ImsLtiPlugin extends Plugin
             )
             ->setDescription(
                 !empty($contentItem['text']) ? $contentItem['text'] : null
-            )
-            ->setCourse($course);
+            );
 
         $em->persist($newLtiTool);
         $em->flush();
@@ -459,7 +453,7 @@ class ImsLtiPlugin extends Plugin
         $toolRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool');
 
         /** @var ImsLtiTool $tool */
-        $tool = $toolRepo->findOneBy(['id' => $toolId, 'isGlobal' => false, 'course' => $course]);
+        $tool = $toolRepo->findOneBy(['id' => $toolId, 'course' => $course]);
 
         return !empty($tool);
     }

+ 23 - 6
plugin/ims_lti/README.md

@@ -1,7 +1,7 @@
 IMS/LTI plugin
 ===
 
-Version 1.2 (beta)
+Version 1.3 (beta)
 
 This plugin is meant to be later integrated into Chamilo (in a major version
 release).
@@ -24,7 +24,15 @@ external tool.
 
 **v1.1**
 * Support for Deep-Linking added.
-* Support for outcomes services.
+* Support for outcomes services. And register score on course gradebook.
+
+**v1.2**
+* Register course in which the tool was added.
+* Register parent tool from which the new tool comes from.
+
+**v1.3**
+* Privacy settings added. Allow to indicate id the launcher's data
+  should be sent in request.
 
 # Installation
 
@@ -42,6 +50,12 @@ ALTER TABLE plugin_ims_lti_tool
     ADD active_deep_linking TINYINT(1) DEFAULT '0' NOT NULL,
     CHANGE id id INT AUTO_INCREMENT NOT NULL,
     CHANGE launch_url launch_url VARCHAR(255) NOT NULL;
+    
+ALTER TABLE plugin_ims_lti_tool ADD gradebook_eval_id INT DEFAULT NULL;
+ALTER TABLE plugin_ims_lti_tool ADD CONSTRAINT FK_C5E47F7C82F80D8B
+    FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id)
+    ON DELETE SET NULL;
+CREATE INDEX IDX_C5E47F7C82F80D8B ON plugin_ims_lti_tool (gradebook_eval_id);
 ```
 
 **To v1.2**
@@ -51,10 +65,13 @@ ALTER TABLE plugin_ims_lti_tool ADD CONSTRAINT FK_C5E47F7C91D79BD3
     FOREIGN KEY (c_id) REFERENCES course (id);
 CREATE INDEX IDX_C5E47F7C91D79BD3 ON plugin_ims_lti_tool (c_id);
 
-ALTER TABLE plugin_ims_lti_tool ADD gradebook_eval_id INT DEFAULT NULL;
-ALTER TABLE plugin_ims_lti_tool ADD CONSTRAINT FK_C5E47F7C82F80D8B
-    FOREIGN KEY (gradebook_eval_id) REFERENCES gradebook_evaluation (id) ON DELETE SET NULL;
-CREATE INDEX IDX_C5E47F7C82F80D8B ON plugin_ims_lti_tool (gradebook_eval_id);
+ALTER TABLE plugin_ims_lti_tool ADD parent_id INT DEFAULT NULL, DROP is_global;
+ALTER TABLE plugin_ims_lti_tool ADD CONSTRAINT FK_C5E47F7C727ACA70
+    FOREIGN KEY (parent_id) REFERENCES plugin_ims_lti_tool (id);
+CREATE INDEX IDX_C5E47F7C727ACA70 ON plugin_ims_lti_tool (parent_id);
+```
 
+**To v1.3**
+```sql
 ALTER TABLE plugin_ims_lti_tool ADD privacy LONGTEXT DEFAULT NULL;
 ```

+ 2 - 0
plugin/ims_lti/admin.php

@@ -11,6 +11,8 @@ $plugin = ImsLtiPlugin::create();
 $em = Database::getManager();
 $tools = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool')->findAll();
 
+$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')];
+
 $template = new Template($plugin->get_title());
 $template->assign('tools', $tools);
 

+ 62 - 80
plugin/ims_lti/configure.php

@@ -20,7 +20,7 @@ $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : 'add';
 /** @var Course $course */
 $course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
 $addedTools = $toolsRepo->findBy(['course' => $course]);
-$globalTools = $toolsRepo->findBy(['isGlobal' => true]);
+$globalTools = $toolsRepo->findBy(['parent' => null, 'course' => null]);
 
 if ($baseTool && !$baseTool->isGlobal()) {
     Display::addFlash(
@@ -33,66 +33,54 @@ if ($baseTool && !$baseTool->isGlobal()) {
 
 switch ($action) {
     case 'add':
-        $form = new FormValidator('ims_lti_add_tool');
-        $form->addHeader($plugin->get_lang('ToolSettings'));
-
-        if ($baseTool) {
-            $form->addHtml('<p class="lead">'.Security::remove_XSS($baseTool->getDescription()).'</p>');
-        }
-
-        $form->addText('name', get_lang('Name'));
-
-        if (!$baseTool) {
-            $form->addElement('url', 'url', $plugin->get_lang('LaunchUrl'));
-            $form->addText('consumer_key', $plugin->get_lang('ConsumerKey'), true);
-            $form->addText('shared_secret', $plugin->get_lang('SharedSecret'), true);
-            $form->addRule('url', get_lang('Required'), 'required');
-        }
-
-        $form->addButtonAdvancedSettings('lti_adv');
-        $form->addHtml('<div id="lti_adv_options" style="display:none;">');
-        $form->addTextarea('description', get_lang('Description'), ['rows' => 3]);
-
-        if (!$baseTool) {
-            $form->addTextarea(
-                'custom_params',
-                [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
-            );
-            $form->addCheckBox('deep_linking', $plugin->get_lang('SupportDeepLinking'), get_lang('Yes'));
-        }
+        $form = new FrmAdd('ims_lti_add_tool', [], $baseTool);
+        $form->build();
 
         if ($baseTool) {
             $form->addHidden('type', $baseTool->getId());
         }
 
-        $form->addHtml('</div>');
-
-        $form->addButtonCreate($plugin->get_lang('AddExternalTool'));
-
         if ($form->validate()) {
             $formValues = $form->getSubmitValues();
-            $tool = null;
-
-            if ($baseTool) {
-                $tool = clone $baseTool;
-            } else {
-                $tool = new ImsLtiTool();
-                $tool
-                    ->setLaunchUrl($formValues['url'])
-                    ->setConsumerKey($formValues['consumer_key'])
-                    ->setSharedSecret($formValues['shared_secret'])
-                    ->setCustomParams(
-                        empty($formValues['custom_params']) ? null : $formValues['custom_params']
-                    );
-            }
 
+            $tool = new ImsLtiTool();
             $tool
                 ->setName($formValues['name'])
                 ->setDescription(
                     empty($formValues['description']) ? null : $formValues['description']
                 )
-                ->setIsGlobal(false)
-                ->setCourse($course);
+                ->setLaunchUrl(
+                    $baseTool ? $baseTool->getLaunchUrl() : $formValues['launch_url']
+                )
+                ->setConsumerKey(
+                    $baseTool ? $baseTool->getConsumerKey() : $formValues['consumer_key']
+                )
+                ->setSharedSecret(
+                    $baseTool ? $baseTool->getSharedSecret() : $formValues['shared_secret']
+                )
+                ->setCustomParams(
+                    empty($formValues['custom_params']) ? null : $formValues['custom_params']
+                )
+                ->setCourse($course)
+                ->setActiveDeepLinking(false)
+                ->setPrivacy(
+                    !empty($formValues['share_name']),
+                    !empty($formValues['share_email']),
+                    !empty($formValues['share_picture'])
+                );
+
+            if (null === $baseTool ||
+                ($baseTool && !$baseTool->isActiveDeepLinking())
+            ) {
+                $tool
+                    ->setActiveDeepLinking(
+                        !empty($formValues['deep_linking'])
+                    );
+            }
+
+            if ($baseTool) {
+                $tool->setParent($baseTool);
+            }
 
             $em->persist($tool);
             $em->flush();
@@ -106,11 +94,10 @@ switch ($action) {
             header('Location: '.api_get_self().'?'.api_get_cidreq());
             exit;
         }
+
+        $form->setDefaultValues();
         break;
     case 'edit':
-        $form = new FormValidator('ims_lti_edit_tool');
-        $form->addHeader($plugin->get_lang('ToolSettings'));
-
         /** @var ImsLtiTool|null $tool */
         $tool = null;
 
@@ -118,35 +105,19 @@ switch ($action) {
             $tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', (int) $_REQUEST['id']);
         }
 
-        if (empty($tool)) {
-            Display::addFlash(
-                Display::return_message($plugin->get_lang('ToolNotAvailable'), 'warning')
-            );
-
-            break;
-        }
-        
-        if (!ImsLtiPlugin::existsToolInCourse($tool->getId(), $course)) {
-            Display::addFlash(
-                Display::return_message($plugin->get_lang('ToolNotAvailable'), 'warning')
+        if (empty($tool) ||
+            !ImsLtiPlugin::existsToolInCourse($tool->getId(), $course)
+        ) {
+            api_not_allowed(
+                true,
+                Display::return_message($plugin->get_lang('ToolNotAvailable'), 'error')
             );
 
             break;
         }
 
-        $form->addText('name', get_lang('Title'));
-        $form->addButtonAdvancedSettings('lti_adv');
-        $form->addHtml('<div id="lti_adv_options" style="display:none;">');
-        $form->addTextarea('description', get_lang('Description'), ['rows' => 3]);
-        $form->addTextarea(
-            'custom_params',
-            [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
-        );
-        $form->addHtml('</div>');
-        $form->addButtonUpdate($plugin->get_lang('EditExternalTool'));
-        $form->addHidden('id', $tool->getId());
-        $form->addHidden('action', 'edit');
-        $form->applyFilter('__ALL__', 'Security::remove_XSS');
+        $form = new FrmEdit('ims_lti_edit_tool', [], $tool);
+        $form->build(false);
 
         if ($form->validate()) {
             $formValues = $form->getSubmitValues();
@@ -154,10 +125,25 @@ switch ($action) {
             $tool
                 ->setName($formValues['name'])
                 ->setDescription($formValues['description'])
+                ->setActiveDeepLinking(
+                    !empty($formValues['deep_linking'])
+                )
                 ->setCustomParams(
                     empty($formValues['custom_params']) ? null : $formValues['custom_params']
+                )
+                ->setPrivacy(
+                    !empty($formValues['share_name']),
+                    !empty($formValues['share_email']),
+                    !empty($formValues['share_picture'])
                 );
 
+            if (null === $tool->getParent()) {
+                $tool
+                    ->setLaunchUrl($formValues['launch_url'])
+                    ->setConsumerKey($formValues['consumer_key'])
+                    ->setSharedSecret($formValues['shared_secret']);
+            }
+
             $em->persist($tool);
             $em->flush();
 
@@ -175,11 +161,7 @@ switch ($action) {
             exit;
         }
 
-        $form->setDefaults([
-            'name' => $tool->getName(),
-            'description' => $tool->getDescription(),
-            'custom_params' => $tool->getCustomParams(),
-        ]);
+        $form->setDefaultValues();
         break;
 }
 

+ 7 - 2
plugin/ims_lti/create.php

@@ -22,11 +22,11 @@ if ($form->validate()) {
     $externalTool
         ->setName($formValues['name'])
         ->setDescription($formValues['description'])
-        ->setLaunchUrl($formValues['base_url'])
+        ->setLaunchUrl($formValues['launch_url'])
         ->setConsumerKey($formValues['consumer_key'])
         ->setSharedSecret($formValues['shared_secret'])
         ->setCustomParams($formValues['custom_params'])
-        ->setIsGlobal(true)
+        ->setCourse(null)
         ->setActiveDeepLinking(
             isset($formValues['deep_linking'])
         )
@@ -47,6 +47,11 @@ if ($form->validate()) {
     exit;
 }
 
+$form->setDefaultValues();
+
+$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);

+ 26 - 26
plugin/ims_lti/edit.php

@@ -29,28 +29,8 @@ if (!$tool) {
     exit;
 }
 
-$form = new FormValidator('ims_lti_edit_tool');
-$form->addText('name', get_lang('Name'));
-$form->addText('url', $plugin->get_lang('LaunchUrl'));
-$form->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
-$form->addText('shared_secret', $plugin->get_lang('SharedSecret'));
-$form->addButtonAdvancedSettings('lti_adv');
-$form->addHtml('<div id="lti_adv_options" style="display:none;">');
-$form->addTextarea('description', get_lang('Description'), ['rows' => 3]);
-$form->addTextarea('custom_params', [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]);
-$form->addCheckBox('deep_linking', $plugin->get_lang('SupportDeepLinking'), get_lang('Yes'));
-$form->addHtml('</div>');
-$form->addButtonSave(get_lang('Save'));
-$form->addHidden('id', $tool->getId());
-$form->setDefaults([
-    'name' => $tool->getName(),
-    'description' => $tool->getDescription(),
-    'url' => $tool->getLaunchUrl(),
-    'consumer_key' => $tool->getConsumerKey(),
-    'shared_secret' => $tool->getSharedSecret(),
-    'custom_params' => $tool->getCustomParams(),
-    'deep_linking' => $tool->isActiveDeepLinking(),
-]);
+$form = new FrmEdit('ims_lti_edit_tool', [], $tool);
+$form->build();
 
 if ($form->validate()) {
     $formValues = $form->exportValues();
@@ -58,10 +38,25 @@ if ($form->validate()) {
     $tool
         ->setName($formValues['name'])
         ->setDescription($formValues['description'])
-        ->setLaunchUrl($formValues['url'])
-        ->setConsumerKey($formValues['consumer_key'])
-        ->setSharedSecret($formValues['shared_secret'])
-        ->setCustomParams($formValues['custom_params']);
+        ->setCustomParams($formValues['custom_params'])
+        ->setPrivacy(
+            !empty($formValues['share_name']),
+            !empty($formValues['share_email']),
+            !empty($formValues['share_picture'])
+        );
+
+    if (null === $tool->getParent()) {
+        $tool
+            ->setLaunchUrl($formValues['launch_url'])
+            ->setConsumerKey($formValues['consumer_key'])
+            ->setSharedSecret($formValues['shared_secret']);
+    }
+
+    if (null === $tool->getParent() ||
+        (null !== $tool->getParent() && !$tool->getParent()->isActiveDeepLinking())
+    ) {
+        $tool->setActiveDeepLinking(!empty($formValues['deep_linking']));
+    }
 
     $em->persist($tool);
     $em->flush();
@@ -74,6 +69,11 @@ if ($form->validate()) {
     exit;
 }
 
+$form->setDefaultValues();
+
+$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());
 

+ 0 - 1
plugin/ims_lti/form.php

@@ -119,7 +119,6 @@ $result = $oauth->sign(array(
         'oauth_callback' => 'about:blank'
     )
 ));
-var_dump($params);die;
 ?>
 <!DOCTYPE html>
 <html>

+ 2 - 0
plugin/ims_lti/lang/english.php

@@ -33,3 +33,5 @@ $strings['ToolEdited'] = 'Tool edited';
 $strings['ShareLauncherName'] = 'Share launcher\'s name';
 $strings['ShareLauncherEmail'] = 'Share launcher\'s email';
 $strings['ShareLauncherPicture'] = 'Share launcher\'s picture';
+$strings['NoTool'] = 'Tool not exists';
+$strings['ToolAddedOnCourseX'] = 'Tool addeed on course <strong>%s</strong>.';

+ 47 - 8
plugin/ims_lti/src/Form/FrmAdd.php

@@ -1,22 +1,33 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
+
 /**
  * Class FrmAdd.
  */
 class FrmAdd extends FormValidator
 {
+    /**
+     * @var ImsLtiTool|null
+     */
+    private $baseTool;
+
     /**
      * FrmAdd constructor.
      *
-     * @param string $name
-     * @param array  $attributes
+     * @param string          $name
+     * @param array           $attributes
+     * @param ImsLtiTool|null $tool
      */
     public function __construct(
         $name,
-        $attributes = []
+        $attributes = [],
+        ImsLtiTool $tool = null
     ) {
         parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
+
+        $this->baseTool = $tool;
     }
 
     /**
@@ -28,17 +39,28 @@ class FrmAdd extends FormValidator
 
         $this->addHeader($plugin->get_lang('ToolSettings'));
         $this->addText('name', get_lang('Name'));
-        $this->addText('base_url', $plugin->get_lang('LaunchUrl'));
-        $this->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
-        $this->addText('shared_secret', $plugin->get_lang('SharedSecret'));
-        $this->addTextarea('description', get_lang('Description'), ['rows' => 3]);
+        $this->addTextarea('description', get_lang('Description'));
+
+        if (null === $this->baseTool) {
+            $this->addElement('url', 'launch_url', $plugin->get_lang('LaunchUrl'));
+            $this->addRule('launch_url', get_lang('Required'), 'required');
+            $this->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
+            $this->addText('shared_secret', $plugin->get_lang('SharedSecret'));
+        }
+
         $this->addButtonAdvancedSettings('lti_adv');
         $this->addHtml('<div id="lti_adv_options" style="display:none;">');
         $this->addTextarea(
             'custom_params',
             [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
         );
-        $this->addCheckBox('deep_linking', null, $plugin->get_lang('SupportDeepLinking'));
+
+        if (null === $this->baseTool ||
+            ($this->baseTool && !$this->baseTool->isActiveDeepLinking())
+        ) {
+            $this->addCheckBox('deep_linking', null, $plugin->get_lang('SupportDeepLinking'));
+        }
+
         $this->addHtml('</div>');
         $this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
         $this->addHtml('<div id="lti_privacy_options" style="display:none;">');
@@ -47,5 +69,22 @@ class FrmAdd extends FormValidator
         $this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture'));
         $this->addHtml('</div>');
         $this->addButtonCreate($plugin->get_lang('AddExternalTool'));
+        $this->applyFilter('__ALL__', 'Security::remove_XSS');
+    }
+
+    public function setDefaultValues()
+    {
+        if (null !== $this->baseTool) {
+            $this->setDefaults(
+                [
+                    'name' => $this->baseTool->getName(),
+                    'description' => $this->baseTool->getDescription(),
+                    'custom_params' => $this->baseTool->getCustomParams(),
+                    'share_name' => $this->baseTool->isSharingName(),
+                    'share_email' => $this->baseTool->isSharingEmail(),
+                    'share_picture' => $this->baseTool->isSharingPicture(),
+                ]
+            );
+        }
     }
 }

+ 111 - 0
plugin/ims_lti/src/Form/FrmEdit.php

@@ -0,0 +1,111 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
+
+/**
+ * Class FrmAdd.
+ */
+class FrmEdit extends FormValidator
+{
+    /**
+     * @var ImsLtiTool|null
+     */
+    private $tool;
+
+    /**
+     * FrmAdd constructor.
+     *
+     * @param string          $name
+     * @param array           $attributes
+     * @param ImsLtiTool|null $tool
+     */
+    public function __construct(
+        $name,
+        $attributes = [],
+        ImsLtiTool $tool = null
+    ) {
+        parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
+
+        $this->tool = $tool;
+    }
+
+    /**
+     * Build the form.
+     *
+     * @param bool $globalMode
+     *
+     * @throws Exception
+     */
+    public function build($globalMode = true)
+    {
+        $plugin = ImsLtiPlugin::create();
+        $course = $this->tool->getCourse();
+        $parent = $this->tool->getParent();
+
+        $this->addHeader($plugin->get_lang('ToolSettings'));
+
+        if (null !== $course && $globalMode) {
+            $this->addHtml(
+                Display::return_message(
+                    sprintf($plugin->get_lang('ToolAddedOnCourseX'), $course->getTitle()),
+                    'normal',
+                    false
+                )
+            );
+        }
+
+        $this->addText('name', get_lang('Name'));
+        $this->addTextarea('description', get_lang('Description'));
+
+        if (null === $parent) {
+            $this->addElement('url', 'launch_url', $plugin->get_lang('LaunchUrl'));
+            $this->addRule('launch_url', get_lang('Required'), 'required');
+            $this->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
+            $this->addText('shared_secret', $plugin->get_lang('SharedSecret'));
+        }
+
+        $this->addButtonAdvancedSettings('lti_adv');
+        $this->addHtml('<div id="lti_adv_options" style="display:none;">');
+        $this->addTextarea(
+            'custom_params',
+            [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
+        );
+
+        if (null === $parent ||
+            (null !== $parent && !$parent->isActiveDeepLinking())
+        ) {
+            $this->addCheckBox('deep_linking', null, $plugin->get_lang('SupportDeepLinking'));
+        }
+
+        $this->addHtml('</div>');
+        $this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
+        $this->addHtml('<div id="lti_privacy_options" style="display:none;">');
+        $this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName'));
+        $this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail'));
+        $this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture'));
+        $this->addHtml('</div>');
+        $this->addButtonCreate($plugin->get_lang('EditExternalTool'));
+        $this->addHidden('id', $this->tool->getId());
+        $this->addHidden('action', 'edit');
+        $this->applyFilter('__ALL__', 'Security::remove_XSS');
+    }
+
+    public function setDefaultValues()
+    {
+        $this->setDefaults(
+            [
+                'name' => $this->tool->getName(),
+                'description' => $this->tool->getDescription(),
+                'launch_url' => $this->tool->getLaunchUrl(),
+                'consumer_key' => $this->tool->getConsumerKey(),
+                'shared_secret' => $this->tool->getSharedSecret(),
+                'custom_params' => $this->tool->getCustomParams(),
+                'deep_linking' => $this->tool->isActiveDeepLinking(),
+                'share_name' => $this->tool->isSharingName(),
+                'share_email' => $this->tool->isSharingEmail(),
+                'share_picture' => $this->tool->isSharingPicture(),
+            ]
+        );
+    }
+}

+ 1 - 1
plugin/ims_lti/view/add.tpl

@@ -31,7 +31,7 @@
         </div>
     {% endif %}
 
-    <div class="col-sm-9 {{ not global_tools|length or not added_tools|length ? 'col-md-offset-3' : '' }}">
+    <div class="col-sm-9 {{ not global_tools|length and not added_tools|length ? 'col-md-offset-3' : '' }}">
         {{ form }}
     </div>
 </div>