mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00

even non-course and sticky blocks. The parent context is block_instances.parentcontextid. The block context should be used for checking permissions directly related to the block, like moodle/block:view or moodle/site:manageblocks. However, if the block is displaying information about the current page, for example the participants block showing who 'here', then it may be better to use the context of the page where the bloack is appearing - in other words $this->page->context - to check permissions about the user's ability to see participants here. Or, if the block is displaying something stronly related to courses, for example, a course meny block, the block should probably use the context for $this->page->course to check permissions.
800 lines
26 KiB
PHP
800 lines
26 KiB
PHP
<?php // $Id$
|
|
|
|
/**
|
|
* This file contains the parent class for moodle blocks, block_base.
|
|
*
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
* @package blocks
|
|
*/
|
|
|
|
/// Constants
|
|
|
|
/**
|
|
* Block type of list. Contents of block should be set as an associative array in the content object as items ($this->content->items). Optionally include footer text in $this->content->footer.
|
|
*/
|
|
define('BLOCK_TYPE_LIST', 1);
|
|
|
|
/**
|
|
* Block type of text. Contents of block should be set to standard html text in the content object as items ($this->content->text). Optionally include footer text in $this->content->footer.
|
|
*/
|
|
define('BLOCK_TYPE_TEXT', 2);
|
|
|
|
/**
|
|
* Class for describing a moodle block, all Moodle blocks derive from this class
|
|
*
|
|
* @author Jon Papaioannou
|
|
* @package blocks
|
|
*/
|
|
class block_base {
|
|
|
|
/**
|
|
* Internal var for storing/caching translated strings
|
|
* @var string $str
|
|
*/
|
|
var $str;
|
|
|
|
/**
|
|
* The title of the block to be displayed in the block title area.
|
|
* @var string $title
|
|
*/
|
|
var $title = NULL;
|
|
|
|
/**
|
|
* The type of content that this block creates. Currently support options - BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT
|
|
* @var int $content_type
|
|
*/
|
|
var $content_type = BLOCK_TYPE_TEXT;
|
|
|
|
/**
|
|
* An object to contain the information to be displayed in the block.
|
|
* @var stdObject $content
|
|
*/
|
|
var $content = NULL;
|
|
|
|
/**
|
|
* A string generated by {@link _add_edit_controls()} to display block manipulation links when the user is in editing mode.
|
|
* @var string $edit_controls
|
|
*/
|
|
var $edit_controls = NULL;
|
|
|
|
/**
|
|
* The current version that the block type defines.
|
|
* @var string $version
|
|
*/
|
|
var $version = NULL;
|
|
|
|
/**
|
|
* The initialized instance of this block object.
|
|
* @var block $instance
|
|
*/
|
|
var $instance = NULL;
|
|
|
|
/**
|
|
* The page that this block is appearing on.
|
|
* @var moodle_page
|
|
*/
|
|
public $page = NULL;
|
|
|
|
/**
|
|
* This blocks's context.
|
|
* @var stdClass
|
|
*/
|
|
public $context = NULL;
|
|
|
|
/**
|
|
* An object containing the instance configuration information for the current instance of this block.
|
|
* @var stdObject $config
|
|
*/
|
|
var $config = NULL;
|
|
|
|
/**
|
|
* How often the cronjob should run, 0 if not at all.
|
|
* @var int $cron
|
|
*/
|
|
|
|
var $cron = NULL;
|
|
|
|
/// Class Functions
|
|
|
|
/**
|
|
* The class constructor
|
|
*
|
|
*/
|
|
function block_base() {
|
|
$this->init();
|
|
}
|
|
|
|
/**
|
|
* Fake constructor to keep PHP5 happy
|
|
*
|
|
*/
|
|
function __construct() {
|
|
$this->block_base();
|
|
}
|
|
|
|
/**
|
|
* Function that can be overridden to do extra cleanup before
|
|
* the database tables are deleted. (Called once per block, not per instance!)
|
|
*/
|
|
function before_delete() {
|
|
}
|
|
|
|
/**
|
|
* Function that can be overridden to do extra setup after a block instance has been
|
|
* restored from backup. For example, it may need to alter any dates that the block
|
|
* stores, if the $restore->course_startdateoffset is set.
|
|
*/
|
|
function after_restore($restore) {
|
|
}
|
|
|
|
/**
|
|
* Enable custom instance data section in backup and restore.
|
|
*
|
|
* If return true, then {@link instance_backup()} and
|
|
* {@link instance_restore()} will be called during
|
|
* backup/restore routines.
|
|
*
|
|
* @return boolean
|
|
**/
|
|
function backuprestore_instancedata_used() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Allows the block class to have a backup routine. Handy
|
|
* when the block has its own tables that have foreign keys to
|
|
* other tables (example: user table).
|
|
*
|
|
* Note: at the time of writing this comment, the indent level
|
|
* for the {@link full_tag()} should start at 5.
|
|
*
|
|
* @param resource $bf Backup File
|
|
* @param object $preferences Backup preferences
|
|
* @return boolean
|
|
**/
|
|
function instance_backup($bf, $preferences) {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Allows the block class to restore its backup routine.
|
|
*
|
|
* Should not return false if data is empty
|
|
* because old backups would not contain block instance backup data.
|
|
*
|
|
* @param object $restore Standard restore object
|
|
* @param object $data Object from backup_getid for this block instance
|
|
* @return boolean
|
|
**/
|
|
function instance_restore($restore, $data) {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Will be called before an instance of this block is backed up, so that any links in
|
|
* in config can be encoded. For example config->text, for the HTML block
|
|
* @return string
|
|
*/
|
|
function get_backup_encoded_config() {
|
|
return base64_encode(serialize($this->config));
|
|
}
|
|
|
|
/**
|
|
* Return the content encoded to support interactivities linking. This function is
|
|
* called automatically from the backup procedure by {@link backup_encode_absolute_links()}.
|
|
*
|
|
* NOTE: There is no block instance when this method is called.
|
|
*
|
|
* @param string $content Content to be encoded
|
|
* @param object $restore Restore preferences object
|
|
* @return string The encoded content
|
|
**/
|
|
function encode_content_links($content, $restore) {
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
|
|
* function in order to decode contents of this block from the backup
|
|
* format to destination site/course in order to mantain inter-activities
|
|
* working in the backup/restore process.
|
|
*
|
|
* This is called from {@link restore_decode_content_links()} function in the restore process.
|
|
*
|
|
* NOTE: There is no block instance when this method is called.
|
|
*
|
|
* @param object $restore Standard restore object
|
|
* @return boolean
|
|
**/
|
|
function decode_content_links_caller($restore) {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Return content decoded to support interactivities linking.
|
|
* This is called automatically from
|
|
* {@link restore_decode_content_links_worker()} function
|
|
* in the restore process.
|
|
*
|
|
* NOTE: There is no block instance when this method is called.
|
|
*
|
|
* @param string $content Content to be dencoded
|
|
* @param object $restore Restore preferences object
|
|
* @return string The dencoded content
|
|
**/
|
|
function decode_content_links($content, $restore) {
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Returns the block name, as present in the class name,
|
|
* the database, the block directory, etc etc.
|
|
*
|
|
* @return string
|
|
*/
|
|
function name() {
|
|
// Returns the block name, as present in the class name,
|
|
// the database, the block directory, etc etc.
|
|
static $myname;
|
|
if ($myname === NULL) {
|
|
$myname = strtolower(get_class($this));
|
|
$myname = substr($myname, strpos($myname, '_') + 1);
|
|
}
|
|
return $myname;
|
|
}
|
|
|
|
/**
|
|
* Parent class version of this function simply returns NULL
|
|
* This should be implemented by the derived class to return
|
|
* the content object.
|
|
*
|
|
* @return stdObject
|
|
*/
|
|
function get_content() {
|
|
// This should be implemented by the derived class.
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* Returns the class $title var value.
|
|
*
|
|
* Intentionally doesn't check if a title is set.
|
|
* This is already done in {@link _self_test()}
|
|
*
|
|
* @return string $this->title
|
|
*/
|
|
function get_title() {
|
|
// Intentionally doesn't check if a title is set. This is already done in _self_test()
|
|
return $this->title;
|
|
}
|
|
|
|
/**
|
|
* Returns the class $content_type var value.
|
|
*
|
|
* Intentionally doesn't check if content_type is set.
|
|
* This is already done in {@link _self_test()}
|
|
*
|
|
* @return string $this->content_type
|
|
*/
|
|
function get_content_type() {
|
|
// Intentionally doesn't check if a content_type is set. This is already done in _self_test()
|
|
return $this->content_type;
|
|
}
|
|
|
|
/**
|
|
* Returns the class $version var value.
|
|
*
|
|
* Intentionally doesn't check if a version is set.
|
|
* This is already done in {@link _self_test()}
|
|
*
|
|
* @return string $this->version
|
|
*/
|
|
function get_version() {
|
|
// Intentionally doesn't check if a version is set. This is already done in _self_test()
|
|
return $this->version;
|
|
}
|
|
|
|
/**
|
|
* Returns true or false, depending on whether this block has any content to display
|
|
* and whether the user has permission to view the block
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function is_empty() {
|
|
if ( !has_capability('moodle/block:view', $this->context) ) {
|
|
return true;
|
|
}
|
|
|
|
$this->get_content();
|
|
return(empty($this->content->text) && empty($this->content->footer));
|
|
}
|
|
|
|
/**
|
|
* First sets the current value of $this->content to NULL
|
|
* then calls the block's {@link get_content()} function
|
|
* to set its value back.
|
|
*
|
|
* @return stdObject
|
|
*/
|
|
function refresh_content() {
|
|
// Nothing special here, depends on content()
|
|
$this->content = NULL;
|
|
return $this->get_content();
|
|
}
|
|
|
|
/**
|
|
* Return a block_contents oject representing the full contents of this block.
|
|
*
|
|
* This internally calls ->get_content(), and then adds the editing controls etc.
|
|
*
|
|
* You probably should not override this method, but instead override
|
|
* {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()},
|
|
* {@link hide_header()}, {@link (get_edit_controls)}, etc.
|
|
*
|
|
* @return block_contents a represntation of the block, for rendering.
|
|
* @since Moodle 2.0.
|
|
*/
|
|
public function get_content_for_output($output) {
|
|
global $CFG;
|
|
|
|
$bc = new block_contents();
|
|
$bc->blockinstanceid = $this->instance->id;
|
|
$bc->blockpositionid = $this->instance->blockpositionid;
|
|
|
|
$attributes = $this->html_attributes();
|
|
if (isset($attributes['id'])) {
|
|
$bc->id = $attributes['id'];
|
|
unset($attributes['id']);
|
|
}
|
|
if (isset($attributes['class'])) {
|
|
$bc->set_classes($attributes['class']);
|
|
unset($attributes['class']);
|
|
}
|
|
$bc->attributes = $attributes;
|
|
|
|
if (!$this->hide_header()) {
|
|
$bc->title = $this->title;
|
|
}
|
|
$bc->content = $this->formatted_contents($output);
|
|
if (!empty($this->content->footer)) {
|
|
$bc->footer = $this->content->footer;
|
|
}
|
|
|
|
if ($this->is_empty() && !$bc->controls) {
|
|
return null;
|
|
}
|
|
|
|
if ($this->page->user_is_editing()) {
|
|
$bc->controls = $this->get_edit_controls($output);
|
|
}
|
|
|
|
if (empty($CFG->allowuserblockhiding)) {
|
|
$bc->collapsible = block_contents::NOT_HIDEABLE;
|
|
} else if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) {
|
|
$bc->collapsible = block_contents::HIDDEN;
|
|
} else {
|
|
$bc->collapsible = block_contents::VISIBLE;
|
|
}
|
|
|
|
$bc->annotation = ''; // TODO
|
|
|
|
return $bc;
|
|
}
|
|
|
|
/**
|
|
* Convert the contents of the block to HTML.
|
|
*
|
|
* This is used by block base classes like block_list to convert the structured
|
|
* $this->content->list and $this->content->icons arrays to HTML. So, in most
|
|
* blocks, you probaby want to override the {@link get_contents()} method,
|
|
* which generates that structured representation of the contents.
|
|
*
|
|
* @param $output The core_renderer to use when generating the output.
|
|
* @return string the HTML that should appearn in the body of the block.
|
|
* @since Moodle 2.0.
|
|
*/
|
|
protected function formatted_contents($output) {
|
|
$this->get_content();
|
|
if (!empty($this->content->text)) {
|
|
return $this->content->text;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the appropriate list of editing icons for this block. This is used
|
|
* to set {@link block_contents::$controls} in {@link get_contents_for_output()}.
|
|
*
|
|
* @param $output The core_renderer to use when generating the output. (Need to get icon paths.)
|
|
* @return an array in the format for {@link block_contents::$controls}
|
|
* @since Moodle 2.0.
|
|
*/
|
|
protected function get_edit_controls($output) {
|
|
global $CFG;
|
|
|
|
$returnurlparam = '&returnurl=' . urlencode($this->page->url->out_returnurl());
|
|
$actionurl = $CFG->wwwroot.'/blocks/action.php?block=' . $this->instance->id .
|
|
'&sesskey=' . sesskey() . $returnurlparam;
|
|
|
|
$controls = array();
|
|
|
|
// Assign roles icon.
|
|
if (has_capability('moodle/role:assign', $this->context)) {
|
|
$controls[] = array('url' => $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$this->context->id,
|
|
'icon' => $output->old_icon_url('i/roles'), 'caption' => get_string('assignroles', 'role'));
|
|
}
|
|
|
|
if ($this->user_can_edit() && $this->page->user_can_edit_blocks()) {
|
|
// Show/hide icon.
|
|
if ($this->instance->visible) {
|
|
$controls[] = array('url' => $actionurl . '&action=hide',
|
|
'icon' => $output->old_icon_url('t/hide'), 'caption' => get_string('hide'));
|
|
} else {
|
|
$controls[] = array('url' => $actionurl . '&action=show',
|
|
'icon' => $output->old_icon_url('t/show'), 'caption' => get_string('show'));
|
|
}
|
|
|
|
// Edit config icon.
|
|
if ($this->instance_allow_multiple() || $this->instance_allow_config()) {
|
|
$editurl = $CFG->wwwroot . '/blocks/edit.php?block=' . $this->instance->id;
|
|
if (!empty($this->instance->blockpositionid)) {
|
|
$editurl .= '&positionid=' . $this->instance->blockpositionid;
|
|
}
|
|
$controls[] = array('url' => $editurl . $returnurlparam,
|
|
'icon' => $output->old_icon_url('t/edit'), 'caption' => get_string('configuration'));
|
|
}
|
|
|
|
// Delete icon.
|
|
if ($this->user_can_addto($this->page)) {
|
|
$controls[] = array('url' => $actionurl . 'action=delete',
|
|
'icon' => $output->old_icon_url('t/delete'), 'caption' => get_string('deletet'));
|
|
}
|
|
|
|
// Move icon.
|
|
$controls[] = array('url' => $this->page->url->out(false, array('moveblockid' => $this->instance->id)),
|
|
'icon' => $output->old_icon_url('t/move'), 'caption' => get_string('move'));
|
|
}
|
|
|
|
return $controls;
|
|
}
|
|
|
|
/**
|
|
* Tests if this block has been implemented correctly.
|
|
* Also, $errors isn't used right now
|
|
*
|
|
* @return boolean
|
|
*/
|
|
|
|
function _self_test() {
|
|
// Tests if this block has been implemented correctly.
|
|
// Also, $errors isn't used right now
|
|
$errors = array();
|
|
|
|
$correct = true;
|
|
if ($this->get_title() === NULL) {
|
|
$errors[] = 'title_not_set';
|
|
$correct = false;
|
|
}
|
|
if (!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) {
|
|
$errors[] = 'invalid_content_type';
|
|
$correct = false;
|
|
}
|
|
//following selftest was not working when roles&capabilities were used from block
|
|
/* if ($this->get_content() === NULL) {
|
|
$errors[] = 'content_not_set';
|
|
$correct = false;
|
|
}*/
|
|
if ($this->get_version() === NULL) {
|
|
$errors[] = 'version_not_set';
|
|
$correct = false;
|
|
}
|
|
|
|
$formats = $this->applicable_formats();
|
|
if (empty($formats) || array_sum($formats) === 0) {
|
|
$errors[] = 'no_formats';
|
|
$correct = false;
|
|
}
|
|
|
|
$width = $this->preferred_width();
|
|
if (!is_int($width) || $width <= 0) {
|
|
$errors[] = 'invalid_width';
|
|
$correct = false;
|
|
}
|
|
return $correct;
|
|
}
|
|
|
|
/**
|
|
* Subclasses should override this and return true if the
|
|
* subclass block has a config_global.html file.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function has_config() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Default behavior: print the config_global.html file
|
|
* You don't need to override this if you're satisfied with the above
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function config_print() {
|
|
// Default behavior: print the config_global.html file
|
|
// You don't need to override this if you're satisfied with the above
|
|
if (!$this->has_config()) {
|
|
return false;
|
|
}
|
|
global $CFG;
|
|
print_simple_box_start('center', '', '', 5, 'blockconfigglobal');
|
|
include($CFG->dirroot.'/blocks/'. $this->name() .'/config_global.html');
|
|
print_simple_box_end();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Default behavior: save all variables as $CFG properties
|
|
* You don't need to override this if you 're satisfied with the above
|
|
*
|
|
* @param array $data
|
|
* @return boolean
|
|
*/
|
|
function config_save($data) {
|
|
foreach ($data as $name => $value) {
|
|
set_config($name, $value);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Default case: the block can be used in all course types
|
|
* @return array
|
|
* @todo finish documenting this function
|
|
*/
|
|
function applicable_formats() {
|
|
// Default case: the block can be used in courses and site index, but not in activities
|
|
return array('all' => true, 'mod' => false, 'tag' => false);
|
|
}
|
|
|
|
|
|
/**
|
|
* Default return is false - header will be shown
|
|
* @return boolean
|
|
*/
|
|
function hide_header() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Return any HTML attributes that you want added to the outer <div> that
|
|
* of the block when it is output.
|
|
* @return array attribute name => value.
|
|
*/
|
|
function html_attributes() {
|
|
return array(
|
|
'id' => 'inst' . $this->instance->id,
|
|
'class' => 'block_' . $this->name()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Given an instance set the class var $instance to it and
|
|
* load class var $config
|
|
* @param block $instance
|
|
* @todo add additional documentation to further explain the format of instance and config
|
|
*/
|
|
function _load_instance($instance, $page) {
|
|
if (!empty($instance->configdata)) {
|
|
$this->config = unserialize(base64_decode($instance->configdata));
|
|
}
|
|
$this->instance = $instance;
|
|
if (isset($instance->context)) {
|
|
$this->context = $instance->context;
|
|
} else {
|
|
$this->context = get_context_instance(CONTEXT_BLOCK, $instance->id);
|
|
}
|
|
$this->page = $page;
|
|
$this->specialization();
|
|
}
|
|
|
|
/**
|
|
* This function is called on your subclass right after an instance is loaded
|
|
* Use this function to act on instance data just after it's loaded and before anything else is done
|
|
* For instance: if your block will have different title's depending on location (site, course, blog, etc)
|
|
*/
|
|
function specialization() {
|
|
// Just to make sure that this method exists.
|
|
}
|
|
|
|
/**
|
|
* Is each block of this type going to have instance-specific configuration?
|
|
* Normally, this setting is controlled by {@link instance_allow_multiple}: if multiple
|
|
* instances are allowed, then each will surely need its own configuration. However, in some
|
|
* cases it may be necessary to provide instance configuration to blocks that do not want to
|
|
* allow multiple instances. In that case, make this function return true.
|
|
* I stress again that this makes a difference ONLY if {@link instance_allow_multiple} returns false.
|
|
* @return boolean
|
|
* @todo finish documenting this function by explaining per-instance configuration further
|
|
*/
|
|
function instance_allow_config() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Are you going to allow multiple instances of each block?
|
|
* If yes, then it is assumed that the block WILL USE per-instance configuration
|
|
* @return boolean
|
|
* @todo finish documenting this function by explaining per-instance configuration further
|
|
*/
|
|
function instance_allow_multiple() {
|
|
// Are you going to allow multiple instances of each block?
|
|
// If yes, then it is assumed that the block WILL USE per-instance configuration
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Default behavior: print the config_instance.html file
|
|
* You don't need to override this if you're satisfied with the above
|
|
*
|
|
* @uses $CFG
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function instance_config_print() {
|
|
global $CFG, $DB;
|
|
// Default behavior: print the config_instance.html file
|
|
// You don't need to override this if you're satisfied with the above
|
|
if (!$this->instance_allow_multiple() && !$this->instance_allow_config()) {
|
|
return false;
|
|
}
|
|
|
|
if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
|
|
print_simple_box_start('center', '', '', 5, 'blockconfiginstance');
|
|
include($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html');
|
|
print_simple_box_end();
|
|
} else {
|
|
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Serialize and store config data
|
|
*/
|
|
function instance_config_save($data, $nolongerused = false) {
|
|
global $DB;
|
|
$DB->set_field('block_instances', 'configdata', base64_encode(serialize($data)),
|
|
array('id' => $this->instance->id));
|
|
}
|
|
|
|
/**
|
|
* Replace the instance's configuration data with those currently in $this->config;
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function instance_config_commit($nolongerused = false) {
|
|
global $DB;
|
|
$this->instance_config_save($this->config);
|
|
}
|
|
|
|
/**
|
|
* Do any additional initialization you may need at the time a new block instance is created
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function instance_create() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Delete everything related to this instance if you have been using persistent storage other than the configdata field.
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function instance_delete() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Allows the block class to have a say in the user's ability to edit (i.e., configure) blocks of this type.
|
|
* The framework has first say in whether this will be allowed (e.g., no editing allowed unless in edit mode)
|
|
* but if the framework does allow it, the block can still decide to refuse.
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function user_can_edit() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Allows the block class to have a say in the user's ability to create new instances of this block.
|
|
* The framework has first say in whether this will be allowed (e.g., no adding allowed unless in edit mode)
|
|
* but if the framework does allow it, the block can still decide to refuse.
|
|
* This function has access to the complete page object, the creation related to which is being determined.
|
|
* @return boolean
|
|
* @todo finish documenting this function
|
|
*/
|
|
function user_can_addto(&$page) {
|
|
return true;
|
|
}
|
|
|
|
function get_extra_capabilities() {
|
|
return array('moodle/block:view');
|
|
}
|
|
|
|
// Methods deprecated in Moodle 2.0 ========================================
|
|
|
|
/**
|
|
* Default case: the block wants to be 180 pixels wide
|
|
* @deprecated since Moodle 2.0.
|
|
* @return int
|
|
*/
|
|
function preferred_width() {
|
|
return 180;
|
|
}
|
|
|
|
/** @deprecated since Moodle 2.0. */
|
|
function _print_block() {
|
|
throw new coding_exception('_print_block is no longer used. It was a private ' .
|
|
'method of the block class, only for use by the blocks system. You ' .
|
|
'should not have been calling it anyway.');
|
|
}
|
|
|
|
/** @deprecated since Moodle 2.0. */
|
|
function _print_shadow() {
|
|
throw new coding_exception('_print_shadow is no longer used. It was a private ' .
|
|
'method of the block class, only for use by the blocks system. You ' .
|
|
'should not have been calling it anyway.');
|
|
}
|
|
|
|
/** @deprecated since Moodle 2.0. */
|
|
function _title_html() {
|
|
throw new coding_exception('_title_html is no longer used. It was a private ' .
|
|
'method of the block class, only for use by the blocks system. You ' .
|
|
'should not have been calling it anyway.');
|
|
}
|
|
|
|
/** @deprecated since Moodle 2.0. */
|
|
function _add_edit_controls() {
|
|
throw new coding_exception('_add_edit_controls is no longer used. It was a private ' .
|
|
'method of the block class, only for use by the blocks system. You ' .
|
|
'should not have been calling it anyway.');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Specialized class for displaying a block with a list of icons/text labels
|
|
*
|
|
* The get_content method should set $this->content->items and (optionally)
|
|
* $this->content->icons, instead of $this->content->text.
|
|
*
|
|
* @author Jon Papaioannou
|
|
* @package blocks
|
|
*/
|
|
|
|
class block_list extends block_base {
|
|
var $content_type = BLOCK_TYPE_LIST;
|
|
|
|
function is_empty() {
|
|
if ( !has_capability('moodle/block:view', $this->context) ) {
|
|
return true;
|
|
}
|
|
|
|
$this->get_content();
|
|
return (empty($this->content->items) && empty($this->content->footer));
|
|
}
|
|
|
|
protected function formatted_contents($output) {
|
|
$this->get_content();
|
|
if (!empty($this->content->items)) {
|
|
return $output->list_block_contents($this->content->icons, $this->content->items);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|