- 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
)
),
- Celtx: Open Source Screenwriting Beginner's Guide
- Photoshop CC摳圖+修圖+調色+合成+特效標準培訓教程(全視頻微課版)
- 穿越Photoshop CC
- 鍵盤錄入技術(第2版)
- ADOBE FLASH PROFESSIONAL CS6 標準培訓教材
- 通達信炒股軟件從入門到精通(第2版)
- 剪映短視頻剪輯與運營全攻略:視頻剪輯+音頻處理+后期特效+運營管理
- 中文版Photoshop CS5實用教程(第2版)
- 中文版Premiere Pro CS6視頻編輯(慕課版)
- Photoshop人像精修秘笈
- 電磁場數值計算及基于FreeFEM的編程實現
- 同花順軟件操作技巧與實戰指南
- Android APP開發實戰:從規劃到上線全程詳解
- 從CAD到CAE設計方法
- Animate核心應用案例教程:Animate 2020(全彩慕課版)