Browse Source

WIP LTI adding privacy settings - refs BT#13469

Angel Fernando Quiroz Campos 6 years ago
parent
commit
517f1fc727

+ 82 - 0
plugin/ims_lti/Entity/ImsLtiTool.php

@@ -72,6 +72,13 @@ class ImsLtiTool
      */
     private $activeDeepLinking = false;
 
+    /**
+     * @var null|string
+     *
+     * @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null})
+     */
+    private $privacy = null;
+
     /**
      * @var Course|null
      *
@@ -99,6 +106,7 @@ class ImsLtiTool
         $this->activeDeepLinking = false;
         $this->course = null;
         $this->gradebookEval =null;
+        $this->privacy = null;
     }
 
     /**
@@ -260,10 +268,14 @@ class ImsLtiTool
      * Set activeDeepLinking.
      *
      * @param bool $activeDeepLinking
+     *
+     * @return ImsLtiTool
      */
     public function setActiveDeepLinking($activeDeepLinking)
     {
         $this->activeDeepLinking = $activeDeepLinking;
+
+        return $this;
     }
 
     /**
@@ -323,4 +335,74 @@ class ImsLtiTool
 
         return $this;
     }
+
+    /**
+     * Get privacy.
+     *
+     * @return null|string
+     */
+    public function getPrivacy()
+    {
+        return $this->privacy;
+    }
+
+    /**
+     * Set privacy.
+     *
+     * @param bool $shareName
+     * @param bool $shareEmail
+     * @param bool $sharePicture
+     *
+     * @return ImsLtiTool
+     */
+    public function setPrivacy($shareName = false, $shareEmail = false, $sharePicture = false)
+    {
+        $this->privacy = serialize(
+            [
+                'share_name' => $shareName,
+                'share_email' => $shareEmail,
+                'share_picture' => $sharePicture,
+            ]
+        );
+
+        return $this;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isSharingName()
+    {
+        $unserialize = $this->unserializePrivacy();
+
+        return (bool) $unserialize['share_name'];
+    }
+
+    /**
+     * @return bool
+     */
+    public function isSharingEmail()
+    {
+        $unserialize = $this->unserializePrivacy();
+
+        return (bool) $unserialize['share_email'];
+    }
+
+    /**
+     * @return bool
+     */
+    public function isSharingPicture()
+    {
+        $unserialize = $this->unserializePrivacy();
+
+        return (bool) $unserialize['share_picture'];
+    }
+
+    /**
+     * @return mixed
+     */
+    public function unserializePrivacy()
+    {
+        return unserialize($this->privacy);
+    }
 }

+ 2 - 0
plugin/ims_lti/README.md

@@ -55,4 +55,6 @@ 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 privacy LONGTEXT DEFAULT NULL;
 ```

+ 7 - 13
plugin/ims_lti/create.php

@@ -12,19 +12,8 @@ $plugin = ImsLtiPlugin::create();
 
 $em = Database::getManager();
 
-$form = new FormValidator('ism_lti_create_tool');
-$form->addHeader($plugin->get_lang('ToolSettings'));
-$form->addText('name', get_lang('Name'));
-$form->addText('base_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->addButtonCreate($plugin->get_lang('AddExternalTool'));
+$form = new FrmAdd('ism_lti_create_tool');
+$form->build();
 
 if ($form->validate()) {
     $formValues = $form->exportValues();
@@ -40,6 +29,11 @@ if ($form->validate()) {
         ->setIsGlobal(true)
         ->setActiveDeepLinking(
             isset($formValues['deep_linking'])
+        )
+        ->setPrivacy(
+            isset($formValues['share_name']),
+            isset($formValues['share_email']),
+            isset($formValues['share_picture'])
         );
 
     $em->persist($externalTool);

+ 16 - 5
plugin/ims_lti/form.php

@@ -72,12 +72,22 @@ if ($tool->isActiveDeepLinking()) {
 }
 
 $params['user_id'] = $toolUserId;
-$params['user_image'] = UserManager::getUserPicture($user->getId());
+
+if ($tool->isSharingPicture()) {
+    $params['user_image'] = UserManager::getUserPicture($user->getId());
+}
+
 $params['roles'] = ImsLtiPlugin::getUserRoles($user);
-$params['lis_person_name_given'] = $user->getFirstname();
-$params['lis_person_name_family'] = $user->getLastname();
-$params['lis_person_name_full'] = $user->getCompleteName();
-$params['lis_person_contact_email_primary'] = $user->getEmail();
+
+if ($tool->isSharingName()) {
+    $params['lis_person_name_given'] = $user->getFirstname();
+    $params['lis_person_name_family'] = $user->getLastname();
+    $params['lis_person_name_full'] = $user->getCompleteName();
+}
+
+if ($tool->isSharingEmail()) {
+    $params['lis_person_contact_email_primary'] = $user->getEmail();
+}
 
 if (api_is_allowed_to_edit(false, true)) {
     $params['role_scope_mentor'] = ImsLtiPlugin::getRoleScopeMentor($course, $session);
@@ -109,6 +119,7 @@ $result = $oauth->sign(array(
         'oauth_callback' => 'about:blank'
     )
 ));
+var_dump($params);die;
 ?>
 <!DOCTYPE html>
 <html>

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

@@ -30,3 +30,6 @@ $strings['ScoreNotSet'] = 'Score not set';
 $strings['ScoreForXUserIsYScore'] = 'Score for %s is %s';
 $strings['ToolsAdded'] = 'Added tools';
 $strings['ToolEdited'] = 'Tool edited';
+$strings['ShareLauncherName'] = 'Share launcher\'s name';
+$strings['ShareLauncherEmail'] = 'Share launcher\'s email';
+$strings['ShareLauncherPicture'] = 'Share launcher\'s picture';

+ 51 - 0
plugin/ims_lti/src/Form/FrmAdd.php

@@ -0,0 +1,51 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Class FrmAdd.
+ */
+class FrmAdd extends FormValidator
+{
+    /**
+     * FrmAdd constructor.
+     *
+     * @param string $name
+     * @param array  $attributes
+     */
+    public function __construct(
+        $name,
+        $attributes = []
+    ) {
+        parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
+    }
+
+    /**
+     * Build the form
+     */
+    public function build()
+    {
+        $plugin = ImsLtiPlugin::create();
+
+        $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->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'));
+        $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('AddExternalTool'));
+    }
+}