diff --git a/plugin/ims_lti/ImsLtiPlugin.php b/plugin/ims_lti/ImsLtiPlugin.php
index d5e6dc03d0..4aa660a8b5 100644
--- a/plugin/ims_lti/ImsLtiPlugin.php
+++ b/plugin/ims_lti/ImsLtiPlugin.php
@@ -1,8 +1,12 @@
course_settings = [
[
'name' => $this->get_lang('ImsLtiDescription').$button.'
',
- 'type' => 'html'
- ]
+ 'type' => 'html',
+ ],
];
}
@@ -238,4 +242,72 @@ class ImsLtiPlugin extends Plugin
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
}
+
+ public static function isInstructor()
+ {
+ api_is_allowed_to_edit(false, true);
+ }
+
+ /**
+ * @param User $user
+ *
+ * @return string
+ */
+ public static function getUserRoles(User $user)
+ {
+ if ($user->getStatus() === INVITEE) {
+ return 'Learner/GuestLearner';
+ }
+
+ if (!api_is_allowed_to_edit(false, true)) {
+ return 'Learner/Learner';
+ }
+
+ $roles = ['Instructor'];
+
+ if (api_is_platform_admin_by_id($user->getId())) {
+ $roles[] = 'Administrator/SystemAdministrator';
+ }
+
+ return implode(',', $roles);
+ }
+
+ /**
+ * @param int $userId
+ *
+ * @return string
+ */
+ public static function generateToolUserId($userId)
+ {
+ $siteName = api_get_setting('siteName');
+ $institution = api_get_setting('Institution');
+ $toolUserId = "$siteName - $institution - $userId";
+ $toolUserId = api_replace_dangerous_char($toolUserId);
+
+ return $toolUserId;
+ }
+
+ /**
+ * @param Course $course
+ * @param Session|null $session
+ *
+ * @return string
+ */
+ public static function getRoleScopeMentor(Course $course, Session $session = null)
+ {
+ $scope = [];
+
+ if ($session) {
+ $students = $session->getUserCourseSubscriptionsByStatus($course, Session::STUDENT);
+ } else {
+ $students = $course->getStudents();
+ }
+
+ /** @var SessionRelCourseRelUser|CourseRelUser $subscription */
+ foreach ($students as $subscription) {
+ $scope[] = self::generateToolUserId($subscription->getUser()->getId());
+ }
+
+ return implode(',', $scope);
+ }
}
diff --git a/plugin/ims_lti/form.php b/plugin/ims_lti/form.php
index ef26dba534..c4d59729a7 100644
--- a/plugin/ims_lti/form.php
+++ b/plugin/ims_lti/form.php
@@ -1,6 +1,7 @@
find('ChamiloCoreBundle:Session', api_get_session_id());
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
/** @var User $user */
$user = $em->find('ChamiloUserBundle:User', api_get_user_id());
$siteName = api_get_setting('siteName');
-$institution = api_get_setting('Institution');
-$toolUserId = "$siteName - $institution - {$user->getId()}";
-$toolUserId = api_replace_dangerous_char($toolUserId);
-
-$params = [
- 'lti_message_type' => 'basic-lti-launch-request',
- 'lti_version' => 'LTI-1p0',
-
- 'resource_link_id' => $tool->getId(),
- 'resource_link_title' => $tool->getName(),
- 'resource_link_description' => $tool->getDescription(),
-
- 'user_id' => $toolUserId,
- 'roles' => api_is_teacher() ? 'Instructor' : 'Student',
-
- 'lis_person_name_given' => $user->getFirstname(),
- 'lis_person_name_family' => $user->getLastname(),
- 'lis_person_name_full' => $user->getCompleteName(),
- 'lis_person_contact_email_primary' => $user->getEmail(),
-
- 'context_id' => $course->getId(),
- 'context_label' => $course->getCode(),
- 'context_title' => $course->getTitle(),
-
- 'launch_presentation_locale' => api_get_language_isocode(),
- 'launch_presentation_document_target' => 'embed',
+$toolUserId = ImsLtiPlugin::generateToolUserId($user);
+
+$params = [];
+$params['lti_message_type'] = 'basic-lti-launch-request';
+$params['lti_version'] = 'LTI-1p0';
+$params['resource_link_id'] = $tool->getId();
+$params['resource_link_title'] = $tool->getName();
+$params['resource_link_description'] = $tool->getDescription();
+$params['user_id'] = ImsLtiPlugin::generateToolUserId($user->getId());
+$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 (api_is_allowed_to_edit(false, true)) {
+ $params['role_scope_mentor'] = ImsLtiPlugin::getRoleScopeMentor($course, $session);
+}
- 'tool_consumer_info_product_family_code' => 'Chamilo LMS',
- 'tool_consumer_info_version' => api_get_version(),
- 'tool_consumer_instance_guid' => api_get_setting('InstitutionUrl'),
- 'tool_consumer_instance_name' => $siteName,
- 'tool_consumer_instance_url' => api_get_path(WEB_PATH),
- 'tool_consumer_instance_contact_email' => api_get_setting('emailAdministrator'),
-];
+$params['context_id'] = $course->getId();
+$params['context_type'] = 'CourseSection';
+$params['context_label'] = $course->getCode();
+$params['context_title'] = $course->getTitle();
+$params['launch_presentation_locale'] = api_get_language_isocode();
+$params['launch_presentation_document_target'] = 'iframe';
+$params['tool_consumer_info_product_family_code'] = 'Chamilo LMS';
+$params['tool_consumer_info_version'] = api_get_version();
+$params['tool_consumer_instance_guid'] = str_replace(['https://', 'http://'], '', api_get_setting('InstitutionUrl'));
+$params['tool_consumer_instance_name'] = $siteName;
+$params['tool_consumer_instance_url'] = api_get_path(WEB_PATH);
+$params['tool_consumer_instance_contact_email'] = api_get_setting('emailAdministrator');
$oauth = new OAuthSimple(
$tool->getConsumerKey(),