/**
* Perform any cleanup or final processing that should be done before an
- * instance of this class is output.
+ * instance of this class is output. This method is supposed to be called
+ * only from renderers.
+ *
+ * @param renderer_base $output output renderer
+ * @param moodle_page $page
+ * @param string $target rendering target
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->classes = array_unique(self::clean_classes($this->classes));
}
}
}
+
class labelled_html_component extends moodle_html_component {
/**
* @var mixed $label The label for that component. String or html_label object
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->text)) {
throw new coding_exception('html_label must have a $text value.');
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
+
/**
* This class hold all the information required to describe a <select> menu that
* will be printed by {@link core_renderer::select()}. (Or by an overridden
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
global $CFG;
// name may contain [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
$this->add_class('select');
$this->initialise_options();
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
* @return void
*/
public function override_option_values($options) {
- global $PAGE;
-
$originalcount = count($options);
$this->initialise_options();
$newcount = count($this->options);
$optionurl = new moodle_url(key($options));
- if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
+ if ($optionurl->compare($page->url, URL_MATCH_PARAMS)) {
$this->options[$optkey]->options[$key]->selected = 'selected';
}
}
$this->options[$optkey]->value = key($options);
$optionurl = new moodle_url(key($options));
- if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
+ if ($optionurl->compare($page->url, URL_MATCH_PARAMS)) {
$this->options[$optkey]->selected = 'selected';
}
next($options);
}
}
+
/**
* This class represents a select option element
*
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->text) && (string)$this->text!=='0') {
throw new coding_exception('html_select_option requires a $text value.');
}
$this->generate_id();
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* This class represents a select optgroup element
*
*/
public $options = array();
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->text)) {
throw new coding_exception('html_select_optgroup requires a $text value.');
}
if (empty($this->options)) {
throw new coding_exception('html_select_optgroup requires at least one html_select_option object');
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
+
/**
* This class represents an input field
*
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->style)) {
$this->style = 'width: 4em;';
}
if (empty($this->id)) {
$this->generate_id();
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Holds all the information required to render a <table> by
* {@see core_renderer::table()} or by an overridden version of that
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (!empty($this->align)) {
foreach ($this->align as $key => $aa) {
if ($aa) {
} else {
$this->rotateheaders = false; // Makes life easier later.
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
* @param string $name The name of the variable to set
}
}
+
/**
* Component representing a table row.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- parent::prepare();
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Component representing a table cell.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if ($this->header && empty($this->scope)) {
$this->scope = 'col';
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
+
/**
* Component representing a XHTML link.
*
* @see lib/moodle_html_component#prepare() Disables the link if it links to the current page.
* @return void
*/
- public function prepare() {
- global $PAGE;
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
// We can't accept an empty text value
if (empty($this->text)) {
throw new coding_exception('A html_link must have a descriptive text value!');
$this->url = new moodle_url($this->url);
}
- if ($this->url->compare($PAGE->url, URL_MATCH_PARAMS) && $this->disableifcurrent) {
+ if ($this->url->compare($page->url, URL_MATCH_PARAMS) && $this->disableifcurrent) {
$this->disabled = true;
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Component representing a XHTML button (input of type 'button').
* The renderer will either output it as a button with an onclick event,
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->add_class('singlebutton');
if (empty($this->text)) {
$this->disabled = 'disabled';
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->src)) {
throw new coding_exception('html_image requires a $src value (moodle_url).');
}
$this->add_class('image');
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Component representing a textarea.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->add_class('form-textarea');
if (empty($this->id)) {
$this->value = htmlspecialchars($value);
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
+
/**
* Component representing a simple form wrapper. Its purpose is mainly to enclose
* a submit input with the appropriate action and hidden inputs.
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (empty($this->url)) {
throw new coding_exception('A html_form must have a $url value (string or moodle_url).');
$this->url->param('sesskey', sesskey());
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
public static function make_button($url, $options, $label='OK', $method='post') {
}
}
+
/**
* Component representing a list.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- parent::prepare();
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Component representing a list item.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- parent::prepare();
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ parent::prepare($output, $page, $target);
}
}
+
/**
* Component representing a span element. It has no special attributes, so
* it is very low-level and can be used for styling and JS actions.
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- parent::prepare();
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ parent::prepare($output, $page, $target);
}
}
/// Complex components aggregating simpler components
+
/**
* Component representing a paging bar.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
if (!isset($this->totalcount) || is_null($this->totalcount)) {
throw new coding_exception('moodle_paging_bar requires a totalcount value.');
}
}
}
+
/**
* Component representing a user picture.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- global $CFG, $DB, $OUTPUT;
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ global $CFG, $DB;
if (empty($this->user)) {
throw new coding_exception('A moodle_user_picture object must have a $user object before being rendered.');
$this->image->src = new moodle_url(get_file_url($this->user->id.'/'.$file.'.jpg', null, 'user'));
} else { // Print default user pictures (use theme version if available)
$this->add_class('defaultuserpic');
- $this->image->src = $OUTPUT->pix_url('u/' . $file);
+ $this->image->src = $output->pix_url('u/' . $file);
}
if ($this->alttext) {
}
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
public static function make($user, $courseid) {
}
}
+
/**
* Component representing a help icon.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
- global $COURSE, $OUTPUT, $CFG;
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
+ global $CFG;
if (empty($this->page)) {
throw new coding_exception('A moodle_help_icon object requires a $page parameter');
$this->link->url = new moodle_url($CFG->wwwroot.'/help.php', array('module' => $this->module, 'file' => $this->page .'.html'));
// fix for MDL-7734
- if (!empty($COURSE->lang)) {
- $this->link->url->param('forcelang', $COURSE->lang);
+ if (!empty($page->course->lang)) {
+ $this->link->url->param('forcelang', $page->course->lang);
}
// Catch references to the old text.html and emoticons.html help files that
if ($image instanceof moodle_url) {
$this->image->src = $image->out();
} else if ($image === true) {
- $this->image->src = $OUTPUT->pix_url('help');
+ $this->image->src = $output->pix_url('help');
} else if (is_string($image)) {
$this->image->src = $image;
}
if (!($this->image instanceof html_image)) {
$this->image = new html_image();
}
- $this->image->src = $OUTPUT->pix_url('help');
+ $this->image->src = $output->pix_url('help');
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
/**
}
}
+
/**
* Component representing an icon linking to a Moodle page.
*
* @see lib/moodle_html_component#prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->image->add_class('action-icon');
if (!empty($this->actions)) {
unset($this->actions);
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
if (empty($this->image->src)) {
throw new coding_exception('moodle_action_icon->image->src must not be empty');
}
}
+
/**
* This class represents how a block appears on a page.
*
* @see moodle_html_component::prepare()
* @return void
*/
- public function prepare() {
+ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->skipid = self::$idcounter;
self::$idcounter += 1;
$this->add_class('sideblock');
if (!empty($this->controls)) {
$this->add_class('block_with_controls');
}
- parent::prepare();
+ parent::prepare($output, $page, $target);
}
}
+
/**
* This class represents a target for where a block can go when it is being moved.
*
*/
function block($bc, $region) {
$bc = clone($bc); // Avoid messing up the object passed in.
- $bc->prepare();
+ $bc->prepare($this, $this->page, $this->target);
$skiptitle = strip_tags($bc->title);
if (empty($skiptitle)) {
return $this->link_to_popup($link);
}
- $link->prepare();
+ $link->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($link);
// A disabled link is rendered as formatted text
throw new coding_exception('$OUTPUT->button($form) requires $form to have a button (html_button) value');
}
$form = clone($form);
- $form->button->prepare();
+ $form->button->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($form->button);
*/
public function form($form, $contents=null) {
$form = clone($form);
- $form->prepare();
+ $form->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($form);
$buttonoutput = null;
} else if (empty($contents)) {
$contents = $this->output_empty_tag('input', array('type' => 'submit', 'value' => get_string('ok')));
} else if (!empty($form->button)) {
- $form->button->prepare();
+ $form->button->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($form->button);
$buttonattributes = array('class' => $form->button->get_classes_string(),
*/
public function action_icon($icon) {
$icon = clone($icon);
- $icon->prepare();
+ $icon->prepare($this, $this->page, $this->target);
$imageoutput = $this->image($icon->image);
if ($icon->linktext) {
public function help_icon($icon) {
global $COURSE;
$icon = clone($icon);
- $icon->prepare();
+ $icon->prepare($this, $this->page, $this->target);
$popup = new popup_action('click', $icon->link->url);
$icon->link->add_action($popup);
}
}
- $link->prepare();
+ $link->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($link);
if (empty($link->url)) {
$image->src = $this->pix_url('spacer')->out(false, array(), false);
}
- $image->prepare();
+ $image->prepare($this, $this->page, $this->target);
$image->add_class('spacer');
$output = $this->image($image);
}
$image = clone($image);
- $image->prepare();
+ $image->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($image);
$userpic = clone($userpic);
}
- $userpic->prepare();
+ $userpic->prepare($this, $this->page, $this->target);
$output = $this->image($userpic->image);
*/
public function htmllist($list) {
$list = clone($list);
- $list->prepare();
+ $list->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($list);
$output .= $this->htmllist($listitem) . "\n";
$output .= $this->output_end_tag('li') . "\n";
} else if ($listitem instanceof html_list_item) {
- $listitem->prepare();
+ $listitem->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($listitem);
$output .= $this->output_tag('li', array('class' => $listitem->get_classes_string()), $listitem->value) . "\n";
} else {
}
$span = clone($span);
- $span->prepare();
+ $span->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($span);
$attributes = array('class' => $span->get_classes_string(),
'alt' => $span->alt,
$closeform->method = 'get';
$closeform->button->text = $text;
$closeform->button->add_action('click', 'close_window');
- $closeform->button->prepare();
+ $closeform->button->prepare($this, $this->page, $this->target);
return $this->container($this->button($closeform), 'closewindow');
}
*/
public function select($select) {
$select = clone($select);
- $select->prepare();
+ $select->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($select);
throw new coding_exception('$OUTPUT->radio($option) only accepts a html_select_option object as param.');
}
$option = clone($option);
- $option->prepare();
+ $option->prepare($this, $this->page, $this->target);
$option->label->for = $option->id;
$this->prepare_event_handlers($option);
throw new coding_exception('$OUTPUT->checkbox($option) only accepts a html_select_option object as param.');
}
$option = clone($option);
- $option->prepare();
+ $option->prepare($this, $this->page, $this->target);
$option->label->for = $option->id;
$this->prepare_event_handlers($option);
*/
public function select_option($option) {
$option = clone($option);
- $option->prepare();
+ $option->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($option);
if ($option instanceof html_select_option) {
*/
public function field($field) {
$field = clone($field);
- $field->prepare();
+ $field->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($field);
$label = '';
if (!empty($field->label->text)) {
*/
public function label($label) {
$label = clone($label);
- $label->prepare();
+ $label->prepare($this, $this->page, $this->target);
$this->prepare_event_handlers($label);
return $this->output_tag('label', array('for' => $label->for, 'class' => $label->get_classes_string()), $label->text);
}
public function paging_bar($pagingbar) {
$output = '';
$pagingbar = clone($pagingbar);
- $pagingbar->prepare();
+ $pagingbar->prepare($this, $this->page, $this->target);
if ($pagingbar->totalcount > $pagingbar->perpage) {
$output .= get_string('page') . ':';
*/
public function table(html_table $table) {
$table = clone($table);
- $table->prepare();
+ $table->prepare($this, $this->page, $this->target);
$attributes = array(
'id' => $table->id,
'width' => $table->width,