Example #1
0
function CreateFromLTIMembership($member)
{
    $user_id = $member->getID(BasicLTI_Tool_Provider::ID_SCOPE_GLOBAL);
    $values = GetPluginSettings();
    $userprovision = $values['userprovision'];
    // Does user exist
    $user = CheckLTIUser($user_id);
    if ((is_null($user) || empty($user)) && $userprovision) {
        $fullname = $member->fullname;
        $email = $member->email;
        if (empty($email)) {
            $email = '*****@*****.**';
        }
        $password = random_string(10);
        $guid = register_user($user_id, $password, $fullname, $email, True, 0, '');
        if (!$guid) {
            return null;
        }
        $user = get_entity($guid);
        $user->enable();
        $user->consumer_key = $member->context->consumer_instance->guid;
        $user->context_id = $member->context->id;
        $user->save();
    }
    return $user;
}
Example #2
0
function ProvisionLTIGroup($tool_provider)
{
    // Get status of group provisining
    $values = GetPluginSettings();
    $groupprovision = $values['groupprovision'];
    $groupname = $tool_provider->context->title;
    // Get context_id and consumer_key for primary context
    $context_id = $tool_provider->context->id;
    $consumer_key = $tool_provider->context->consumer_instance->consumer_guid;
    $user_id = $tool_provider->user->getID(BasicLTI_Tool_Provider::ID_SCOPE_GLOBAL);
    // Check if we are dealing with an unapproved share. If so return
    // to consumer with suitable message
    if (!empty($tool_provider->user->context->share_approved) && !$tool_provider->user->context->share_approved) {
        $urlencode = urlencode(sprintf(elgg_echo('LTI:error:sharing'), elgg_get_config('sitename')));
        forward($tool_provider->return_url . '&lti_msg=' . $urlencode);
        return false;
    }
    // Get user
    $user = CheckLTIUser($user_id);
    $user_guid = $user->getGUID();
    $_SESSION['lti_logger_id'] = $user->getGUID();
    $staff = $tool_provider->user->isStaff();
    // Check that groups are present and provisioning is on
    if (elgg_is_active_plugin('groups') && $groupprovision) {
        $group = CheckLTIGroup($groupname, $context_id, $consumer_key);
        // Only staff can create groups.
        if ($staff && is_null($group)) {
            $group = CreateLTIGroup($user, $groupname, $context_id, $consumer_key);
            // Ensure that the owner is instructor as simpifies matters
            add_entity_relationship($user_guid, 'instructor', $group->getGUID());
            system_message(elgg_echo('LTI:info:newgroup'));
            forward($group->getURL());
        }
        if (is_null($group)) {
            system_messages(elgg_echo('LTI:info:nogroup'));
            forward();
        }
        $group_guid = $group->getGUID();
        $_SESSION['lti_group_id'] = $group->getGUID();
        // Is this user a member of the group
        if ($group->isMember($user)) {
            // If user used to be instructor but is now student remove 'instructor' relationship
            if ($tool_provider->user->isLearner() && check_entity_relationship($user_guid, 'instructor', $group_guid)) {
                remove_entity_relationship($user_guid, 'instructor', $group->getGUID());
                system_messages(elgg_echo('LTI:change:downgrade'));
                forward($group->getURL());
            }
            // If user is staff add instructor relationship unless they are group owner
            if ($staff && !check_entity_relationship($user_guid, 'instructor', $group_guid) && $user_guid != $group_guid) {
                add_entity_relationship($user_guid, 'instructor', $group_guid);
                system_messages(elgg_echo('LTI:change:upgrade'));
                forward($group->getURL());
            }
            system_messages('Forwarded to Group');
            forward($group->getURL());
        }
        // If not member join
        $group->join($user);
        // If instructor but not owner give instructor relationship to group. This makes
        // other consumer instructors able to edit the group in Elgg
        if ($staff && !check_entity_relationship($user_guid, 'instructor', $group_guid)) {
            add_entity_relationship($user_guid, 'instructor', $group_guid);
            system_messages(elgg_echo('LTI:change:upgrade'));
            forward($group->getURL());
        }
        system_messages('Forwarded to Group');
        forward($group->getURL());
    }
}
Example #3
0
<?php

/*------------------------------------------------------------------
 * Elgg LTI
 *
 * This is called when a sync (membership) operation is performed.
 * This works out the added, deleted and changed when called. The
 * results are stored in session variables to avoid recaluating when
 * the added, deleted and changed tabs are clicked.
 ------------------------------------------------------------------*/
elgg_set_context('groups');
// Must be logged in to use this page
gatekeeper();
// Get plugin settings
$values = GetPluginSettings();
$userprovision = $values['userprovision'];
$instructorupdate = $values['allowinstructor'];
$testmode = $values['testmode'];
// Get group details
$group_guid = (int) get_input('group_guid');
$group = get_entity($group_guid);
set_page_owner($group_guid);
// Update synchronisation time
$contexts = array();
// Get logged in user
$cur_user = elgg_get_logged_in_user_entity();
$consumer_instance = new LTI_Tool_Consumer_Instance($cur_user->consumer_key, elgg_get_config('dbprefix'));
$context = new LTI_Context($consumer_instance, $cur_user->context_id);
// Add this context as must be used
$contexts[] = $context;
if ($cur_user->consumer_key == $group->consumer_key) {
Example #4
0
function LTI_pagesetup()
{
    $page_owner = elgg_get_page_owner_entity();
    // Add administrator's menu items
    if (elgg_get_context() == 'admin' && elgg_is_admin_logged_in()) {
        /* elgg_register_menu_item('page', array(
        					'name' => elgg_echo('LTI:registered'),
        					'text' => elgg_echo('LTI:registered'),
        					'href' => "blti/displayconsumers",
        					'title' => elgg_echo('LTI:registered'),
        		)); */
    }
    // Group submenu: add the option to Sync Users
    $user = elgg_get_logged_in_user_entity();
    if ($page_owner instanceof ElggGroup && elgg_get_context() == 'groups') {
        // LTI plugin must be enabled, Group must be LTI and current user must be instructor from module
        // Also need to add check that extensions are enabled for this consumer. Finally check that instructor
        // can create/update
        // Get status of instructors for create/update users
        $values = GetPluginSettings();
        $allowinstructor = $values['allowinstructor'];
        // Get context to allow check that membership servce is available before putting up Sync option.
        // Use the user context to ensure we check against consumer they came from
        $consumer_instance = new LTI_Tool_Consumer_Instance($user->consumer_key, elgg_get_config('dbprefix'));
        $context = new LTI_Context($consumer_instance, $user->context_id);
        if (elgg_is_active_plugin(elgg_get_config('ltiname')) && !empty($page_owner->consumer_key) && $context->hasMembershipsService() && check_entity_relationship($user->getGUID(), 'instructor', $page_owner->getGUID()) && $allowinstructor) {
            //$page_owner->consumer_key;
            add_submenu_item(sprintf(elgg_echo('LTI:sync')), elgg_get_config('wwwroot') . elgg_get_config('ltiname') . '/synctext/' . $page_owner->getGUID());
        }
        // Only display sharing options to instructors from primary context
        if (elgg_is_active_plugin(elgg_get_config('ltiname')) && !empty($page_owner->consumer_key) && $page_owner->consumer_key == $user->consumer_key && check_entity_relationship($user->getGUID(), 'instructor', $page_owner->getGUID())) {
            add_submenu_item(sprintf(elgg_echo('LTI:share:key')), elgg_get_config('wwwroot') . elgg_get_config('ltiname') . '/sharekey/' . $page_owner->consumer_key . '/' . $page_owner->getGUID() . '/');
            add_submenu_item(sprintf(elgg_echo('LTI:share:manage')), elgg_get_config('wwwroot') . elgg_get_config('ltiname') . '/sharemanage/' . $page_owner->consumer_key . '/' . $page_owner->getGUID() . '/');
        }
    }
}