了解Moodle $ context [英] Understanding Moodle $context

查看:118
本文介绍了了解Moodle $ context的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 Moodle文档:

上下文是Moodle中可以分配角色的空间.

A context is a space in Moodle where roles can be assigned.

我知道上下文是用于管理Moodle对象的逻辑空间.

I understand that a context is a logical space used to manage Moodle objects.

我开发了一个自定义块插件,带有文件上传功能,其中使用了file_prepare_draft_areafile_save_draft_area_files函数.必须传递一个$context参数,我真的不知道应该传递哪个上下文? 我想这意味着我应该将块插件上传的文件放在哪个逻辑空间? 我认为,最合乎逻辑的做法是将上传的文件存储在与我的块插件相关的上下文中.

I developed a custom block plugin with a file upload where I use file_prepare_draft_area andfile_save_draft_area_files functions.There is a $context parameter that must be passed and I am don't really know what context should I pass ? This mean, I guess, in which logical space should I put my block plugin uploaded files ? In my opinion, the most logical would be store the uploaded files in a context related to my block plugin.

我尝试使用context_block :: instance($ instanceid),但我不知道如何获取$ instanceid参数.

I tried to use context_block::instance($instanceid) but I don't know how to get $instanceid param.

  • 在这种情况下,我应该使用哪个上下文?
  • 如何获取?

推荐答案

上下文类型如下:

  • 系统
  • 课程类别
  • 课程
  • 活动模块
  • 阻止
  • 用户

上下文层次结构为: 系统=>课程类别=>课程=>活动模块

The hierarchy of contexts are: System => Course category => Course => Activity module

块上下文可以出现在课程中或站点"课程中. 用户上下文不在课程之内.

Block contexts can appear within courses or within the 'site' course. User contexts are outside of courses.

如果您希望将文件绑定到块的特定实例(例如,以便在删除块时将它们自动删除,并且可以将来自块的不同实例的文件分开),则应使用块上下文(但是您必须将代码块的instanceid传递给子页面,才能使用它来获取上下文:

If you want the files tied to a specific instance of the block (e.g. so they are deleted automatically when the block is deleted and you can keep the files from different instances of the block separate), then you should use the block context (but you'll have to pass the instanceid of the block to the sub-pages in order to use this to get the context:

$context = context_block::instance($blockinstanceid);

如果您希望文件与课程绑定-因此课程中该块的所有实例共享相同的文件空间,并且仅在删除整个课程时才删除文件,然后使用课程上下文(将课程ID传递到子页面作为参数,然后使用:

If you want the files tied to the course - so all instances of the block in the course share the same file space and the files are only deleted when the whole course is deleted, then use the course context (pass the courseid into the subpages, as a param, then use:

$context = context_course::instance($courseid);

但是,如果要在站点上的所有块之间共享该文件区域,则需要使用系统上下文:

If, however, you want to share that file area across all blocks on the site, then the system context is what you want:

$context = context_system();

这篇关于了解Moodle $ context的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆