block/search: Eliminate todo that was already done, and clean up whitespace.
[moodle.git] / blocks / moodleblock.class.php
CommitLineData
ec972ade 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
0f3fe4b6 17
c7e3bc51 18/**
ccd3dd0c 19 * This file contains the parent class for moodle blocks, block_base.
c7e3bc51 20 *
c7e3bc51 21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package blocks
23 */
24
25/// Constants
26
27/**
28 * 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.
29 */
0f3fe4b6 30define('BLOCK_TYPE_LIST', 1);
c7e3bc51 31
32/**
33 * 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.
34 */
0f3fe4b6 35define('BLOCK_TYPE_TEXT', 2);
c7e3bc51 36
c7e3bc51 37/**
e0134f84 38 * Class for describing a moodle block, all Moodle blocks derive from this class
c7e3bc51 39 *
40 * @author Jon Papaioannou
41 * @package blocks
42 */
e89d741a 43class block_base {
c7e3bc51 44
45 /**
46 * Internal var for storing/caching translated strings
47 * @var string $str
48 */
0f3fe4b6 49 var $str;
c7e3bc51 50
51 /**
f8582e3e 52 * The title of the block to be displayed in the block title area.
c7e3bc51 53 * @var string $title
54 */
9b4b78fd 55 var $title = NULL;
c7e3bc51 56
c7e3bc51 57 /**
ccd3dd0c 58 * The type of content that this block creates. Currently support options - BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT
c7e3bc51 59 * @var int $content_type
60 */
3ef642d9 61 var $content_type = BLOCK_TYPE_TEXT;
c7e3bc51 62
63 /**
64 * An object to contain the information to be displayed in the block.
65 * @var stdObject $content
66 */
9b4b78fd 67 var $content = NULL;
c7e3bc51 68
69 /**
1345403a 70 * A string generated by {@link _add_edit_controls()} to display block manipulation links when the user is in editing mode.
c7e3bc51 71 * @var string $edit_controls
72 */
0f3fe4b6 73 var $edit_controls = NULL;
c7e3bc51 74
75 /**
76 * The current version that the block type defines.
77 * @var string $version
78 */
9b4b78fd 79 var $version = NULL;
c7e3bc51 80
81 /**
82 * The initialized instance of this block object.
83 * @var block $instance
84 */
9b4b78fd 85 var $instance = NULL;
c7e3bc51 86
3179b000 87 /**
88 * The page that this block is appearing on.
89 * @var moodle_page
90 */
91 public $page = NULL;
92
e92c286c 93 /**
94 * This blocks's context.
95 * @var stdClass
96 */
97 public $context = NULL;
98
c7e3bc51 99 /**
100 * An object containing the instance configuration information for the current instance of this block.
101 * @var stdObject $config
102 */
9b4b78fd 103 var $config = NULL;
104
f9648e77 105 /**
106 * How often the cronjob should run, 0 if not at all.
107 * @var int $cron
108 */
109
110 var $cron = NULL;
111
e0134f84 112/// Class Functions
c7e3bc51 113
114 /**
115 * The class constructor
116 *
117 */
e89d741a 118 function block_base() {
9b4b78fd 119 $this->init();
120 }
0f3fe4b6 121
73554752 122 /**
123 * Fake constructor to keep PHP5 happy
124 *
125 */
126 function __construct() {
e89d741a 127 $this->block_base();
73554752 128 }
44c55d46 129
44c55d46 130 /**
131 * Function that can be overridden to do extra cleanup before
132 * the database tables are deleted. (Called once per block, not per instance!)
133 */
134 function before_delete() {
135 }
a82e9bc3 136
137 /**
138 * Function that can be overridden to do extra setup after a block instance has been
139 * restored from backup. For example, it may need to alter any dates that the block
140 * stores, if the $restore->course_startdateoffset is set.
141 */
142 function after_restore($restore) {
143 }
73554752 144
b486ef1a 145 /**
5cfefc9b 146 * Enable custom instance data section in backup and restore.
b486ef1a 147 *
148 * If return true, then {@link instance_backup()} and
149 * {@link instance_restore()} will be called during
150 * backup/restore routines.
151 *
152 * @return boolean
153 **/
5cfefc9b 154 function backuprestore_instancedata_used() {
b486ef1a 155 return false;
156 }
157
158 /**
159 * Allows the block class to have a backup routine. Handy
160 * when the block has its own tables that have foreign keys to
161 * other tables (example: user table).
162 *
163 * Note: at the time of writing this comment, the indent level
164 * for the {@link full_tag()} should start at 5.
165 *
166 * @param resource $bf Backup File
167 * @param object $preferences Backup preferences
168 * @return boolean
169 **/
170 function instance_backup($bf, $preferences) {
171 return true;
172 }
173
174 /**
175 * Allows the block class to restore its backup routine.
176 *
177 * Should not return false if data is empty
178 * because old backups would not contain block instance backup data.
179 *
180 * @param object $restore Standard restore object
181 * @param object $data Object from backup_getid for this block instance
182 * @return boolean
183 **/
184 function instance_restore($restore, $data) {
185 return true;
186 }
187
43457dc8 188 /**
189 * Will be called before an instance of this block is backed up, so that any links in
5cfefc9b 190 * in config can be encoded. For example config->text, for the HTML block
191 * @return string
43457dc8 192 */
5cfefc9b 193 function get_backup_encoded_config() {
194 return base64_encode(serialize($this->config));
43457dc8 195 }
196
197 /**
5cfefc9b 198 * Return the content encoded to support interactivities linking. This function is
199 * called automatically from the backup procedure by {@link backup_encode_absolute_links()}.
43457dc8 200 *
5cfefc9b 201 * NOTE: There is no block instance when this method is called.
202 *
203 * @param string $content Content to be encoded
204 * @param object $restore Restore preferences object
205 * @return string The encoded content
206 **/
207 function encode_content_links($content, $restore) {
208 return $content;
209 }
210
211 /**
212 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
213 * function in order to decode contents of this block from the backup
214 * format to destination site/course in order to mantain inter-activities
215 * working in the backup/restore process.
216 *
217 * This is called from {@link restore_decode_content_links()} function in the restore process.
218 *
219 * NOTE: There is no block instance when this method is called.
220 *
221 * @param object $restore Standard restore object
222 * @return boolean
223 **/
224 function decode_content_links_caller($restore) {
225 return true;
226 }
227
228 /**
229 * Return content decoded to support interactivities linking.
230 * This is called automatically from
231 * {@link restore_decode_content_links_worker()} function
232 * in the restore process.
233 *
234 * NOTE: There is no block instance when this method is called.
235 *
236 * @param string $content Content to be dencoded
237 * @param object $restore Restore preferences object
238 * @return string The dencoded content
239 **/
240 function decode_content_links($content, $restore) {
241 return $content;
43457dc8 242 }
243
c7e3bc51 244 /**
245 * Returns the block name, as present in the class name,
246 * the database, the block directory, etc etc.
247 *
248 * @return string
249 */
0f3fe4b6 250 function name() {
251 // Returns the block name, as present in the class name,
252 // the database, the block directory, etc etc.
253 static $myname;
c7e3bc51 254 if ($myname === NULL) {
0f3fe4b6 255 $myname = strtolower(get_class($this));
256 $myname = substr($myname, strpos($myname, '_') + 1);
257 }
258 return $myname;
259 }
260
c7e3bc51 261 /**
262 * Parent class version of this function simply returns NULL
263 * This should be implemented by the derived class to return
264 * the content object.
265 *
266 * @return stdObject
267 */
0f3fe4b6 268 function get_content() {
269 // This should be implemented by the derived class.
270 return NULL;
271 }
c7e3bc51 272
273 /**
274 * Returns the class $title var value.
275 *
276 * Intentionally doesn't check if a title is set.
277 * This is already done in {@link _self_test()}
278 *
279 * @return string $this->title
280 */
0f3fe4b6 281 function get_title() {
6195e04a 282 // Intentionally doesn't check if a title is set. This is already done in _self_test()
0f3fe4b6 283 return $this->title;
284 }
c7e3bc51 285
286 /**
287 * Returns the class $content_type var value.
288 *
289 * Intentionally doesn't check if content_type is set.
290 * This is already done in {@link _self_test()}
291 *
292 * @return string $this->content_type
293 */
0f3fe4b6 294 function get_content_type() {
6195e04a 295 // Intentionally doesn't check if a content_type is set. This is already done in _self_test()
0f3fe4b6 296 return $this->content_type;
297 }
c7e3bc51 298
299 /**
300 * Returns the class $version var value.
301 *
302 * Intentionally doesn't check if a version is set.
303 * This is already done in {@link _self_test()}
304 *
305 * @return string $this->version
306 */
0f3fe4b6 307 function get_version() {
6195e04a 308 // Intentionally doesn't check if a version is set. This is already done in _self_test()
0f3fe4b6 309 return $this->version;
310 }
c7e3bc51 311
3ef642d9 312 /**
313 * Returns true or false, depending on whether this block has any content to display
7e874772 314 * and whether the user has permission to view the block
3ef642d9 315 *
316 * @return boolean
317 */
318 function is_empty() {
e92c286c 319 if ( !has_capability('moodle/block:view', $this->context) ) {
7e874772 320 return true;
321 }
322
3ef642d9 323 $this->get_content();
324 return(empty($this->content->text) && empty($this->content->footer));
325 }
326
c7e3bc51 327 /**
328 * First sets the current value of $this->content to NULL
329 * then calls the block's {@link get_content()} function
330 * to set its value back.
331 *
332 * @return stdObject
333 */
0f3fe4b6 334 function refresh_content() {
335 // Nothing special here, depends on content()
336 $this->content = NULL;
337 return $this->get_content();
338 }
c7e3bc51 339
340 /**
d4a03c00 341 * Return a block_contents oject representing the full contents of this block.
342 *
343 * This internally calls ->get_content(), and then adds the editing controls etc.
344 *
345 * You probably should not override this method, but instead override
346 * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()},
347 * {@link hide_header()}, {@link (get_edit_controls)}, etc.
348 *
349 * @return block_contents a represntation of the block, for rendering.
350 * @since Moodle 2.0.
c7e3bc51 351 */
d4a03c00 352 public function get_content_for_output($output) {
353 global $CFG;
0a0bb380 354
d4a03c00 355 $bc = new block_contents();
356 $bc->blockinstanceid = $this->instance->id;
357 $bc->blockpositionid = $this->instance->blockpositionid;
c7e3bc51 358
d4a03c00 359 $attributes = $this->html_attributes();
360 if (isset($attributes['id'])) {
361 $bc->id = $attributes['id'];
362 unset($attributes['id']);
363 }
364 if (isset($attributes['class'])) {
365 $bc->set_classes($attributes['class']);
366 unset($attributes['class']);
367 }
368 $bc->attributes = $attributes;
c4d951e1 369
d4a03c00 370 if (!$this->hide_header()) {
371 $bc->title = $this->title;
372 }
ae42ff6f 373
374 if ($this->instance->visible) {
375 $bc->content = $this->formatted_contents($output);
376 if (!empty($this->content->footer)) {
377 $bc->footer = $this->content->footer;
378 }
bc422e69 379 } else {
380 $bc->add_class('invisible');
d4a03c00 381 }
c4d951e1 382
d4a03c00 383 if ($this->page->user_is_editing()) {
1936f20b 384 $bc->controls = block_edit_controls($this, $this->page);
d4a03c00 385 }
c4d951e1 386
f674ec86 387 if ($this->is_empty() && !$bc->controls) {
388 return null;
389 }
390
ae42ff6f 391 if (empty($CFG->allowuserblockhiding) ||
392 (empty($bc->content) && empty($bc->footer))) {
d4a03c00 393 $bc->collapsible = block_contents::NOT_HIDEABLE;
394 } else if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) {
395 $bc->collapsible = block_contents::HIDDEN;
396 } else {
397 $bc->collapsible = block_contents::VISIBLE;
0f3fe4b6 398 }
c4d951e1 399
d4a03c00 400 $bc->annotation = ''; // TODO
401
402 return $bc;
0f3fe4b6 403 }
89adb174 404
c7e3bc51 405 /**
d4a03c00 406 * Convert the contents of the block to HTML.
c7e3bc51 407 *
d4a03c00 408 * This is used by block base classes like block_list to convert the structured
409 * $this->content->list and $this->content->icons arrays to HTML. So, in most
410 * blocks, you probaby want to override the {@link get_contents()} method,
411 * which generates that structured representation of the contents.
412 *
413 * @param $output The core_renderer to use when generating the output.
414 * @return string the HTML that should appearn in the body of the block.
415 * @since Moodle 2.0.
c7e3bc51 416 */
d4a03c00 417 protected function formatted_contents($output) {
418 $this->get_content();
419 if (!empty($this->content->text)) {
420 return $this->content->text;
421 } else {
422 return '';
423 }
424 }
425
c7e3bc51 426 /**
427 * Tests if this block has been implemented correctly.
428 * Also, $errors isn't used right now
429 *
430 * @return boolean
431 */
432
0f3fe4b6 433 function _self_test() {
434 // Tests if this block has been implemented correctly.
435 // Also, $errors isn't used right now
436 $errors = array();
437
438 $correct = true;
c7e3bc51 439 if ($this->get_title() === NULL) {
0f3fe4b6 440 $errors[] = 'title_not_set';
441 $correct = false;
442 }
ccd3dd0c 443 if (!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) {
0f3fe4b6 444 $errors[] = 'invalid_content_type';
445 $correct = false;
446 }
17e5635c 447 //following selftest was not working when roles&capabilities were used from block
35a518c5 448/* if ($this->get_content() === NULL) {
0f3fe4b6 449 $errors[] = 'content_not_set';
450 $correct = false;
35a518c5 451 }*/
c7e3bc51 452 if ($this->get_version() === NULL) {
0f3fe4b6 453 $errors[] = 'version_not_set';
454 $correct = false;
455 }
2b0d60ec 456
457 $formats = $this->applicable_formats();
c7e3bc51 458 if (empty($formats) || array_sum($formats) === 0) {
8a47e075 459 $errors[] = 'no_formats';
0f3fe4b6 460 $correct = false;
461 }
2b0d60ec 462
0f3fe4b6 463 $width = $this->preferred_width();
c7e3bc51 464 if (!is_int($width) || $width <= 0) {
0f3fe4b6 465 $errors[] = 'invalid_width';
466 $correct = false;
467 }
468 return $correct;
469 }
470
c7e3bc51 471 /**
472 * Subclasses should override this and return true if the
473 * subclass block has a config_global.html file.
474 *
475 * @return boolean
476 */
0f3fe4b6 477 function has_config() {
478 return false;
479 }
c7e3bc51 480
c7e3bc51 481 /**
482 * Default behavior: save all variables as $CFG properties
483 * You don't need to override this if you 're satisfied with the above
484 *
f8582e3e 485 * @param array $data
c7e3bc51 486 * @return boolean
487 */
f8582e3e 488 function config_save($data) {
f8582e3e 489 foreach ($data as $name => $value) {
9b4b78fd 490 set_config($name, $value);
491 }
492 return true;
0f3fe4b6 493 }
59b29207 494
c7e3bc51 495 /**
496 * Default case: the block can be used in all course types
497 * @return array
498 * @todo finish documenting this function
499 */
0f3fe4b6 500 function applicable_formats() {
d232b8c7 501 // Default case: the block can be used in courses and site index, but not in activities
9591bc3c 502 return array('all' => true, 'mod' => false, 'tag' => false);
0f3fe4b6 503 }
59b29207 504
c7e3bc51 505
c7e3bc51 506 /**
507 * Default return is false - header will be shown
508 * @return boolean
509 */
0f3fe4b6 510 function hide_header() {
0f3fe4b6 511 return false;
512 }
c7e3bc51 513
514 /**
d4a03c00 515 * Return any HTML attributes that you want added to the outer <div> that
516 * of the block when it is output.
517 * @return array attribute name => value.
c7e3bc51 518 */
c5507e52 519 function html_attributes() {
2f747639 520 return array(
d4a03c00 521 'id' => 'inst' . $this->instance->id,
522 'class' => 'block_' . $this->name()
2f747639 523 );
c5507e52 524 }
d4a03c00 525
c7e3bc51 526 /**
527 * Given an instance set the class var $instance to it and
528 * load class var $config
529 * @param block $instance
530 * @todo add additional documentation to further explain the format of instance and config
531 */
3179b000 532 function _load_instance($instance, $page) {
c7e3bc51 533 if (!empty($instance->configdata)) {
9b4b78fd 534 $this->config = unserialize(base64_decode($instance->configdata));
535 }
9b4b78fd 536 $this->instance = $instance;
e92c286c 537 if (isset($instance->context)) {
538 $this->context = $instance->context;
539 } else {
540 $this->context = get_context_instance(CONTEXT_BLOCK, $instance->id);
541 }
3179b000 542 $this->page = $page;
9b4b78fd 543 $this->specialization();
544 }
59b29207 545
43038ce6 546 /**
547 * This function is called on your subclass right after an instance is loaded
548 * Use this function to act on instance data just after it's loaded and before anything else is done
67677908 549 * For instance: if your block will have different title's depending on location (site, course, blog, etc)
43038ce6 550 */
9b4b78fd 551 function specialization() {
552 // Just to make sure that this method exists.
9b4b78fd 553 }
554
c7e3bc51 555 /**
f032aa7a 556 * Is each block of this type going to have instance-specific configuration?
557 * Normally, this setting is controlled by {@link instance_allow_multiple}: if multiple
558 * instances are allowed, then each will surely need its own configuration. However, in some
559 * cases it may be necessary to provide instance configuration to blocks that do not want to
560 * allow multiple instances. In that case, make this function return true.
561 * I stress again that this makes a difference ONLY if {@link instance_allow_multiple} returns false.
562 * @return boolean
563 * @todo finish documenting this function by explaining per-instance configuration further
564 */
565 function instance_allow_config() {
566 return false;
567 }
568
569 /**
570 * Are you going to allow multiple instances of each block?
c7e3bc51 571 * If yes, then it is assumed that the block WILL USE per-instance configuration
572 * @return boolean
573 * @todo finish documenting this function by explaining per-instance configuration further
574 */
9b4b78fd 575 function instance_allow_multiple() {
576 // Are you going to allow multiple instances of each block?
577 // If yes, then it is assumed that the block WILL USE per-instance configuration
578 return false;
579 }
59b29207 580
c7e3bc51 581 /**
582 * Default behavior: print the config_instance.html file
583 * You don't need to override this if you're satisfied with the above
584 *
585 * @uses $CFG
c7e3bc51 586 * @return boolean
587 * @todo finish documenting this function
588 */
9b4b78fd 589 function instance_config_print() {
f28f2d90 590 global $CFG, $DB;
9b4b78fd 591 // Default behavior: print the config_instance.html file
e1b8bdf8 592 // You don't need to override this if you're satisfied with the above
f032aa7a 593 if (!$this->instance_allow_multiple() && !$this->instance_allow_config()) {
9b4b78fd 594 return false;
595 }
9b4b78fd 596
c7e3bc51 597 if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
0705dcc0 598 print_simple_box_start('center', '', '', 5, 'blockconfiginstance');
6195e04a 599 include($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html');
9b4b78fd 600 print_simple_box_end();
6195e04a 601 } else {
9b4b78fd 602 notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
603 }
604
605 return true;
606 }
c7e3bc51 607
608 /**
609 * Serialize and store config data
c7e3bc51 610 */
f474a4e5 611 function instance_config_save($data, $nolongerused = false) {
a5d424df 612 global $DB;
f474a4e5 613 $DB->set_field('block_instances', 'configdata', base64_encode(serialize($data)),
e03c0c1d 614 array('id' => $this->instance->id));
9b4b78fd 615 }
616
0144a0a7 617 /**
618 * Replace the instance's configuration data with those currently in $this->config;
619 * @return boolean
620 * @todo finish documenting this function
621 */
f474a4e5 622 function instance_config_commit($nolongerused = false) {
a5d424df 623 global $DB;
f474a4e5 624 $this->instance_config_save($this->config);
0144a0a7 625 }
626
d4a03c00 627 /**
b33dd23a 628 * Do any additional initialization you may need at the time a new block instance is created
629 * @return boolean
630 * @todo finish documenting this function
631 */
632 function instance_create() {
633 return true;
634 }
635
d4a03c00 636 /**
b33dd23a 637 * Delete everything related to this instance if you have been using persistent storage other than the configdata field.
638 * @return boolean
639 * @todo finish documenting this function
640 */
641 function instance_delete() {
642 return true;
643 }
644
d4a03c00 645 /**
11306331 646 * Allows the block class to have a say in the user's ability to edit (i.e., configure) blocks of this type.
647 * The framework has first say in whether this will be allowed (e.g., no editing allowed unless in edit mode)
648 * but if the framework does allow it, the block can still decide to refuse.
649 * @return boolean
650 * @todo finish documenting this function
651 */
652 function user_can_edit() {
653 return true;
654 }
655
d4a03c00 656 /**
11306331 657 * Allows the block class to have a say in the user's ability to create new instances of this block.
658 * The framework has first say in whether this will be allowed (e.g., no adding allowed unless in edit mode)
659 * but if the framework does allow it, the block can still decide to refuse.
660 * This function has access to the complete page object, the creation related to which is being determined.
661 * @return boolean
662 * @todo finish documenting this function
663 */
15a00b4b 664 function user_can_addto($page) {
11306331 665 return true;
666 }
667
f432bebf 668 function get_extra_capabilities() {
44df8fa9 669 return array('moodle/block:view');
f432bebf 670 }
d4a03c00 671
672 // Methods deprecated in Moodle 2.0 ========================================
673
674 /**
675 * Default case: the block wants to be 180 pixels wide
676 * @deprecated since Moodle 2.0.
677 * @return int
678 */
679 function preferred_width() {
680 return 180;
681 }
682
683 /** @deprecated since Moodle 2.0. */
684 function _print_block() {
685 throw new coding_exception('_print_block is no longer used. It was a private ' .
686 'method of the block class, only for use by the blocks system. You ' .
687 'should not have been calling it anyway.');
688 }
689
690 /** @deprecated since Moodle 2.0. */
691 function _print_shadow() {
692 throw new coding_exception('_print_shadow is no longer used. It was a private ' .
693 'method of the block class, only for use by the blocks system. You ' .
694 'should not have been calling it anyway.');
695 }
696
697 /** @deprecated since Moodle 2.0. */
698 function _title_html() {
699 throw new coding_exception('_title_html is no longer used. It was a private ' .
700 'method of the block class, only for use by the blocks system. You ' .
701 'should not have been calling it anyway.');
702 }
703
704 /** @deprecated since Moodle 2.0. */
705 function _add_edit_controls() {
706 throw new coding_exception('_add_edit_controls is no longer used. It was a private ' .
707 'method of the block class, only for use by the blocks system. You ' .
708 'should not have been calling it anyway.');
709 }
710
7cf51142 711 /** @deprecated since Moodle 2.0. */
712 function config_print() {
713 throw new coding_exception('config_print() can no longer be used. Blocks should use a settings.php file.');
714 }
0f3fe4b6 715}
716
c7e3bc51 717/**
3ef642d9 718 * Specialized class for displaying a block with a list of icons/text labels
719 *
d4a03c00 720 * The get_content method should set $this->content->items and (optionally)
721 * $this->content->icons, instead of $this->content->text.
722 *
3ef642d9 723 * @author Jon Papaioannou
724 * @package blocks
725 */
726
727class block_list extends block_base {
728 var $content_type = BLOCK_TYPE_LIST;
729
730 function is_empty() {
e92c286c 731 if ( !has_capability('moodle/block:view', $this->context) ) {
25a7d980 732 return true;
733 }
734
3ef642d9 735 $this->get_content();
736 return (empty($this->content->items) && empty($this->content->footer));
737 }
738
d4a03c00 739 protected function formatted_contents($output) {
740 $this->get_content();
741 if (!empty($this->content->items)) {
742 return $output->list_block_contents($this->content->icons, $this->content->items);
3ef642d9 743 } else {
d4a03c00 744 return '';
3ef642d9 745 }
746 }
3ef642d9 747}
748
d0b59e3b 749?>