$action = new confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
$deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')), $action);
- $table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . $deleteicon));
+ $table->data[] = new html_table_row(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . $deleteicon));
}
echo $OUTPUT->table($table);
}
$cell->colspan = 12;
$cell->add_classes(array($element['type'], 'moving'));
$cell->text = $object->name.' ('.get_string('move').')';
- return array(html_table_row::make(array($cell)));
+ return array(new html_table_row(array($cell)));
}
if ($element['type'] == 'category') {
$cell->colspan = 12;
$cell->text = $OUTPUT->action_icon($aurl, $strmovehere, new pix_icon(array('class'=>'movetarget'), 'movehere'));
- $moveto = html_table_row::make(array($cell));
+ $moveto = new html_table_row(array($cell));
}
$newparents = $parents;
$endcell->colspan = (19 - $level);
$endcell->add_classes(array('colspan', $levelclass));
- $returnrows[] = html_table_row::make(array($endcell));;
+ $returnrows[] = new html_table_row(array($endcell));;
} else { // Dealing with a grade item
$fillercell->add_classes(array('fixedcolumn', 'cell', 'topleft'));
$fillercell->text = ' ';
$fillercell->colspan = $colspan;
- $row = html_table_row::make(array($fillercell));
+ $row = new html_table_row(array($fillercell));
$rows[] = $row;
}
// ===============================================================================================
-// TODO: Following components will be refactored soon
+// TODO: Following HTML components still need some refactoring
/**
* Base class for classes representing HTML elements.
*/
protected $actions = array();
- /**
- * Compoment constructor.
- * @param array $options image attributes such as title, id, alt, style, class
- */
- public function __construct(array $options = null) {
- // not implemented in this class because we want to set only public properties of this component
- renderer_base::apply_component_options($this, $options);
- }
-
/**
* Ensure some class names are an array.
* @param mixed $classes either an array of class names or a space-separated
* Perform any cleanup or final processing that should be done before an
* 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(renderer_base $output, moodle_page $page, $target) {
+ public function prepare() {
$this->classes = array_unique(self::clean_classes($this->classes));
}
-
- /**
- * This checks developer do not try to assign a property directly
- * if we have a setter for it. Otherwise, the property is set as expected.
- * @param string $name The name of the variable to set
- * @param mixed $value The value to assign to the variable
- * @return void
- */
- public function __set($name, $value) {
- if ($name == 'class') {
- debugging('this way of setting css class has been deprecated. use set_classes() method instead.');
- $this->set_classes($value);
- } else {
- $this->{$name} = $value;
- }
- }
-
- /**
- * Adds a JS action to this component.
- * Note: the JS function you write must have only two arguments: (string)event and (object|array)args
- * If you want to add an instantiated component_action (or one of its subclasses), give the object as the only parameter
- *
- * @param mixed $event a DOM event (click, mouseover etc.) or a component_action object
- * @param string $jsfunction The name of the JS function to call. required if argument 1 is a string (event)
- * @param array $jsfunctionargs An optional array of JS arguments to pass to the function
- */
- public function add_action($event, $jsfunction=null, $jsfunctionargs=array()) {
- if (empty($this->id)) {
- $this->generate_id();
- }
-
- if ($event instanceof component_action) {
- $this->actions[] = $event;
- } else {
- if (empty($jsfunction)) {
- throw new coding_exception('html_component::add_action requires a JS function argument if the first argument is a string event');
- }
- $this->actions[] = new component_action($event, $jsfunction, $jsfunctionargs);
- }
- }
-
- /**
- * Internal method for generating a unique ID for the purpose of event handlers.
- */
- protected function generate_id() {
- $this->id = uniqid(get_class($this));
- }
-
- /**
- * Returns the array of component_actions.
- * @return array Component actions
- */
- public function get_actions() {
- return $this->actions;
- }
-
- /**
- * Shortcut for adding a JS confirm dialog when the component is clicked.
- * The message must be a yes/no question.
- * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
- * @param string $callback The name of a JS function whose scope will be set to the simpleDialog object and have this
- * function's arguments set as this.args.
- * @return void
- */
- public function add_confirm_action($message, $callback=null) {
- $this->add_action(new component_action('click', 'M.util.show_confirm_dialog', array('message' => $message, 'callback' => $callback)));
- }
-
- /**
- * Returns true if this component has an action of the requested type (component_action by default).
- * @param string $class The class of the action we are looking for
- * @return boolean True if action is found
- */
- public function has_action($class='component_action') {
- foreach ($this->actions as $action) {
- if (get_class($action) == $class) {
- return true;
- }
- }
- return false;
- }
}
-/// Components representing HTML elements
-
-
/**
* Holds all the information required to render a <table> by
* {@see core_renderer::table()} or by an overridden version of that
* @see html_component::prepare()
* @return void
*/
- public function prepare(renderer_base $output, moodle_page $page, $target) {
+ public function prepare() {
if (!empty($this->align)) {
foreach ($this->align as $key => $aa) {
if ($aa) {
} else {
$this->rotateheaders = false; // Makes life easier later.
}
- parent::prepare($output, $page, $target);
- }
- /**
- * @param string $name The name of the variable to set
- * @param mixed $value The value to assign to the variable
- * @return void
- */
- public function __set($name, $value) {
- if ($name == 'rowclass') {
- debugging('rowclass[] has been deprecated for html_table ' .
- 'and should be replaced with rowclasses[]. please fix the code.');
- $this->rowclasses = $value;
- } else {
- parent::__set($name, $value);
- }
+ parent::prepare();
}
}
* @see lib/html_component#prepare()
* @return void
*/
- public function prepare(renderer_base $output, moodle_page $page, $target) {
- parent::prepare($output, $page, $target);
+ public function prepare() {
+ parent::prepare();
}
/**
- * Shortcut method for creating a row with an array of cells. Converts cells to html_table_cell objects.
+ * Constructor
* @param array $cells
- * @return html_table_row
- */
- public static function make($cells=array()) {
- $row = new html_table_row();
- foreach ($cells as $celltext) {
- if (!($celltext instanceof html_table_cell)) {
- $cell = new html_table_cell();
- $cell->text = $celltext;
- $row->cells[] = $cell;
+ */
+ public function __construct(array $cells=null) {
+ $cells = (array)$cells;
+ foreach ($cells as $cell) {
+ if ($cell instanceof html_table_cell) {
+ $this->cells[] = $cell;
} else {
- $row->cells[] = $celltext;
+ $this->cells[] = new html_table_cell($cell);
}
}
- return $row;
}
}
* @see lib/html_component#prepare()
* @return void
*/
- public function prepare(renderer_base $output, moodle_page $page, $target) {
+ public function prepare() {
if ($this->header && empty($this->scope)) {
$this->scope = 'col';
}
- parent::prepare($output, $page, $target);
+ parent::prepare();
+ }
+
+ public function __construct($text = null) {
+ $this->text = $text;
}
}
public function pix_url($imagename, $component = 'moodle') {
return $this->page->theme->pix_url($imagename, $component);
}
-
- /**
- * A helper function that takes a html_component subclass as param.
- * If that component has an id attribute and an array of valid component_action objects,
- * it sets up the appropriate event handlers.
- *
- * @param html_component $component
- * @return void;
- */
- protected function prepare_event_handlers(html_component $component) {
- //TODO: to be deleted soon
- $actions = $component->get_actions();
- if (!empty($actions) && is_array($actions) && $actions[0] instanceof component_action) {
- foreach ($actions as $action) {
- if (!empty($action->jsfunction)) {
- $this->page->requires->event_handler("#$component->id", $action->event, $action->jsfunction, $action->jsfunctionargs);
- }
- }
- }
- }
-
- /**
- * Helper function for applying of html_component options
- * @param html_component $component
- * @param array $options
- * @return void
- */
- public static function apply_component_options(html_component $component, array $options = null) {
- //TODO: to be deleted soon
- $options = (array)$options;
- foreach ($options as $key => $value) {
- if ($key === 'class' or $key === 'classes') {
- $component->add_classes($value);
- } else if (array_key_exists($key, $component)) {
- $component->$key = $value;
- }
- }
- }
}
$heading->header = true;
}
- $this->prepare_event_handlers($heading);
-
$heading->add_classes(array('header', 'c' . $key));
if (isset($table->headspan[$key]) && $table->headspan[$key] > 1) {
$heading->colspan = $table->headspan[$key];
foreach ($row as $unused => $item) {
$cell = new html_table_cell();
$cell->text = $item;
- $this->prepare_event_handlers($cell);
$newrow->cells[] = $cell;
}
$row = $newrow;
}
- $this->prepare_event_handlers($row);
-
$oddeven = $oddeven ? 0 : 1;
if (isset($table->rowclasses[$key])) {
$row->add_classes(array_unique(html_component::clean_classes($table->rowclasses[$key])));
$cell = $mycell;
}
- // Prepare all events handlers for this cell
- $this->prepare_event_handlers($cell);
-
if (isset($table->colclasses[$key])) {
$cell->add_classes(array_unique(html_component::clean_classes($table->colclasses[$key])));
}
$table = new html_table();
$table->set_classes(array('subscribertable','boxaligncenter'));
- $table->data = array(html_table_row::make(array($existingcell, $actioncell, $potentialcell)));
+ $table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell)));
$output .= $this->output->table($table);
$output .= html_writer::end_tag('form');
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson")." $i<span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
}
$cells = array();
$cells[] = "<span class=\"label\">".get_string("branch", "lesson")." $i<span>: ";
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson")." $i<span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
$cells[] = "<span class=\"label\">".get_string("wrongresponse", "lesson").'</span>';
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
}
$n++;
$i--;
$cells[] = '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">'.get_string("matchesanswer", "lesson")." $i</span>: ";
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
}
if ($i == 1) {
$cells = array();
$cells[] = '<span class="label">'.get_string("correctanswerscore", "lesson")." $i</span>: ";
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">'.get_string("correctanswerjump", "lesson")." $i</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
} elseif ($i == 2) {
$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerscore", "lesson")." $i</span>: ";
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">'.get_string("wronganswerjump", "lesson")." $i</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
}
if ($i === 1){
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("score", "lesson").'</span>';
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson").'</span>';
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
}
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("score", "lesson").'</span>';
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson").'</span>';
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
}
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("score", "lesson").'</span>';
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson").'</span>';
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
}
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
}
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("score", "lesson").'</span>';
$cells[] = $answer->score;
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = "<span class=\"label\">".get_string("jump", "lesson").'</span>';
$cells[] = $this->get_jump_name($answer->jumpto);
- $table->data[] = html_table_row::make($cells);
+ $table->data[] = new html_table_row($cells);
if ($i === 1){
$table->data[count($table->data)-1]->cells[0]->style = 'width:20%;';
$cell->colspan = 2;
$cell->style = 'text-align:center';
$cell->text = format_text($page->contents, FORMAT_MOODLE, $options);
- $pagetable->data[] = html_table_row::make(array($cell));
+ $pagetable->data[] = new html_table_row(array($cell));
$cell = new html_table_cell();
$cell->colspan = 2;
$cell->style = 'text-align:center';
$cell->text = '<strong>'.$qtypes[$page->qtype] . $page->option_description_string().'</strong>';
- $pagetable->data[] = html_table_row::make(array($cell));
+ $pagetable->data[] = new html_table_row(array($cell));
$pagetable = $page->display_answers($pagetable);
$table = new html_table();
$table->set_classes(array('progress_bar_table', 'center'));
- $table->data = array(html_table_row::make($cells));
+ $table->data = array(new html_table_row($cells));
return $this->output->box($this->output->table($table), 'progress_bar');
}
$group->descriptionformat = FORMAT_MOODLE;
}
$contentcell->text = $OUTPUT->heading($contentheading, 3) . format_text($group->description, $group->descriptionformat);
- $groupinfotable->data[] = html_table_row::make(array($picturecell, $contentcell));
+ $groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell));
echo $OUTPUT->table($groupinfotable);
}
}