コード例 #1
0
 /**
  * Generate a list of menu options and a default selection which will be used as arguments to a popup_form()
  * function call in order to display a drop-down list of places from which to browse files using any Moodle
  * file browsing interface anywhere in the system.
  *
  * @uses $USER
  * @param int    $cid         A course record ID.
  * @param int    $uid         A user record ID.
  * @param int    $oid         A cluster record ID.
  * @param bool   $shared      A flag to indicate whether the user is currently located in the shared repository area.
  * @param string $choose      File browser 'choose' parameter.
  * @param string $origurl     The originating URL from where this function was called.
  * @param string $moodleurl   The base URL for browsing files from Moodledata.
  * @param string $alfrescourl The base URL for browsing files from Alfresco.
  * @param string $default     The default option to be selected in the form.
  * @return array An array of options meant to be used in a popup_form() function call.
  */
 function file_browse_options($cid, $uid, $oid, $shared, $choose, $origurl, $moodleurl, $alfrescourl, &$default)
 {
     global $USER;
     $opts = array();
     // Modify the base URLs to prepare them correctly for additional parameters to be added later.
     $origurl .= (strpos($origurl, '?') !== false ? '&' : '?') . 'dd=1&';
     $moodleurl .= (strpos($moodleurl, '?') !== false ? '&' : '?') . 'dd=1&';
     $alfrescourl .= (strpos($alfrescourl, '?') !== false ? '&' : '?') . 'dd=1&';
     if ($cid == SITEID) {
         $context = get_context_instance(CONTEXT_SYSTEM);
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $cid);
     }
     // Determine if the user has access to their own personal file storage area.
     $editalfshared = false;
     $viewalfshared = false;
     $viewalfpersonal = false;
     $editalfpersonal = false;
     $viewalforganization = false;
     $editalforganization = false;
     if (!empty($USER->access['rdef'])) {
         foreach ($USER->access['rdef'] as $rdef) {
             if ($viewalfshared) {
                 continue;
             }
             if (isset($rdef['block/repository:createowncontent']) && $rdef['block/repository:createowncontent'] == CAP_ALLOW) {
                 $editalfpersonal = true;
             }
             if (isset($rdef['block/repository:viewowncontent']) && $rdef['block/repository:viewowncontent'] == CAP_ALLOW) {
                 $viewalfpersonal = true;
             }
             if (isset($rdef['block/repository:viewsharedcontent']) && $rdef['block/repository:viewsharedcontent'] == CAP_ALLOW) {
                 $viewalfshared = true;
             }
             if (isset($rdef['block/repository:createsharedcontent']) && $rdef['block/repository:createsharedcontent'] == CAP_ALLOW) {
                 $editalfshared = true;
             }
         }
     }
     $editmoodle = has_capability('moodle/course:managefiles', $context);
     $editalfsite = has_capability('block/repository:createsitecontent', $context);
     $viewalfsite = has_capability('block/repository:viewsitecontent', $context);
     $editalfcourse = has_capability('block/repository:createcoursecontent', $context);
     $viewalfcourse = has_capability('block/repository:viewcoursecontent', $context);
     // Build the option for browsing from the Moodle site files.
     if ($editmoodle) {
         $surl = $moodleurl . 'id=' . $cid . '&userid=' . $uid . '&choose=' . $choose;
         $opts[$surl] = $cid == SITEID ? get_string('sitefiles') : get_string('coursefiles');
     }
     // Fix username
     $username = $this->fix_username($USER->username);
     // Build the option for browsing from the repository course / site / cluster files.
     if ($cid == SITEID && $viewalfsite) {
         $curl = $alfrescourl . 'id=' . $cid . '&userid=0&choose=' . $choose;
         $opts[$curl] = get_string('repositorysitefiles', 'repository');
         $alfroot = $this->get_root();
         if (!empty($alfroot->uuid)) {
             $uuid = $alfroot->uuid;
             // Make sure this user actually has the correct permissions assigned here.
             if (!alfresco_has_permission($uuid, $username)) {
                 $this->allow_read($username, $uuid);
             }
         }
     } else {
         if ($cid != SITEID && $viewalfcourse) {
             $curl = $alfrescourl . 'id=' . $cid . '&userid=0&choose=' . $choose;
             $opts[$curl] = get_string('repositorycoursefiles', 'repository');
             if (!alfresco_has_permission($this->muuid, $username)) {
                 $this->allow_read($username, $this->muuid);
             }
             if (!alfresco_has_permission($this->cuuid, $username)) {
                 $this->allow_read($username, $this->cuuid);
             }
             if (($uuid = $this->get_course_store($cid)) !== false) {
                 // Make sure this user actually has the correct permissions assigned here.
                 if (!alfresco_has_permission($uuid, $username)) {
                     $this->allow_read($username, $uuid);
                 }
             }
         }
     }
     // Build the option for browsing from the repository shared files.
     if ($viewalfshared) {
         $shurl = $alfrescourl . 'id=' . $cid . '&shared=true&userid=0&choose=' . $choose;
         $opts[$shurl] = get_string('repositorysharedfiles', 'repository');
         if (!alfresco_has_permission($this->muuid, $username)) {
             $this->allow_read($username, $this->muuid);
         }
         if (!alfresco_has_permission($this->suuid, $username)) {
             $this->allow_read($username, $this->suuid);
         }
     }
     // Build the option for browsing from the repository personal / user files.
     if ($viewalfpersonal) {
         $uurl = $alfrescourl . 'id=' . $cid . '&userid=' . $USER->id . '&choose=' . $choose;
         $opts[$uurl] = get_string('repositoryuserfiles', 'repository');
     }
     // Build the option for browsing from the repository organization files.
     if ($organization_folders = $this->find_organization_folders($USER->id, $username)) {
         foreach ($organization_folders as $name => $cluster) {
             $cluster_context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $cluster['id']);
             $viewalforganization = has_capability('block/repository:vieworganizationcontent', $cluster_context);
             $ourl = $alfrescourl . 'id=' . $cid . '&oid=' . $cluster['id'] . '&userid=0&choose=' . $choose;
             if ($viewalforganization) {
                 // viewalforganization
                 // Give the user read access to the folder moodle
                 if (!alfresco_has_permission($this->muuid, $username)) {
                     $this->allow_read($username, $this->muuid);
                 }
                 // Give the read access to the parent folder organization
                 if (!alfresco_has_permission($this->ouuid, $username)) {
                     $this->allow_read($username, $this->ouuid);
                 }
                 if (!alfresco_has_permission($cluster['uuid'], $username)) {
                     $this->allow_read($username, $cluster['uuid']);
                 }
                 $opts[$ourl] = $name;
             }
         }
     }
     // Assemble the default menu selection based on the information given to this method.
     $default = $origurl . 'id=' . $cid . (!empty($oid) ? '&oid=' . $oid : '') . (!empty($shared) ? '&shared=true' : '') . '&userid=' . ($editalfpersonal || $viewalfpersonal ? $uid : '0') . '&choose=' . $choose;
     return $opts;
 }
コード例 #2
0
ファイル: lib.php プロジェクト: remotelearner/elis.alfresco
/**
 * Handle the event when a user is assigned to a cluster.
 *
 * @uses $CFG
 * @param object $clusterinfo The Moodle role_assignment record object.
 * @return bool True on success or failure (event handlers must always return true).
 */
function block_repository_cluster_assigned($clusterinfo)
{
    global $CFG;
    // Only proceed here if the Alfresco plug-in is actually enabled.
    if (!isset($CFG->repository_plugins_enabled) || strstr($CFG->repository_plugins_enabled, 'alfresco') === false || !($repo = repository_factory::factory('alfresco'))) {
        return true;
    }
    // Get the Moodle user ID from the CM user ID.
    if (!($muserid = cm_get_moodleuserid($clusterinfo->userid))) {
        return true;
    }
    if (!($username = get_field('user', 'username', 'id', $muserid))) {
        return true;
    }
    if (!($cluster = get_record('crlm_cluster', 'id', $clusterinfo->clusterid))) {
        return true;
    }
    if (!file_exists($CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php')) {
        return true;
    }
    require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
    // Get the extra cluster data and ensure it is present before proceeding.
    $clusterdata = clusterclassification::get_for_cluster($cluster);
    if (empty($clusterdata->params)) {
        return true;
    }
    $clusterparams = unserialize($clusterdata->params);
    // Make sure this cluster has the Alfresco shared folder property defined
    if (empty($clusterparams['alfresco_shared_folder'])) {
        return true;
    }
    // Make sure we can get the storage space from Alfresco for this organization.
    if (!($uuid = $repo->get_organization_store($cluster->id))) {
        return true;
    }
    $context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $cluster->id);
    $sql = "SELECT rc.*\n            FROM {$CFG->prefix}role_capabilities rc\n            INNER JOIN {$CFG->prefix}role r ON r.id = rc.roleid\n            INNER JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n            WHERE ra.contextid = {$context->id}\n            AND ra.userid = {$muserid}\n            AND rc.capability = 'block/repository:createorganizationcontent'\n            AND rc.permission = " . CAP_ALLOW;
    // Check if the user has the the editing capability for the Alfresco organization shared
    // storage space assigned at this cluster context level or is designated as a cluster leader in order to
    // enable editing permission on the Alfresco space.
    if (record_exists('crlm_usercluster', 'userid', $clusterinfo->userid, 'clusterid', $cluster->id, 'leader', 1) || record_exists_sql($sql)) {
        // Ensure that this user already has an Alfresco account.
        if (!$repo->alfresco_userdir($username)) {
            if (!$repo->migrate_user($username)) {
                return true;
            }
        }
        if (!alfresco_has_permission($uuid, $username, true)) {
            alfresco_set_permission($username, $uuid, ALFRESCO_ROLE_COLLABORATOR, ALFRESCO_CAPABILITY_ALLOWED);
        }
        // Double-check tjhat the user is designated as a cluster member (we should not be here otherwise) in order to
        // enable viewinging permission on the Alfresco space.
    } else {
        if (record_exists('crlm_usercluster', 'userid', $clusterinfo->userid, 'clusterid', $cluster->id, 'leader', 0)) {
            // Ensure that this user already has an Alfresco account.
            if (!$repo->alfresco_userdir($username)) {
                if (!$repo->migrate_user($username)) {
                    return true;
                }
            }
            if (!alfresco_has_permission($uuid, $username, false)) {
                alfresco_set_permission($username, $uuid, ALFRESCO_ROLE_CONSUMER, ALFRESCO_CAPABILITY_ALLOWED);
            }
        }
    }
    return true;
}