当前位置: 首页>>代码示例>>PHP>>正文


PHP repository::get_instances方法代码示例

本文整理汇总了PHP中repository::get_instances方法的典型用法代码示例。如果您正苦于以下问题:PHP repository::get_instances方法的具体用法?PHP repository::get_instances怎么用?PHP repository::get_instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在repository的用法示例。


在下文中一共展示了repository::get_instances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xmldb_repository_alfresco_upgrade

/**
 * Upgrade function.
 *
 * @param int $oldversion the version we are upgrading from.
 * @return bool result
 */
function xmldb_repository_alfresco_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2014020301) {
        require_once $CFG->dirroot . '/repository/lib.php';
        require_once $CFG->dirroot . '/repository/alfresco/db/upgradelib.php';
        $params = array();
        $params['context'] = array();
        $params['onlyvisible'] = false;
        $params['type'] = 'alfresco';
        $instances = repository::get_instances($params);
        // Notify the admin about the migration process if they are using the repo.
        if (!empty($instances)) {
            repository_alfresco_admin_security_key_notice();
        }
        upgrade_plugin_savepoint(true, 2014020301, 'repository', 'alfresco');
    }
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
开发者ID:mercysmart,项目名称:naikelas,代码行数:32,代码来源:upgrade.php

示例2: toHtml

 public function toHtml()
 {
     global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
     $id = $this->_attributes['id'];
     $elname = $this->_attributes['name'];
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     if (!($draftitemid = (int) $this->getValue())) {
         // no existing area info provided - let's use fresh new draft area
         $draftitemid = file_get_unused_draft_itemid();
         $this->setValue($draftitemid);
     }
     if ($COURSE->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($COURSE->id);
     }
     $client_id = uniqid();
     $args = new stdClass();
     // Need these three to filter repositories list.
     $args->accepted_types = $this->_options['accepted_types'] ? $this->_options['accepted_types'] : '*';
     $args->return_types = $this->_options['return_types'];
     $args->itemid = $draftitemid;
     $args->maxbytes = 0;
     $args->context = $PAGE->context;
     $args->buttonname = $elname . 'choose';
     $args->elementname = $elname;
     // We can only tell the filepicker that we want FILE_REFERENCE repos
     // and which specific repo types we don't want. So here we build a list
     // of all FILE_REFERENCE supplying repos that aren't thebox to force
     // it to only display that one.
     $refrepos = repository::get_instances(array('currentcontext' => $PAGE->context, 'return_types' => FILE_REFERENCE));
     $disabled = array();
     foreach ($refrepos as $repo) {
         if (($name = $repo->get_typename()) != $this->repo) {
             $disabled[] = $name;
         }
     }
     $args->disable_types = $disabled;
     $html = $this->_getTabs();
     $fp = new file_picker($args);
     $options = $fp->options;
     $options->context = $PAGE->context;
     $html .= $OUTPUT->render($fp);
     $html .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" value="' . $draftitemid . '" class="filepickerhidden"/>';
     $module = array('name' => 'form_filepicker', 'fullpath' => '/lib/form/filepicker.js', 'requires' => array('core_filepicker', 'node', 'node-event-simulate', 'core_dndupload'));
     $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
     $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array('env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, 'subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey()));
     // non js file picker
     $html .= '<noscript>';
     $html .= "<div><object type='text/html' data='{$nonjsfilepicker}' height='160' width='600' style='border:1px solid #000'></object></div>";
     $html .= '</noscript>';
     return $html;
 }
开发者ID:eSrem,项目名称:moodle-mod_mediagallery,代码行数:55,代码来源:uploader.php

示例3: xmldb_repository_boxnet_upgrade

/**
 * Upgrade function.
 *
 * @param int $oldversion the version we are upgrading from.
 * @return bool result
 */
function xmldb_repository_boxnet_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2013110503) {
        // Delete old user preferences containing auth tokens.
        $DB->delete_records('user_preferences', array('name' => 'boxnet__auth_token'));
        upgrade_plugin_savepoint(true, 2013110503, 'repository', 'boxnet');
    }
    if ($oldversion < 2013110700) {
        require_once $CFG->dirroot . '/repository/lib.php';
        require_once $CFG->dirroot . '/repository/boxnet/db/upgradelib.php';
        $clientid = get_config('boxnet', 'clientid');
        $clientsecret = get_config('boxnet', 'clientsecret');
        // Only proceed if the repository hasn't been set for APIv2 yet.
        if ($clientid === false && $clientsecret === false) {
            $params = array();
            $params['context'] = array();
            $params['onlyvisible'] = false;
            $params['type'] = 'boxnet';
            $instances = repository::get_instances($params);
            // Notify the admin about the migration process if they are using the repo.
            if (!empty($instances)) {
                repository_boxnet_admin_upgrade_notification();
            }
            // Hide the repository.
            $repositorytype = repository::get_type_by_typename('boxnet');
            if (!empty($repositorytype)) {
                $repositorytype->update_visibility(false);
            }
        }
        upgrade_plugin_savepoint(true, 2013110700, 'repository', 'boxnet');
    }
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:51,代码来源:upgrade.php

示例4: toHtml

    /**
     * Returns HTML for this form element.
     *
     * @return string
     */
    function toHtml()
    {
        global $PAGE, $OUTPUT;
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        if ($this->_hiddenLabel) {
            $this->_generateId();
            $str = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
        } else {
            $str = HTML_QuickForm_Text::toHtml();
        }
        if (empty($this->_options['usefilepicker'])) {
            return $str;
        }
        $client_id = uniqid();
        $args = new stdClass();
        $args->accepted_types = '*';
        $args->return_types = FILE_EXTERNAL;
        $args->context = $PAGE->context;
        $args->client_id = $client_id;
        $args->env = 'url';
        $refrepos = repository::get_instances(array('currentcontext' => $PAGE->context, 'return_types' => FILE_EXTERNAL));
        $disabled = array();
        foreach ($refrepos as $repo) {
            if (($name = $repo->get_typename()) != $this->_options['repo']) {
                $disabled[] = $name;
            }
        }
        $args->disable_types = $disabled;
        $fp = new file_picker($args);
        $options = $fp->options;
        if (count($options->repositories) > 0) {
            $straddlink = get_string('choosealink', 'repository');
            $str .= <<<EOD
<button id="filepicker-button-{$client_id}" class="visibleifjs">
{$straddlink}
</button>
EOD;
        }
        // print out file picker
        $str .= $OUTPUT->render($fp);
        $module = array('name' => 'form_url', 'fullpath' => '/lib/form/url.js', 'requires' => array('core_filepicker'));
        $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module);
        return $str;
    }
开发者ID:eSrem,项目名称:moodle-mod_mediagallery,代码行数:50,代码来源:limitedurl.php

示例5: test_install_repository

 /**
  * Installing repository tests
  *
  * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
  */
 public function test_install_repository()
 {
     global $CFG, $DB;
     $this->resetAfterTest(true);
     $syscontext = context_system::instance();
     $repositorypluginname = 'boxnet';
     // override repository permission
     $capability = 'repository/' . $repositorypluginname . ':view';
     $allroles = $DB->get_records_menu('role', array(), 'id', 'archetype, id');
     assign_capability($capability, CAP_ALLOW, $allroles['guest'], $syscontext->id, true);
     $plugintype = new repository_type($repositorypluginname);
     $pluginid = $plugintype->create(false);
     $this->assertInternalType('int', $pluginid);
     $args = array();
     $args['type'] = $repositorypluginname;
     $repos = repository::get_instances($args);
     $repository = reset($repos);
     $this->assertInstanceOf('repository', $repository);
     $info = $repository->get_meta();
     $this->assertEquals($repositorypluginname, $info->type);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:26,代码来源:repositorylib_test.php

示例6: test_delete_original_file_from_draft

 /**
  * Testing deleting original files.
  *
  * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 public function test_delete_original_file_from_draft()
 {
     global $USER, $DB;
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     $user = $generator->create_user();
     $usercontext = context_user::instance($user->id);
     $USER = $DB->get_record('user', array('id' => $user->id));
     $repositorypluginname = 'user';
     $args = array();
     $args['type'] = $repositorypluginname;
     $repos = repository::get_instances($args);
     $userrepository = reset($repos);
     $this->assertInstanceOf('repository', $userrepository);
     $fs = get_file_storage();
     $syscontext = context_system::instance();
     $filecontent = 'User file content';
     // Create a user private file.
     $userfilerecord = new stdClass();
     $userfilerecord->contextid = $usercontext->id;
     $userfilerecord->component = 'user';
     $userfilerecord->filearea = 'private';
     $userfilerecord->itemid = 0;
     $userfilerecord->filepath = '/';
     $userfilerecord->filename = 'userfile.txt';
     $userfilerecord->source = 'test';
     $userfile = $fs->create_file_from_string($userfilerecord, $filecontent);
     $userfileref = $fs->pack_reference($userfilerecord);
     $contenthash = $userfile->get_contenthash();
     $filerecord = array('contextid' => $syscontext->id, 'component' => 'core', 'filearea' => 'phpunit', 'itemid' => 0, 'filepath' => '/', 'filename' => 'test.txt');
     // Create a file reference.
     $fileref = $fs->create_file_from_reference($filerecord, $userrepository->id, $userfileref);
     $this->assertInstanceOf('stored_file', $fileref);
     $this->assertEquals($userrepository->id, $fileref->get_repository_id());
     $this->assertSame($userfile->get_contenthash(), $fileref->get_contenthash());
     $this->assertEquals($userfile->get_filesize(), $fileref->get_filesize());
     $this->assertRegExp('#' . $userfile->get_filename() . '$#', $fileref->get_reference_details());
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $usercontext->id, 'user', 'private', 0);
     $draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid);
     $this->assertCount(2, $draftfiles);
     $draftfile = $fs->get_file($usercontext->id, 'user', 'draft', $draftitemid, $userfilerecord->filepath, $userfilerecord->filename);
     $draftfile->delete();
     // Save changed file.
     file_save_draft_area_files($draftitemid, $usercontext->id, 'user', 'private', 0);
     // The file reference should be a regular moodle file now.
     $fileref = $fs->get_file($syscontext->id, 'core', 'phpunit', 0, '/', 'test.txt');
     $this->assertFalse($fileref->is_external_file());
     $this->assertSame($contenthash, $fileref->get_contenthash());
     $this->assertEquals($filecontent, $fileref->get_content());
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:57,代码来源:filelib_test.php

示例7: type_config_form

    /**
     * Add Plugin settings input to Moodle form
     *
     * @param moodleform $mform
     * @param string $classname
     */
    public static function type_config_form($mform, $classname = 'repository') {
        global $CFG;
        parent::type_config_form($mform);
        $public_account = get_config('boxnet', 'public_account');
        $api_key = get_config('boxnet', 'api_key');
        if (empty($api_key)) {
            $api_key = '';
        }
        $strrequired = get_string('required');
        $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'), array('value'=>$api_key,'size' => '40'));
        $mform->addRule('api_key', $strrequired, 'required', null, 'client');
        $mform->addElement('static', null, '',  get_string('information','repository_boxnet'));

        //retrieve the flickr instances
        $params = array();
        $params['context'] = array();
        //$params['currentcontext'] = $this->context;
        $params['onlyvisible'] = false;
        $params['type'] = 'boxnet';
        $instances = repository::get_instances($params);
        if (empty($instances)) {
            $callbackurl = get_string('callbackwarning', 'repository_boxnet');
            $mform->addElement('static', null, '',  $callbackurl);
        } else {
            $instance = array_shift($instances);
            $callbackurl = $CFG->wwwroot.'/repository/repository_callback.php?repo_id='.$instance->id;
            $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_boxnet', $callbackurl));
        }
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:35,代码来源:lib.php

示例8: catch

                 echo $client_id;
             } else {
                 echo '';
             }
         } else {
             echo '';
         }
         exit;
     } catch (repository_exception $e) {
         $err->e = $e->getMessage();
         die(json_encode($err));
     }
     break;
 case 'gsearch':
     //  Global Search
     $repos = repository::get_instances(array(get_context_instance_by_id($ctx_id), get_system_context()));
     $list = array();
     foreach ($repos as $repo) {
         if ($repo->global_search()) {
             try {
                 $ret = $repo->search($search_text);
                 array_walk($ret['list'], 'repository_attach_id', $repo->id);
                 // See function below
                 $tmp = array_merge($list, $ret['list']);
                 $list = $tmp;
             } catch (repository_exception $e) {
                 $err->e = $e->getMessage();
                 die(json_encode($err));
             }
         }
     }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:ws.php

示例9: display_instances_list

 /**
  * Display a repository instance list (with edit/delete/create links)
  * @global object $CFG
  * @global object $USER
  * @param object $context the context for which we display the instance
  * @param string $typename if set, we display only one type of instance
  */
 public static function display_instances_list($context, $typename = null)
 {
     global $CFG, $USER, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     //if the context is SYSTEM, so we call it from administration page
     $admin = $context->id == SYSCONTEXTID ? true : false;
     if ($admin) {
         $baseurl = "{$CFG->httpswwwroot}/{$CFG->admin}/repositoryinstance.php?sesskey=" . sesskey();
         $output .= "<div ><h2 style='text-align: center'>" . get_string('siteinstances', 'repository') . " ";
         $output .= "</h2></div>";
     } else {
         $baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&amp;sesskey=' . sesskey();
     }
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'repository');
     $settingsstr = get_string('settings');
     $deletestr = get_string('delete');
     $updown = get_string('updown', 'repository');
     //retrieve list of instances. In administration context we want to display all
     //instances of a type, even if this type is not visible. In course/user context we
     //want to display only visible instances, but for every type types. The repository_get_instances()
     //third parameter displays only visible type.
     $instances = repository::get_instances(array($context), null, !$admin, $typename);
     $instancesnumber = count($instances);
     $alreadyplugins = array();
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, $deletestr, $settingsstr);
     $table->align = array('left', 'left', 'center', 'center');
     $table->data = array();
     $updowncount = 1;
     foreach ($instances as $i) {
         $settings = '';
         $delete = '';
         $settings .= '<a href="' . $baseurl . '&amp;type=' . $typename . '&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
         if (!$i->readonly) {
             $delete .= '<a href="' . $baseurl . '&amp;type=' . $typename . '&amp;delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
         }
         $type = repository::get_type_by_id($i->options['typeid']);
         $table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
         //display a grey row if the type is defined as not visible
         if (isset($type) && !$type->get_visible()) {
             $table->rowclasses[] = 'dimmed_text';
         } else {
             $table->rowclasses[] = '';
         }
         if (!in_array($i->name, $alreadyplugins)) {
             $alreadyplugins[] = $i->name;
         }
     }
     $output .= $OUTPUT->table($table);
     $instancehtml = '<div>';
     $addable = 0;
     //if no type is set, we can create all type of instance
     if (!$typename) {
         $instancehtml .= '<h3>';
         $instancehtml .= get_string('createrepository', 'repository');
         $instancehtml .= '</h3><ul>';
         $types = repository::get_editable_types($context);
         foreach ($types as $type) {
             if (!empty($type) && $type->get_visible()) {
                 $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                 if (!empty($instanceoptionnames)) {
                     $instancehtml .= '<li><a href="' . $baseurl . '&amp;new=' . $type->get_typename() . '">' . get_string('createxxinstance', 'repository', get_string('repositoryname', 'repository_' . $type->get_typename())) . '</a></li>';
                     $addable++;
                 }
             }
         }
         $instancehtml .= '</ul>';
     } else {
         $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
         if (!empty($instanceoptionnames)) {
             //create a unique type of instance
             $addable = 1;
             $instancehtml .= "<form action='" . $baseurl . "&amp;new=" . $typename . "' method='post'>\n                    <p style='text-align:center'><input type='submit' value='" . get_string('createinstance', 'repository') . "'/></p>\n                    </form>";
         }
     }
     if ($addable) {
         $instancehtml .= '</div>';
         $output .= $instancehtml;
     }
     $output .= $OUTPUT->box_end();
     //print the list + creation links
     print $output;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:91,代码来源:lib.php

示例10: test_delete_reference_one_symlink_does_not_rule_them_all

 /**
  * Calling stored_file::delete_reference() on a reference file does not affect other
  * symlinks to the same original
  */
 public function test_delete_reference_one_symlink_does_not_rule_them_all()
 {
     $this->resetAfterTest(true);
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $repo = reset($repos);
     // create two aliases linking the same original
     $originalfile = null;
     foreach ($fs->get_area_files($user->ctxid, 'user', 'private') as $areafile) {
         if (!$areafile->is_directory()) {
             $originalfile = $areafile;
             break;
         }
     }
     $this->assertInstanceOf('stored_file', $originalfile);
     // calling delete_reference() on a non-reference file
     $originalrecord = array('contextid' => $originalfile->get_contextid(), 'component' => $originalfile->get_component(), 'filearea' => $originalfile->get_filearea(), 'itemid' => $originalfile->get_itemid(), 'filepath' => $originalfile->get_filepath(), 'filename' => $originalfile->get_filename());
     $aliasrecord = $this->generate_file_record();
     $aliasrecord->filepath = '/A/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $aliasfile1 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     $aliasrecord->filepath = '/B/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $aliasfile2 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // refetch A/symlink.txt
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertTrue($symlink1->is_external_file());
     // unlink the A/symlink.txt
     $symlink1->delete_reference();
     $this->assertFalse($symlink1->is_external_file());
     // make sure that B/symlink.txt has not been affected
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertTrue($symlink2->is_external_file());
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:41,代码来源:file_storage_test.php

示例11: array

    echo ' <input name="draftpath" type="hidden" value="'.s($draftpath).'" />';
    echo ' <input name="savepath" type="hidden" value="'.s($savepath).'" />';
    echo ' <input type="submit" value="'.s(get_string('download', 'repository')).'" />';
    echo '</div>';
    echo '</form>';
    echo $OUTPUT->footer();
    break;

default:
case 'plugins':
    $params = array();
    $params['context'] = array($user_context, get_system_context());
    $params['currentcontext'] = $PAGE->context;
    $params['return_types'] = FILE_INTERNAL;

    $repos = repository::get_instances($params);
    echo $OUTPUT->header();
    echo html_writer::link($home_url->out(false), get_string('backtodraftfiles', 'repository'));
    echo '<div>';
    echo '<ul>';
    foreach($repos as $repo) {
        $info = $repo->get_meta();

        $aurl = clone($url);
        $aurl->params(array('savepath'=>$savepath, 'action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));

        echo '<li>';
        echo '<img src="'.$info->icon.'" alt="'.$info->name.'" width="16" height="16" /> ';
        echo html_writer::link($aurl, $info->name);
        echo '</li>';
    }
开发者ID:nicusX,项目名称:moodle,代码行数:31,代码来源:filepicker.php

示例12: display_instances_list

 /**
  * Display a repository instance list (with edit/delete/create links)
  *
  * @static
  * @param stdClass $context the context for which we display the instance
  * @param string $typename if set, we display only one type of instance
  */
 public static function display_instances_list($context, $typename = null)
 {
     global $CFG, $USER, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     //if the context is SYSTEM, so we call it from administration page
     $admin = $context->id == SYSCONTEXTID ? true : false;
     if ($admin) {
         $baseurl = new moodle_url('/' . $CFG->admin . '/repositoryinstance.php', array('sesskey' => sesskey()));
         $output .= $OUTPUT->heading(get_string('siteinstances', 'repository'));
     } else {
         $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid' => $context->id, 'sesskey' => sesskey()));
     }
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'repository');
     $settingsstr = get_string('settings');
     $deletestr = get_string('delete');
     // Retrieve list of instances. In administration context we want to display all
     // instances of a type, even if this type is not visible. In course/user context we
     // want to display only visible instances, but for every type types. The repository::get_instances()
     // third parameter displays only visible type.
     $params = array();
     $params['context'] = array($context);
     $params['currentcontext'] = $context;
     $params['return_types'] = 0;
     $params['onlyvisible'] = !$admin;
     $params['type'] = $typename;
     $instances = repository::get_instances($params);
     $instancesnumber = count($instances);
     $alreadyplugins = array();
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr);
     $table->align = array('left', 'left', 'center', 'center');
     $table->data = array();
     $updowncount = 1;
     foreach ($instances as $i) {
         $settings = '';
         $delete = '';
         $type = repository::get_type_by_id($i->options['typeid']);
         if ($type->get_contextvisibility($context)) {
             if (!$i->readonly) {
                 $settingurl = new moodle_url($baseurl);
                 $settingurl->param('type', $i->options['type']);
                 $settingurl->param('edit', $i->id);
                 $settings .= html_writer::link($settingurl, $settingsstr);
                 $deleteurl = new moodle_url($baseurl);
                 $deleteurl->param('delete', $i->id);
                 $deleteurl->param('type', $i->options['type']);
                 $delete .= html_writer::link($deleteurl, $deletestr);
             }
         }
         $type = repository::get_type_by_id($i->options['typeid']);
         $table->data[] = array(format_string($i->name), $type->get_readablename(), $settings, $delete);
         //display a grey row if the type is defined as not visible
         if (isset($type) && !$type->get_visible()) {
             $table->rowclasses[] = 'dimmed_text';
         } else {
             $table->rowclasses[] = '';
         }
         if (!in_array($i->name, $alreadyplugins)) {
             $alreadyplugins[] = $i->name;
         }
     }
     $output .= html_writer::table($table);
     $instancehtml = '<div>';
     $addable = 0;
     //if no type is set, we can create all type of instance
     if (!$typename) {
         $instancehtml .= '<h3>';
         $instancehtml .= get_string('createrepository', 'repository');
         $instancehtml .= '</h3><ul>';
         $types = repository::get_editable_types($context);
         foreach ($types as $type) {
             if (!empty($type) && $type->get_visible()) {
                 // If the user does not have the permission to view the repository, it won't be displayed in
                 // the list of instances. Hiding the link to create new instances will prevent the
                 // user from creating them without being able to find them afterwards, which looks like a bug.
                 if (!has_capability('repository/' . $type->get_typename() . ':view', $context)) {
                     continue;
                 }
                 $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                 if (!empty($instanceoptionnames)) {
                     $baseurl->param('new', $type->get_typename());
                     $instancehtml .= '<li><a href="' . $baseurl->out() . '">' . get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_' . $type->get_typename())) . '</a></li>';
                     $baseurl->remove_params('new');
                     $addable++;
                 }
             }
         }
         $instancehtml .= '</ul>';
     } else {
         $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
         if (!empty($instanceoptionnames)) {
             //create a unique type of instance
//.........这里部分代码省略.........
开发者ID:isuruAb,项目名称:moodle,代码行数:101,代码来源:lib.php

示例13: test_get_external_files

 public function test_get_external_files()
 {
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $userrepository = reset($repos);
     $this->assertInstanceOf('repository', $userrepository);
     // This should break on oracle.
     $fs->get_external_files($userrepository->id, 'id');
     // TODO MDL-33368 Verify result!!
 }
开发者ID:nicusX,项目名称:moodle,代码行数:11,代码来源:file_storage_test.php

示例14: xmldb_hotpot_locate_externalfile

function xmldb_hotpot_locate_externalfile($contextid, $component, $filearea, $itemid, $filepath, $filename)
{
    global $CFG, $DB;
    if (!class_exists('repository')) {
        return false;
        // Moodle <= 2.2 has no repositories
    }
    static $repositories = null;
    if ($repositories === null) {
        $exclude_types = array('recent', 'upload', 'user', 'areafiles');
        $repositories = repository::get_instances();
        foreach (array_keys($repositories) as $id) {
            if (method_exists($repositories[$id], 'get_typename')) {
                $type = $repositories[$id]->get_typename();
            } else {
                $type = $repositories[$id]->options['type'];
            }
            if (in_array($type, $exclude_types)) {
                unset($repositories[$id]);
            }
        }
        // ensure upgraderunning is set
        if (empty($CFG->upgraderunning)) {
            $CFG->upgraderunning = null;
        }
    }
    // get file storage
    $fs = get_file_storage();
    // the following types repository use encoded params
    $encoded_types = array('user', 'areafiles', 'coursefiles');
    foreach ($repositories as $id => $repository) {
        // "filesystem" path is in plain text, others are encoded
        if (method_exists($repositories[$id], 'get_typename')) {
            $type = $repositories[$id]->get_typename();
        } else {
            $type = $repositories[$id]->options['type'];
        }
        $encodepath = in_array($type, $encoded_types);
        // save $root_path, because it may get messed up by
        // $repository->get_listing($path), if $path is non-existant
        if (method_exists($repository, 'get_rootpath')) {
            $root_path = $repository->get_rootpath();
        } else {
            if (isset($repository->root_path)) {
                $root_path = $repository->root_path;
            } else {
                $root_path = false;
            }
        }
        // get repository type
        switch (true) {
            case isset($repository->options['type']):
                $type = $repository->options['type'];
                break;
            case isset($repository->instance->typeid):
                $type = repository::get_type_by_id($repository->instance->typeid);
                $type = $type->get_typename();
                break;
            default:
                $type = '';
                // shouldn't happen !!
        }
        $path = $filepath;
        $source = trim($filepath . $filename, '/');
        // setup $params for path encoding, if necessary
        $params = array();
        if ($encodepath) {
            $listing = $repository->get_listing();
            switch (true) {
                case isset($listing['list'][0]['source']):
                    $param = 'source';
                    break;
                    // file
                // file
                case isset($listing['list'][0]['path']):
                    $param = 'path';
                    break;
                    // dir
                // dir
                default:
                    return false;
                    // shouldn't happen !!
            }
            $params = file_storage::unpack_reference($listing['list'][0][$param], true);
            $params['filepath'] = '/' . $path . ($path == '' ? '' : '/');
            $params['filename'] = '.';
            // "." signifies a directory
            $path = file_storage::pack_reference($params);
        }
        // reset $repository->root_path (filesystem repository only)
        if ($root_path) {
            $repository->root_path = $root_path;
        }
        // unset upgraderunning because it can cause get_listing() to fail
        $upgraderunning = $CFG->upgraderunning;
        $CFG->upgraderunning = null;
        // Note: we use "@" to suppress warnings in case $path does not exist
        $listing = @$repository->get_listing($path);
        // restore upgraderunning flag
        $CFG->upgraderunning = $upgraderunning;
//.........这里部分代码省略.........
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:101,代码来源:upgrade.php

示例15: foreach

     echo '<div><ul>';
     foreach ($repos as $repo) {
         $info = $repo->get_meta();
         $icon = new moodle_action_icon();
         $icon->image->src = $info->icon;
         $icon->image->style = 'height: 16px; width: 16px;';
         $icon->link->url = clone $url;
         $icon->link->url->params(array('action' => 'list', 'repo_id' => $info->id));
         $icon->linktext = $info->name;
         echo '<li>' . $OUTPUT->action_icon($icon) . '</li>';
     }
     echo '</ul></div>';
     break;
 default:
     $user_context = get_context_instance(CONTEXT_USER, $USER->id);
     $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
     print_header();
     $fs = get_file_storage();
     $context = get_context_instance(CONTEXT_USER, $USER->id);
     $files = $fs->get_area_files($context->id, 'user_draft', $itemid);
     if (empty($files)) {
         echo get_string('nofilesattached', 'repository');
     } else {
         echo '<ul>';
         foreach ($files as $file) {
             if ($file->get_filename() != '.') {
                 $drafturl = new moodle_url($CFG->httpswwwroot . '/draftfile.php/' . $context->id . '/user_draft/' . $itemid . '/' . $file->get_filename());
                 echo '<li><a href="' . $drafturl->out() . '">' . $file->get_filename() . '</a> ';
                 echo '<a href="' . $CFG->httpswwwroot . '/repository/filepicker.php?action=deletedraft&amp;itemid=' . $itemid . '&amp;ctx_id=' . $ctx_id . '&amp;title=' . $file->get_filename() . '"><img src="' . $OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" /></a></li>';
             }
         }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:filepicker.php


注:本文中的repository::get_instances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。