2004-05-10 13:27:09 +00:00
|
|
|
<?php // $Id$
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
2007-02-26 14:02:21 +00:00
|
|
|
* This file contains the parent class for moodle blocks, block_base.
|
2004-10-28 01:26:33 +00:00
|
|
|
*
|
|
|
|
* @author Jon Papaioannou
|
|
|
|
* @version $Id$
|
|
|
|
* @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.
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
define('BLOCK_TYPE_LIST', 1);
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
define('BLOCK_TYPE_TEXT', 2);
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2004-11-10 16:43:57 +00:00
|
|
|
* Class for describing a moodle block, all Moodle blocks derive from this class
|
2004-10-28 01:26:33 +00:00
|
|
|
*
|
|
|
|
* @author Jon Papaioannou
|
|
|
|
* @package blocks
|
|
|
|
*/
|
2004-11-23 18:53:34 +00:00
|
|
|
class block_base {
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal var for storing/caching translated strings
|
|
|
|
* @var string $str
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
var $str;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2004-11-19 02:41:32 +00:00
|
|
|
* The title of the block to be displayed in the block title area.
|
2004-10-28 01:26:33 +00:00
|
|
|
* @var string $title
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
var $title = NULL;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2007-02-26 14:02:21 +00:00
|
|
|
* The type of content that this block creates. Currently support options - BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT
|
2004-10-28 01:26:33 +00:00
|
|
|
* @var int $content_type
|
|
|
|
*/
|
2005-03-02 19:22:26 +00:00
|
|
|
var $content_type = BLOCK_TYPE_TEXT;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object to contain the information to be displayed in the block.
|
|
|
|
* @var stdObject $content
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
var $content = NULL;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2005-01-25 02:57:30 +00:00
|
|
|
* A string generated by {@link _add_edit_controls()} to display block manipulation links when the user is in editing mode.
|
2004-10-28 01:26:33 +00:00
|
|
|
* @var string $edit_controls
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
var $edit_controls = NULL;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current version that the block type defines.
|
|
|
|
* @var string $version
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
var $version = NULL;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The initialized instance of this block object.
|
|
|
|
* @var block $instance
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
var $instance = NULL;
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object containing the instance configuration information for the current instance of this block.
|
|
|
|
* @var stdObject $config
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
var $config = NULL;
|
|
|
|
|
2006-02-14 03:24:08 +00:00
|
|
|
/**
|
|
|
|
* How often the cronjob should run, 0 if not at all.
|
|
|
|
* @var int $cron
|
|
|
|
*/
|
|
|
|
|
|
|
|
var $cron = NULL;
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
|
2004-11-10 16:43:57 +00:00
|
|
|
/// Class Functions
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The class constructor
|
|
|
|
*
|
|
|
|
*/
|
2004-11-23 18:53:34 +00:00
|
|
|
function block_base() {
|
2004-10-19 21:04:28 +00:00
|
|
|
$this->init();
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-11-22 16:09:06 +00:00
|
|
|
/**
|
|
|
|
* Fake constructor to keep PHP5 happy
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __construct() {
|
2004-11-23 18:53:34 +00:00
|
|
|
$this->block_base();
|
2004-11-22 16:09:06 +00:00
|
|
|
}
|
2006-07-14 11:17:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that can be overridden to do extra setup after
|
|
|
|
* the database install. (Called once per block, not per instance!)
|
|
|
|
*/
|
|
|
|
function after_install() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
}
|
2006-09-21 12:07:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
}
|
2004-11-22 16:09:06 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Returns the block name, as present in the class name,
|
|
|
|
* the database, the block directory, etc etc.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function name() {
|
|
|
|
// Returns the block name, as present in the class name,
|
|
|
|
// the database, the block directory, etc etc.
|
|
|
|
static $myname;
|
2004-10-28 01:26:33 +00:00
|
|
|
if ($myname === NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$myname = strtolower(get_class($this));
|
|
|
|
$myname = substr($myname, strpos($myname, '_') + 1);
|
|
|
|
}
|
|
|
|
return $myname;
|
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Parent class version of this function simply returns NULL
|
|
|
|
* This should be implemented by the derived class to return
|
|
|
|
* the content object.
|
|
|
|
*
|
|
|
|
* @return stdObject
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function get_content() {
|
|
|
|
// This should be implemented by the derived class.
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function get_title() {
|
2004-10-25 03:30:48 +00:00
|
|
|
// Intentionally doesn't check if a title is set. This is already done in _self_test()
|
2004-04-18 23:20:53 +00:00
|
|
|
return $this->title;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function get_content_type() {
|
2004-10-25 03:30:48 +00:00
|
|
|
// Intentionally doesn't check if a content_type is set. This is already done in _self_test()
|
2004-04-18 23:20:53 +00:00
|
|
|
return $this->content_type;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function get_version() {
|
2004-10-25 03:30:48 +00:00
|
|
|
// Intentionally doesn't check if a version is set. This is already done in _self_test()
|
2004-04-18 23:20:53 +00:00
|
|
|
return $this->version;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
2005-03-02 19:22:26 +00:00
|
|
|
/**
|
|
|
|
* Returns true or false, depending on whether this block has any content to display
|
2007-08-13 10:08:15 +00:00
|
|
|
* and whether the user has permission to view the block
|
2005-03-02 19:22:26 +00:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function is_empty() {
|
2007-08-13 10:08:15 +00:00
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
|
|
|
|
|
|
|
|
if ( !has_capability('moodle/block:view', $context) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-03-02 19:22:26 +00:00
|
|
|
$this->get_content();
|
|
|
|
return(empty($this->content->text) && empty($this->content->footer));
|
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function refresh_content() {
|
|
|
|
// Nothing special here, depends on content()
|
|
|
|
$this->content = NULL;
|
|
|
|
return $this->get_content();
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the block!
|
|
|
|
*/
|
2005-01-25 02:57:30 +00:00
|
|
|
function _print_block() {
|
2006-09-20 20:31:09 +00:00
|
|
|
global $COURSE;
|
2006-08-24 03:20:37 +00:00
|
|
|
|
2005-03-02 19:22:26 +00:00
|
|
|
// is_empty() includes a call to get_content()
|
2006-08-24 03:28:09 +00:00
|
|
|
if ($this->is_empty() && empty($COURSE->javascriptportal)) {
|
2005-03-02 19:22:26 +00:00
|
|
|
if (empty($this->edit_controls)) {
|
|
|
|
// No content, no edit controls, so just shut up
|
2005-03-02 19:29:50 +00:00
|
|
|
return;
|
2005-03-02 19:22:26 +00:00
|
|
|
} else {
|
|
|
|
// No content but editing, so show something at least
|
|
|
|
$this->_print_shadow();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($this->hide_header() && empty($this->edit_controls)) {
|
|
|
|
// Header wants to hide, no edit controls to show, so no header it is
|
|
|
|
print_side_block(NULL, $this->content->text, NULL, NULL, $this->content->footer, $this->html_attributes());
|
|
|
|
} else {
|
2006-06-09 14:25:18 +00:00
|
|
|
// The full treatment, please. Include the title text.
|
|
|
|
print_side_block($this->_title_html(), $this->content->text, NULL, NULL, $this->content->footer, $this->html_attributes(), $this->title);
|
2005-03-02 19:22:26 +00:00
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Block contents are missing. Simply display an empty block so that
|
|
|
|
* edit controls are accessbile to the user and they are aware that this
|
|
|
|
* block is in place, even if empty.
|
|
|
|
*/
|
2005-01-25 02:57:30 +00:00
|
|
|
function _print_shadow() {
|
2006-06-09 14:25:18 +00:00
|
|
|
print_side_block($this->_title_html(), ' ', NULL, NULL, '', array('class' => 'hidden'), $this->title);
|
2005-05-10 04:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _title_html() {
|
|
|
|
global $CFG;
|
|
|
|
|
2006-02-28 13:12:13 +00:00
|
|
|
//Accessibility: validation, can't have <div> inside <h2>, use <span>.
|
2006-03-06 12:50:43 +00:00
|
|
|
$title = '<div class="title">';
|
2007-05-08 15:07:25 +00:00
|
|
|
|
2005-05-10 04:00:56 +00:00
|
|
|
if (!empty($CFG->allowuserblockhiding)) {
|
2006-02-28 13:12:13 +00:00
|
|
|
//Accessibility: added static 'alt' text for the +- icon.
|
2006-03-06 12:50:43 +00:00
|
|
|
//TODO (nfreear): language string 'hide OR show block'
|
2006-12-11 07:15:30 +00:00
|
|
|
$title .= '<div class="hide-show">'.
|
2007-05-08 15:07:25 +00:00
|
|
|
'<a title="'.get_string('showhideblock','access').
|
|
|
|
'" href="#" onclick="elementToggleHide(this, true, function(el) {'.
|
|
|
|
'return findParentNode(el, \'DIV\', \'sideblock\'); '.
|
|
|
|
'}, \''.$CFG->pixpath.'\' ); return false;">'.
|
|
|
|
'<img src="'.$CFG->pixpath.'/spacer.gif" '.
|
|
|
|
'id = "togglehide_inst'.$this->instance->id.'" '.
|
|
|
|
'alt="'.get_string('showhideblock','access').'" class="hide-show-image" /></a></div>';
|
2005-05-10 04:00:56 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 12:50:43 +00:00
|
|
|
//Accesssibility: added H2 (was in, weblib.php: print_side_block)
|
|
|
|
$title .= '<h2>'.$this->title.'</h2>';
|
2005-05-10 04:00:56 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
if ($this->edit_controls !== NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$title .= $this->edit_controls;
|
|
|
|
}
|
2005-05-10 04:00:56 +00:00
|
|
|
|
2006-03-06 12:50:43 +00:00
|
|
|
$title .= '</div>';
|
2005-05-10 04:00:56 +00:00
|
|
|
return $title;
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Sets class $edit_controls var with correct block manipulation links.
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @uses $USER
|
|
|
|
* @param stdObject $options ?
|
|
|
|
* @todo complete documenting this function. Define $options.
|
|
|
|
*/
|
2005-01-25 02:57:30 +00:00
|
|
|
function _add_edit_controls($options) {
|
2006-09-02 23:55:56 +00:00
|
|
|
global $CFG, $USER, $PAGE;
|
2006-09-20 20:31:09 +00:00
|
|
|
|
|
|
|
// this is the context relevant to this particular block instance
|
|
|
|
$blockcontext = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
|
|
|
|
|
|
|
|
// context for site or course, i.e. participant list etc
|
|
|
|
// check to see if user can edit site or course blocks.
|
|
|
|
// blocks can appear on other pages such as mod and blog pages...
|
2007-02-16 07:57:19 +00:00
|
|
|
|
2006-09-20 20:31:09 +00:00
|
|
|
switch ($this->instance->pagetype) {
|
|
|
|
case 'course-view':
|
2007-02-16 01:26:19 +00:00
|
|
|
if (!has_capability('moodle/site:manageblocks', $blockcontext)) {
|
2006-09-20 20:31:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
if (!isset($this->str)) {
|
|
|
|
$this->str->delete = get_string('delete');
|
|
|
|
$this->str->moveup = get_string('moveup');
|
|
|
|
$this->str->movedown = get_string('movedown');
|
|
|
|
$this->str->moveright = get_string('moveright');
|
|
|
|
$this->str->moveleft = get_string('moveleft');
|
|
|
|
$this->str->hide = get_string('hide');
|
|
|
|
$this->str->show = get_string('show');
|
2004-10-19 21:04:28 +00:00
|
|
|
$this->str->configure = get_string('configuration');
|
2006-09-06 02:16:48 +00:00
|
|
|
$this->str->assignroles = get_string('assignroles', 'role');
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2007-08-09 08:47:09 +00:00
|
|
|
// RTL support - exchange right and left arrows
|
|
|
|
if (right_to_left()) {
|
|
|
|
$rightarrow = 'left.gif';
|
|
|
|
$leftarrow = 'right.gif';
|
|
|
|
} else {
|
|
|
|
$rightarrow = 'right.gif';
|
|
|
|
$leftarrow = 'left.gif';
|
|
|
|
}
|
|
|
|
|
2005-03-02 19:47:04 +00:00
|
|
|
$movebuttons = '<div class="commands">';
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
if ($this->instance->visible) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$icon = '/t/hide.gif';
|
|
|
|
$title = $this->str->hide;
|
2004-10-28 01:26:33 +00:00
|
|
|
} else {
|
2004-04-18 23:20:53 +00:00
|
|
|
$icon = '/t/show.gif';
|
|
|
|
$title = $this->str->show;
|
|
|
|
}
|
|
|
|
|
2005-08-23 04:48:34 +00:00
|
|
|
if (empty($this->instance->pageid)) {
|
|
|
|
$this->instance->pageid = 0;
|
|
|
|
}
|
2006-09-02 23:55:56 +00:00
|
|
|
if (!empty($PAGE->type) and ($this->instance->pagetype == $PAGE->type) and $this->instance->pageid == $PAGE->id) {
|
|
|
|
$page = $PAGE;
|
|
|
|
} else {
|
|
|
|
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
|
|
|
|
}
|
2004-11-08 19:36:07 +00:00
|
|
|
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey));
|
2007-08-24 02:17:28 +00:00
|
|
|
|
|
|
|
if (empty($this->instance->pinned)) {
|
|
|
|
$movebuttons .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$blockcontext->id.'">' .
|
|
|
|
'<img src="'.$CFG->pixpath.'/i/roles.gif" alt="'.$this->str->assignroles.'" /></a>';
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2007-08-17 13:07:23 +00:00
|
|
|
if ($this->user_can_edit()) {
|
|
|
|
$movebuttons .= '<a class="icon hide" title="'. $title .'" href="'.$script.'&blockaction=toggle">' .
|
|
|
|
'<img src="'. $CFG->pixpath.$icon .'" alt="'.$title.'" /></a>';
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2005-12-17 04:37:55 +00:00
|
|
|
if ($options & BLOCK_CONFIGURE && $this->user_can_edit()) {
|
2005-03-07 12:08:44 +00:00
|
|
|
$movebuttons .= '<a class="icon edit" title="'. $this->str->configure .'" href="'.$script.'&blockaction=config">' .
|
2005-01-29 04:01:15 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. $this->str->configure .'" /></a>';
|
2004-10-19 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-17 13:07:23 +00:00
|
|
|
if ($this->user_can_addto($page)) {
|
|
|
|
$movebuttons .= '<a class="icon delete" title="'. $this->str->delete .'" href="'.$script.'&blockaction=delete">' .
|
|
|
|
'<img src="'. $CFG->pixpath .'/t/delete.gif" alt="'. $this->str->delete .'" /></a>';
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
if ($options & BLOCK_MOVE_LEFT) {
|
2005-03-07 12:08:44 +00:00
|
|
|
$movebuttons .= '<a class="icon left" title="'. $this->str->moveleft .'" href="'.$script.'&blockaction=moveleft">' .
|
2007-08-09 08:47:09 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/t/'.$leftarrow.'" alt="'. $this->str->moveleft .'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
if ($options & BLOCK_MOVE_UP) {
|
2005-03-07 12:08:44 +00:00
|
|
|
$movebuttons .= '<a class="icon up" title="'. $this->str->moveup .'" href="'.$script.'&blockaction=moveup">' .
|
2005-01-29 04:01:15 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/t/up.gif" alt="'. $this->str->moveup .'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
if ($options & BLOCK_MOVE_DOWN) {
|
2005-03-07 12:08:44 +00:00
|
|
|
$movebuttons .= '<a class="icon down" title="'. $this->str->movedown .'" href="'.$script.'&blockaction=movedown">' .
|
2005-01-29 04:01:15 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/t/down.gif" alt="'. $this->str->movedown .'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
if ($options & BLOCK_MOVE_RIGHT) {
|
2005-03-07 12:08:44 +00:00
|
|
|
$movebuttons .= '<a class="icon right" title="'. $this->str->moveright .'" href="'.$script.'&blockaction=moveright">' .
|
2007-08-09 08:47:09 +00:00
|
|
|
'<img src="'. $CFG->pixpath .'/t/'.$rightarrow.'" alt="'. $this->str->moveright .'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$movebuttons .= '</div>';
|
|
|
|
$this->edit_controls = $movebuttons;
|
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Tests if this block has been implemented correctly.
|
|
|
|
* Also, $errors isn't used right now
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
function _self_test() {
|
|
|
|
// Tests if this block has been implemented correctly.
|
|
|
|
// Also, $errors isn't used right now
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
$correct = true;
|
2004-10-28 01:26:33 +00:00
|
|
|
if ($this->get_title() === NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$errors[] = 'title_not_set';
|
|
|
|
$correct = false;
|
|
|
|
}
|
2007-02-26 14:02:21 +00:00
|
|
|
if (!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$errors[] = 'invalid_content_type';
|
|
|
|
$correct = false;
|
|
|
|
}
|
2006-10-08 11:00:49 +00:00
|
|
|
//following selftest was not working when roles&capabilities were used from block
|
2006-09-02 10:03:30 +00:00
|
|
|
/* if ($this->get_content() === NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$errors[] = 'content_not_set';
|
|
|
|
$correct = false;
|
2006-09-02 10:03:30 +00:00
|
|
|
}*/
|
2004-10-28 01:26:33 +00:00
|
|
|
if ($this->get_version() === NULL) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$errors[] = 'version_not_set';
|
|
|
|
$correct = false;
|
|
|
|
}
|
2004-08-22 16:54:48 +00:00
|
|
|
|
|
|
|
$formats = $this->applicable_formats();
|
2004-10-28 01:26:33 +00:00
|
|
|
if (empty($formats) || array_sum($formats) === 0) {
|
2005-02-08 02:59:44 +00:00
|
|
|
$errors[] = 'no_formats';
|
2004-04-18 23:20:53 +00:00
|
|
|
$correct = false;
|
|
|
|
}
|
2004-08-22 16:54:48 +00:00
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
$width = $this->preferred_width();
|
2004-10-28 01:26:33 +00:00
|
|
|
if (!is_int($width) || $width <= 0) {
|
2004-04-18 23:20:53 +00:00
|
|
|
$errors[] = 'invalid_width';
|
|
|
|
$correct = false;
|
|
|
|
}
|
|
|
|
return $correct;
|
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Subclasses should override this and return true if the
|
|
|
|
* subclass block has a config_global.html file.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function has_config() {
|
|
|
|
return false;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default behavior: print the config_global.html file
|
|
|
|
* You don't need to override this if you're satisfied with the above
|
|
|
|
*
|
|
|
|
* @uses $CFG
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-11-19 02:41:32 +00:00
|
|
|
function config_print() {
|
2004-10-19 21:04:28 +00:00
|
|
|
// Default behavior: print the config_global.html file
|
2004-10-28 01:26:33 +00:00
|
|
|
// You don't need to override this if you're satisfied with the above
|
|
|
|
if (!$this->has_config()) {
|
2004-10-19 21:04:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-01-29 04:01:15 +00:00
|
|
|
global $CFG;
|
|
|
|
print_simple_box_start('center', '', '', 5, 'blockconfigglobal');
|
2004-10-24 21:49:58 +00:00
|
|
|
include($CFG->dirroot.'/blocks/'. $this->name() .'/config_global.html');
|
2004-10-19 21:04:28 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
return true;
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Default behavior: save all variables as $CFG properties
|
|
|
|
* You don't need to override this if you 're satisfied with the above
|
|
|
|
*
|
2004-11-19 02:41:32 +00:00
|
|
|
* @param array $data
|
2004-10-28 01:26:33 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-11-19 02:41:32 +00:00
|
|
|
function config_save($data) {
|
|
|
|
foreach ($data as $name => $value) {
|
2004-10-19 21:04:28 +00:00
|
|
|
set_config($name, $value);
|
|
|
|
}
|
|
|
|
return true;
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Default case: the block can be used in all course types
|
|
|
|
* @return array
|
|
|
|
* @todo finish documenting this function
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function applicable_formats() {
|
2005-02-11 06:30:50 +00:00
|
|
|
// Default case: the block can be used in courses and site index, but not in activities
|
2007-08-10 09:33:21 +00:00
|
|
|
return array('all' => true, 'mod' => false, 'tag' => false);
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default case: the block wants to be 180 pixels wide
|
|
|
|
* @return int
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function preferred_width() {
|
|
|
|
return 180;
|
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* Default return is false - header will be shown
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2004-04-18 23:20:53 +00:00
|
|
|
function hide_header() {
|
|
|
|
return false;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2005-12-17 04:37:55 +00:00
|
|
|
* Default case: an id with the instance and a class with our name in it
|
2004-10-28 01:26:33 +00:00
|
|
|
* @return array
|
|
|
|
* @todo finish documenting this function
|
|
|
|
*/
|
2004-05-21 10:59:40 +00:00
|
|
|
function html_attributes() {
|
2005-02-10 00:50:08 +00:00
|
|
|
return array('id' => 'inst'.$this->instance->id, 'class' => 'block_'. $this->name());
|
2004-05-21 10:59:40 +00:00
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2005-01-25 02:57:30 +00:00
|
|
|
function _load_instance($instance) {
|
2004-10-28 01:26:33 +00:00
|
|
|
if (!empty($instance->configdata)) {
|
2004-10-19 21:04:28 +00:00
|
|
|
$this->config = unserialize(base64_decode($instance->configdata));
|
|
|
|
}
|
2005-02-05 01:32:15 +00:00
|
|
|
// [pj] This line below is supposed to be an optimization (we don't need configdata anymore)
|
|
|
|
// but what it does is break in PHP5 because the same instance object will be passed to
|
|
|
|
// this function twice in each page view, and the second time it won't have any configdata
|
|
|
|
// so it won't work correctly. Thus it's commented out.
|
|
|
|
// unset($instance->configdata);
|
2004-10-19 21:04:28 +00:00
|
|
|
$this->instance = $instance;
|
|
|
|
$this->specialization();
|
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-25 00:09:47 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2005-01-11 19:38:19 +00:00
|
|
|
* For instance: if your block will have different title's depending on location (site, course, blog, etc)
|
2004-10-25 00:09:47 +00:00
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
function specialization() {
|
|
|
|
// Just to make sure that this method exists.
|
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
2004-11-08 19:36:07 +00:00
|
|
|
* 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?
|
2004-10-28 01:26:33 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2004-10-24 21:49:58 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-10-19 21:04:28 +00:00
|
|
|
function instance_config_print() {
|
|
|
|
// Default behavior: print the config_instance.html file
|
2004-10-24 15:52:25 +00:00
|
|
|
// You don't need to override this if you're satisfied with the above
|
2004-11-08 19:36:07 +00:00
|
|
|
if (!$this->instance_allow_multiple() && !$this->instance_allow_config()) {
|
2004-10-19 21:04:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-01-29 04:01:15 +00:00
|
|
|
global $CFG;
|
2004-10-19 21:04:28 +00:00
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
|
2005-01-29 04:01:15 +00:00
|
|
|
print_simple_box_start('center', '', '', 5, 'blockconfiginstance');
|
2004-10-25 03:30:48 +00:00
|
|
|
include($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html');
|
2004-10-19 21:04:28 +00:00
|
|
|
print_simple_box_end();
|
2004-10-25 03:30:48 +00:00
|
|
|
} else {
|
2004-10-19 21:04:28 +00:00
|
|
|
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-10-28 01:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize and store config data
|
|
|
|
* @return boolean
|
|
|
|
* @todo finish documenting this function
|
|
|
|
*/
|
2005-08-16 00:25:39 +00:00
|
|
|
function instance_config_save($data,$pinned=false) {
|
2004-10-19 21:04:28 +00:00
|
|
|
$data = stripslashes_recursive($data);
|
|
|
|
$this->config = $data;
|
2005-08-16 00:25:39 +00:00
|
|
|
$table = 'block_instance';
|
|
|
|
if (!empty($pinned)) {
|
|
|
|
$table = 'block_pinned';
|
|
|
|
}
|
|
|
|
return set_field($table, 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
|
2004-10-19 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2005-02-01 06:51:00 +00:00
|
|
|
/**
|
|
|
|
* Replace the instance's configuration data with those currently in $this->config;
|
|
|
|
* @return boolean
|
|
|
|
* @todo finish documenting this function
|
|
|
|
*/
|
2005-08-16 00:25:39 +00:00
|
|
|
function instance_config_commit($pinned=false) {
|
|
|
|
$table = 'block_instance';
|
|
|
|
if (!empty($pinned)) {
|
|
|
|
$table = 'block_pinned';
|
|
|
|
}
|
|
|
|
return set_field($table, 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
|
2005-02-01 06:51:00 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 03:32:31 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2005-12-17 04:37:55 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-28 01:26:33 +00:00
|
|
|
/**
|
2005-03-02 19:22:26 +00:00
|
|
|
* Specialized class for displaying a block with a list of icons/text labels
|
|
|
|
*
|
|
|
|
* @author Jon Papaioannou
|
|
|
|
* @package blocks
|
|
|
|
*/
|
|
|
|
|
|
|
|
class block_list extends block_base {
|
|
|
|
var $content_type = BLOCK_TYPE_LIST;
|
|
|
|
|
|
|
|
function is_empty() {
|
2007-08-22 10:35:28 +00:00
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
|
|
|
|
|
|
|
|
if ( !has_capability('moodle/block:view', $context) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-03-02 19:22:26 +00:00
|
|
|
$this->get_content();
|
|
|
|
return (empty($this->content->items) && empty($this->content->footer));
|
|
|
|
}
|
|
|
|
|
|
|
|
function _print_block() {
|
2006-09-20 20:31:09 +00:00
|
|
|
global $COURSE;
|
2006-08-24 03:20:37 +00:00
|
|
|
|
2005-03-02 19:22:26 +00:00
|
|
|
// is_empty() includes a call to get_content()
|
2006-08-24 03:28:09 +00:00
|
|
|
if ($this->is_empty() && empty($COURSE->javascriptportal)) {
|
2005-03-02 19:22:26 +00:00
|
|
|
if (empty($this->edit_controls)) {
|
|
|
|
// No content, no edit controls, so just shut up
|
2005-03-02 19:29:50 +00:00
|
|
|
return;
|
2005-03-02 19:22:26 +00:00
|
|
|
} else {
|
|
|
|
// No content but editing, so show something at least
|
|
|
|
$this->_print_shadow();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($this->hide_header() && empty($this->edit_controls)) {
|
|
|
|
// Header wants to hide, no edit controls to show, so no header it is
|
2006-08-24 03:20:37 +00:00
|
|
|
print_side_block(NULL, '', $this->content->items, $this->content->icons,
|
|
|
|
$this->content->footer, $this->html_attributes());
|
2005-03-02 19:22:26 +00:00
|
|
|
} else {
|
2006-06-09 14:25:18 +00:00
|
|
|
// The full treatment, please. Include the title text.
|
2006-08-24 03:20:37 +00:00
|
|
|
print_side_block($this->_title_html(), '', $this->content->items, $this->content->icons,
|
|
|
|
$this->content->footer, $this->html_attributes(), $this->title);
|
|
|
|
}
|
2005-03-02 19:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-12-12 07:12:11 +00:00
|
|
|
?>
|