HotPot module: differentiate between "guesses-correct" (JCloze) and "guess-correct...
[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
e54f4a78 359 if ($this->instance->visible) {
360 $bc->content = $this->formatted_contents($output);
361 if (!empty($this->content->footer)) {
362 $bc->footer = $this->content->footer;
363 }
364 } else {
365 $bc->add_class('invisible');
366 }
367
d4a03c00 368 $attributes = $this->html_attributes();
369 if (isset($attributes['id'])) {
370 $bc->id = $attributes['id'];
371 unset($attributes['id']);
372 }
373 if (isset($attributes['class'])) {
374 $bc->set_classes($attributes['class']);
375 unset($attributes['class']);
376 }
377 $bc->attributes = $attributes;
c4d951e1 378
d4a03c00 379 if (!$this->hide_header()) {
380 $bc->title = $this->title;
381 }
ae42ff6f 382
d4a03c00 383 if ($this->page->user_is_editing()) {
00a24d44 384 $bc->controls = $this->page->blocks->edit_controls($this);
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
40928036 400 $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here.
d4a03c00 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 /**
40928036 496 * Which page types this block may appear on.
497 *
498 * The information returned here is processed by the
499 * {@link blocks_name_allowed_in_format()} function. Look there if you need
500 * to know exactly how this works.
501 *
502 * Default case: everything except mod and tag.
503 *
504 * @return array page-type prefix => true/false.
c7e3bc51 505 */
0f3fe4b6 506 function applicable_formats() {
d232b8c7 507 // Default case: the block can be used in courses and site index, but not in activities
9591bc3c 508 return array('all' => true, 'mod' => false, 'tag' => false);
0f3fe4b6 509 }
59b29207 510
c7e3bc51 511
c7e3bc51 512 /**
513 * Default return is false - header will be shown
514 * @return boolean
515 */
0f3fe4b6 516 function hide_header() {
0f3fe4b6 517 return false;
518 }
c7e3bc51 519
520 /**
d4a03c00 521 * Return any HTML attributes that you want added to the outer <div> that
522 * of the block when it is output.
523 * @return array attribute name => value.
c7e3bc51 524 */
c5507e52 525 function html_attributes() {
2f747639 526 return array(
d4a03c00 527 'id' => 'inst' . $this->instance->id,
528 'class' => 'block_' . $this->name()
2f747639 529 );
c5507e52 530 }
d4a03c00 531
c7e3bc51 532 /**
40928036 533 * Set up a particular instance of this class given data from the block_insances
534 * table and the current page. (See {@link block_manager::load_blocks()}.)
535 *
536 * @param stdClass $instance data from block_insances, block_positions, etc.
537 * @param moodle_page $the page this block is on.
c7e3bc51 538 */
3179b000 539 function _load_instance($instance, $page) {
c7e3bc51 540 if (!empty($instance->configdata)) {
9b4b78fd 541 $this->config = unserialize(base64_decode($instance->configdata));
542 }
9b4b78fd 543 $this->instance = $instance;
e92c286c 544 if (isset($instance->context)) {
545 $this->context = $instance->context;
546 } else {
547 $this->context = get_context_instance(CONTEXT_BLOCK, $instance->id);
548 }
3179b000 549 $this->page = $page;
9b4b78fd 550 $this->specialization();
551 }
59b29207 552
43038ce6 553 /**
554 * This function is called on your subclass right after an instance is loaded
555 * Use this function to act on instance data just after it's loaded and before anything else is done
67677908 556 * For instance: if your block will have different title's depending on location (site, course, blog, etc)
43038ce6 557 */
9b4b78fd 558 function specialization() {
559 // Just to make sure that this method exists.
9b4b78fd 560 }
561
c7e3bc51 562 /**
f032aa7a 563 * Is each block of this type going to have instance-specific configuration?
40928036 564 * Normally, this setting is controlled by {@link instance_allow_multiple()}: if multiple
f032aa7a 565 * instances are allowed, then each will surely need its own configuration. However, in some
566 * cases it may be necessary to provide instance configuration to blocks that do not want to
567 * allow multiple instances. In that case, make this function return true.
40928036 568 * I stress again that this makes a difference ONLY if {@link instance_allow_multiple()} returns false.
f032aa7a 569 * @return boolean
f032aa7a 570 */
571 function instance_allow_config() {
572 return false;
573 }
574
575 /**
576 * Are you going to allow multiple instances of each block?
c7e3bc51 577 * If yes, then it is assumed that the block WILL USE per-instance configuration
578 * @return boolean
c7e3bc51 579 */
9b4b78fd 580 function instance_allow_multiple() {
581 // Are you going to allow multiple instances of each block?
582 // If yes, then it is assumed that the block WILL USE per-instance configuration
583 return false;
584 }
59b29207 585
c7e3bc51 586 /**
587 * Default behavior: print the config_instance.html file
588 * You don't need to override this if you're satisfied with the above
589 *
40928036 590 * @deprecated since Moodle 2.0.
591 * @return boolean whether anything was done. Blocks should use edit_form.php.
c7e3bc51 592 */
9b4b78fd 593 function instance_config_print() {
25c56af8 594 global $CFG, $DB, $OUTPUT;
9b4b78fd 595 // Default behavior: print the config_instance.html file
e1b8bdf8 596 // You don't need to override this if you're satisfied with the above
f032aa7a 597 if (!$this->instance_allow_multiple() && !$this->instance_allow_config()) {
9b4b78fd 598 return false;
599 }
9b4b78fd 600
c7e3bc51 601 if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
25c56af8 602 echo $OUTPUT->box_start('generalbox boxaligncenter blockconfiginstance');
6195e04a 603 include($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html');
25c56af8 604 echo $OUTPUT->box_end();
6195e04a 605 } else {
9b4b78fd 606 notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
607 }
40928036 608
9b4b78fd 609 return true;
610 }
c7e3bc51 611
612 /**
613 * Serialize and store config data
c7e3bc51 614 */
f474a4e5 615 function instance_config_save($data, $nolongerused = false) {
a5d424df 616 global $DB;
f474a4e5 617 $DB->set_field('block_instances', 'configdata', base64_encode(serialize($data)),
e03c0c1d 618 array('id' => $this->instance->id));
9b4b78fd 619 }
620
0144a0a7 621 /**
622 * Replace the instance's configuration data with those currently in $this->config;
0144a0a7 623 */
f474a4e5 624 function instance_config_commit($nolongerused = false) {
a5d424df 625 global $DB;
f474a4e5 626 $this->instance_config_save($this->config);
0144a0a7 627 }
628
d4a03c00 629 /**
b33dd23a 630 * Do any additional initialization you may need at the time a new block instance is created
631 * @return boolean
b33dd23a 632 */
633 function instance_create() {
634 return true;
635 }
636
d4a03c00 637 /**
b33dd23a 638 * Delete everything related to this instance if you have been using persistent storage other than the configdata field.
639 * @return boolean
b33dd23a 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
11306331 650 */
651 function user_can_edit() {
d14edf06 652 return has_capability('moodle/block:edit', $this->context);
11306331 653 }
654
d4a03c00 655 /**
11306331 656 * Allows the block class to have a say in the user's ability to create new instances of this block.
657 * The framework has first say in whether this will be allowed (e.g., no adding allowed unless in edit mode)
658 * but if the framework does allow it, the block can still decide to refuse.
659 * This function has access to the complete page object, the creation related to which is being determined.
660 * @return boolean
11306331 661 */
15a00b4b 662 function user_can_addto($page) {
d14edf06 663 return has_capability('moodle/block:edit', $page->context);
11306331 664 }
665
f432bebf 666 function get_extra_capabilities() {
d14edf06 667 return array('moodle/block:view', 'moodle/block:edit');
f432bebf 668 }
d4a03c00 669
670 // Methods deprecated in Moodle 2.0 ========================================
671
672 /**
673 * Default case: the block wants to be 180 pixels wide
674 * @deprecated since Moodle 2.0.
675 * @return int
676 */
677 function preferred_width() {
678 return 180;
679 }
680
681 /** @deprecated since Moodle 2.0. */
682 function _print_block() {
683 throw new coding_exception('_print_block is no longer used. It was a private ' .
684 'method of the block class, only for use by the blocks system. You ' .
685 'should not have been calling it anyway.');
686 }
687
688 /** @deprecated since Moodle 2.0. */
689 function _print_shadow() {
690 throw new coding_exception('_print_shadow is no longer used. It was a private ' .
691 'method of the block class, only for use by the blocks system. You ' .
692 'should not have been calling it anyway.');
693 }
694
695 /** @deprecated since Moodle 2.0. */
696 function _title_html() {
697 throw new coding_exception('_title_html is no longer used. It was a private ' .
698 'method of the block class, only for use by the blocks system. You ' .
699 'should not have been calling it anyway.');
700 }
701
702 /** @deprecated since Moodle 2.0. */
703 function _add_edit_controls() {
704 throw new coding_exception('_add_edit_controls is no longer used. It was a private ' .
705 'method of the block class, only for use by the blocks system. You ' .
706 'should not have been calling it anyway.');
707 }
708
7cf51142 709 /** @deprecated since Moodle 2.0. */
710 function config_print() {
711 throw new coding_exception('config_print() can no longer be used. Blocks should use a settings.php file.');
712 }
1bcb7eb5 713 /** @callback callback functions for comments api */
714 public static function comment_template($options) {
715 $ret = <<<EOD
716<div class="comment-userpicture">___picture___</div>
717<div class="comment-content">
718 ___name___ - <span>___time___</span>
719 <div>___content___</div>
720</div>
721EOD;
722 return $ret;
723 }
724 public static function comment_permissions($options) {
725 return array('view'=>true, 'post'=>true);
726 }
727 public static function comment_url($options) {
728 return null;
729 }
730 public static function comment_display(&$comments, $options) {
731 return true;
732 }
733 public static function comment_add(&$comments, $options) {
734 return true;
735 }
0f3fe4b6 736}
737
c7e3bc51 738/**
3ef642d9 739 * Specialized class for displaying a block with a list of icons/text labels
740 *
d4a03c00 741 * The get_content method should set $this->content->items and (optionally)
742 * $this->content->icons, instead of $this->content->text.
743 *
3ef642d9 744 * @author Jon Papaioannou
745 * @package blocks
746 */
747
748class block_list extends block_base {
749 var $content_type = BLOCK_TYPE_LIST;
750
751 function is_empty() {
e92c286c 752 if ( !has_capability('moodle/block:view', $this->context) ) {
25a7d980 753 return true;
754 }
755
3ef642d9 756 $this->get_content();
757 return (empty($this->content->items) && empty($this->content->footer));
758 }
759
d4a03c00 760 protected function formatted_contents($output) {
761 $this->get_content();
762 if (!empty($this->content->items)) {
763 return $output->list_block_contents($this->content->icons, $this->content->items);
3ef642d9 764 } else {
d4a03c00 765 return '';
3ef642d9 766 }
767 }
3ef642d9 768}
769
d0b59e3b 770?>