- Moodle 1.9 Extension Development
- Jonathan Moore Michael Churchward
- 439字
- 2021-08-06 17:24:06
Using a block as a code container
Sometimes we will want to make additions to Moodle that don't necessarily have a user interface, or at least a block interface. In these situations we can still benefit from creating a block. Firstly, the block is one of the simplest plugins that we can make for Moodle. Secondly, blocks have a simple, well-understood installation procedure. Moodle also provides many facilities for plugins, such as configuration and database storage. And finally, it gives us a simple and standardized method for dealing with version upgrades.
Let's take a look at the repository block, which is part of a suite of additions to Moodle that we call the Enterprise Learning Intelligence Suite (ELIS). The repository block is never used to display content. It simply acts as a storage container for capabilities associated with the Alfresco integration. The Alfresco integration itself is a separate set of functions contained in its own directory. Alfresco is a popular and powerful open source document management system written in Java.
Creating a block stub for our container
Let's take a look at some code. In this first section of code we are looking at the block's main file, block_repository.php
. This file uses the PHPDoc format for commenting code, which can be used with tools like PHPXref to automatically generate documentation. In our initial function, we again define the minimum values for a block: title and version:
<?php // $Id: block_repository.php,v 1.2 2009/04/22 15:14:08 jfilip Exp $ /** * Class for the repository control block. * * @version $Id: block_repository.php,v 1.2 2009/04/22 15:14:08 jfilip Exp $ * @author Open Knowledge Technologies - http://www.oktech.ca/ * @author Remote Learner - http://www.remote-learner.net/ * @author Justin Filip <jfilip@oktech.ca> */ class block_repository extends block_base { function block_repository() { $this->title = get_string('blockname', 'block_repository'); $this->version = 2009042100; } //function block_repository
In the final section of our main file, we make sure that our block content is set to blank values so that the block will never display on screen:
function get_content() {
if($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = ''; $this->content->footer = '';
return $this->content;
}
Creating capabilities for our container
As we can see, there is not much happening in the main block file. This is evidence of the fact that we are just using the block structure as a container. Next, let's take a look at the functional component of the block, which is defined in the db
folder. We have a single file defined called access.php
. This functions just as it does in our Hello World block. We simply define an array of access capabilities. Note that in the case of this block, we are using the riskbitmask
value in the array. This provides the administrator with information about the risk associated with giving this capability to a particular role:
$block_repository_capabilities = array(
'block/repository:createsitecontent' => array(
'riskbitmask' => RISK_XSS| RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
),
- TensorFlow與自然語言處理應(yīng)用
- Tomcat 6 Developer's Guide
- 印象筆記留給你的空間2.0:個人知識管理實(shí)踐指南
- iPhone User Interface Cookbook
- BackTrack 5 Wireless Penetration Testing Beginner's Guide
- 詳解AutoCAD 2022電氣設(shè)計(第6版)
- 說服力:工作型PPT該這樣做(第2版)
- UG NX 12.0完全自學(xué)寶典
- Photoshop電商設(shè)計與產(chǎn)品精修實(shí)戰(zhàn)(微視頻版)
- Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide
- Photoshop CG 古風(fēng)插畫繪制技法精解
- 剪映:短、中、長視頻剪輯全攻略(手機(jī)版+電腦版)
- 基于深度學(xué)習(xí)的自然語言處理
- Photoshop人像攝影后期處理技法100問
- AutoCAD 2022中文版園林景觀設(shè)計從入門到精通